mirror of
https://github.com/status-im/nim-stew.git
synced 2025-02-13 12:36:57 +00:00
Add options to storeMacroResults that improve the results in NBC
This commit is contained in:
parent
9a2a542b9f
commit
a333eb080f
@ -26,22 +26,14 @@ var
|
||||
macroLocations {.compileTime.} = newSeq[LineInfo]()
|
||||
macroOutputs {.compileTime.} = newSeq[NimNode]()
|
||||
|
||||
proc storeMacroResult*(callSite: LineInfo, macroResult: NimNode) =
|
||||
macroLocations.add callSite
|
||||
macroOutputs.add macroResult
|
||||
|
||||
proc storeMacroResult*(macroResult: NimNode) =
|
||||
let usageSite = callsite().lineInfoObj
|
||||
storeMacroResult(usageSite, macroResult)
|
||||
|
||||
macro dumpMacroResults*: untyped =
|
||||
proc writeMacroResultsNow* {.compileTime.} =
|
||||
var files = initTable[string, NimNode]()
|
||||
|
||||
proc addToFile(file: var NimNode, location: LineInfo, macroOutput: NimNode) =
|
||||
if file == nil:
|
||||
file = newNimNode(nnkStmtList, macroOutput)
|
||||
|
||||
file.add newCommentStmtNode($location)
|
||||
file.add newCommentStmtNode("Generated at line " & $location.line)
|
||||
file.add macroOutput
|
||||
|
||||
for i in 0..< macroLocations.len:
|
||||
@ -53,6 +45,22 @@ macro dumpMacroResults*: untyped =
|
||||
writeFile(targetFile, repr(contents))
|
||||
hint "Wrote macro output to " & targetFile, contents
|
||||
|
||||
proc storeMacroResult*(callSite: LineInfo,
|
||||
macroResult: NimNode,
|
||||
writeOutputImmediately = false) =
|
||||
macroLocations.add callSite
|
||||
macroOutputs.add macroResult
|
||||
if writeOutputImmediately:
|
||||
# echo macroResult.repr
|
||||
writeMacroResultsNow()
|
||||
|
||||
proc storeMacroResult*(macroResult: NimNode, writeOutputImmediately = false) =
|
||||
let usageSite = callsite().lineInfoObj
|
||||
storeMacroResult(usageSite, macroResult, writeOutputImmediately)
|
||||
|
||||
macro dumpMacroResults*: untyped =
|
||||
writeMacroResultsNow()
|
||||
|
||||
proc findPragma*(pragmas: NimNode, pragmaSym: NimNode): NimNode =
|
||||
for p in pragmas:
|
||||
if p.kind in {nnkSym, nnkIdent} and eqIdent(p, pragmaSym):
|
||||
|
Loading…
x
Reference in New Issue
Block a user