Add sym owner to macros (#8253)

This commit is contained in:
cooldome 2018-09-03 12:25:59 +01:00 • committed by Andreas Rumpf
commit e63c66b810
7 changed files with 50 additions and 3 deletions

View file

@ -237,6 +237,12 @@ else: # bootstrapping substitute
else:
n.strValOld
when defined(nimHasSymOwnerInMacro):
proc owner*(sym: NimNode): NimNode {.magic: "SymOwner", noSideEffect.}
## accepts node of kind nnkSym and returns its owner's symbol.
## result is also mnde of kind nnkSym if owner exists otherwise
## nnkNilLit is returned
proc getType*(n: NimNode): NimNode {.magic: "NGetType", noSideEffect.}
## with 'getType' you can access the node's `type`:idx:. A Nim type is
## mapped to a Nim AST too, so it's slightly confusing but it means the same