diff options
author | cooldome <cdome@bk.ru> | 2018-09-03 12:25:59 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-09-03 13:25:59 +0200 |
commit | e63c66b8104225cefe0413471410ef4c072f9954 (patch) | |
tree | cd2aaf32d9fda170074c247b5a310650020ef8f9 /tests/macros/tgetimpl.nim | |
parent | 1abef2dc59e812f7aee41620bf5cd298f5cc8270 (diff) | |
download | Nim-e63c66b8104225cefe0413471410ef4c072f9954.tar.gz |
Add sym owner to macros (#8253)
Diffstat (limited to 'tests/macros/tgetimpl.nim')
-rw-r--r-- | tests/macros/tgetimpl.nim | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/tests/macros/tgetimpl.nim b/tests/macros/tgetimpl.nim index d38492934..715c969f3 100644 --- a/tests/macros/tgetimpl.nim +++ b/tests/macros/tgetimpl.nim @@ -1,6 +1,7 @@ discard """ msg: '''"muhaha" proc poo(x, y: int) = + let y = x echo ["poo"]''' """ @@ -10,11 +11,39 @@ const foo = "muhaha" proc poo(x, y: int) = + let y = x echo "poo" macro m(x: typed): untyped = - echo repr x.symbol.getImpl + echo repr x.getImpl result = x discard m foo discard m poo + +#------------ + +macro checkOwner(x: typed, check_id: static[int]): untyped = + let sym = case check_id: + of 0: x + of 1: x.getImpl.body[0][0][0] + of 2: x.getImpl.body[0][0][^1] + of 3: x.getImpl.body[1][0] + else: x + result = newStrLitNode($sym.owner.symKind) + +macro isSameOwner(x, y: typed): untyped = + result = + if x.owner == y.owner: bindSym"true" + else: bindSym"false" + + +static: + doAssert checkOwner(foo, 0) == "nskModule" + doAssert checkOwner(poo, 0) == "nskModule" + doAssert checkOwner(poo, 1) == "nskProc" + doAssert checkOwner(poo, 2) == "nskProc" + doAssert checkOwner(poo, 3) == "nskModule" + doAssert isSameOwner(foo, poo) + doAssert isSameOwner(foo, echo) == false + doAssert isSameOwner(poo, len) == false |