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]()
|
macroLocations {.compileTime.} = newSeq[LineInfo]()
|
||||||
macroOutputs {.compileTime.} = newSeq[NimNode]()
|
macroOutputs {.compileTime.} = newSeq[NimNode]()
|
||||||
|
|
||||||
proc storeMacroResult*(callSite: LineInfo, macroResult: NimNode) =
|
proc writeMacroResultsNow* {.compileTime.} =
|
||||||
macroLocations.add callSite
|
|
||||||
macroOutputs.add macroResult
|
|
||||||
|
|
||||||
proc storeMacroResult*(macroResult: NimNode) =
|
|
||||||
let usageSite = callsite().lineInfoObj
|
|
||||||
storeMacroResult(usageSite, macroResult)
|
|
||||||
|
|
||||||
macro dumpMacroResults*: untyped =
|
|
||||||
var files = initTable[string, NimNode]()
|
var files = initTable[string, NimNode]()
|
||||||
|
|
||||||
proc addToFile(file: var NimNode, location: LineInfo, macroOutput: NimNode) =
|
proc addToFile(file: var NimNode, location: LineInfo, macroOutput: NimNode) =
|
||||||
if file == nil:
|
if file == nil:
|
||||||
file = newNimNode(nnkStmtList, macroOutput)
|
file = newNimNode(nnkStmtList, macroOutput)
|
||||||
|
|
||||||
file.add newCommentStmtNode($location)
|
file.add newCommentStmtNode("Generated at line " & $location.line)
|
||||||
file.add macroOutput
|
file.add macroOutput
|
||||||
|
|
||||||
for i in 0..< macroLocations.len:
|
for i in 0..< macroLocations.len:
|
||||||
|
@ -53,6 +45,22 @@ macro dumpMacroResults*: untyped =
|
||||||
writeFile(targetFile, repr(contents))
|
writeFile(targetFile, repr(contents))
|
||||||
hint "Wrote macro output to " & targetFile, 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 =
|
proc findPragma*(pragmas: NimNode, pragmaSym: NimNode): NimNode =
|
||||||
for p in pragmas:
|
for p in pragmas:
|
||||||
if p.kind in {nnkSym, nnkIdent} and eqIdent(p, pragmaSym):
|
if p.kind in {nnkSym, nnkIdent} and eqIdent(p, pragmaSym):
|
||||||
|
|
Loading…
Reference in New Issue