store full definition AST for consts, fix noRewrite (#20115)
* continue #9582 for consts, close #9331, fix #20114 also move extractPragma to ast to pave the way for things like {.strdefine: "abc".} etc * changelog correctly * fix jsgen * update tgetimpl * fix sighashes * fix #19766, add comment about postfix * fix noRewrite LOL refs #16620 * fix changelog * fix destructors
This commit is contained in:
parent
fdc6b0fb6e
commit
de4b0346bd
26 changed files with 176 additions and 65 deletions
|
|
@ -439,3 +439,43 @@ when false:
|
|||
|
||||
# left-to-right priority/override order for getCustomPragmaVal
|
||||
assert bb.getCustomPragmaVal(hehe) == (key: "hi", val: "hu", haha: "he")
|
||||
|
||||
{.experimental: "dynamicBindSym".}
|
||||
|
||||
# const
|
||||
block:
|
||||
template myAttr() {.pragma.}
|
||||
template myAttr2(x: int) {.pragma.}
|
||||
template myAttr3(x: string) {.pragma.}
|
||||
|
||||
type
|
||||
MyObj2 = ref object
|
||||
|
||||
const a {.myAttr,myAttr2(2),myAttr3:"test".}: int = 0
|
||||
const b {.myAttr,myAttr2(2),myAttr3:"test".} = 0
|
||||
|
||||
macro forceHasCustomPragma(x: untyped, y: typed): untyped =
|
||||
var x = bindSym(x.repr)
|
||||
for c in x:
|
||||
if c.symKind == nskConst:
|
||||
x = c
|
||||
break
|
||||
result = getAst(hasCustomPragma(x, y))
|
||||
|
||||
macro forceGetCustomPragmaVal(x: untyped, y: typed): untyped =
|
||||
var x = bindSym(x.repr)
|
||||
for c in x:
|
||||
if c.symKind == nskConst:
|
||||
x = c
|
||||
break
|
||||
result = getAst(getCustomPragmaVal(x, y))
|
||||
|
||||
template check(s: untyped) =
|
||||
doAssert forceHasCustomPragma(s, myAttr)
|
||||
doAssert forceHasCustomPragma(s, myAttr2)
|
||||
doAssert forceGetCustomPragmaVal(s, myAttr2) == 2
|
||||
doAssert forceHasCustomPragma(s, myAttr3)
|
||||
doAssert forceGetCustomPragmaVal(s, myAttr3) == "test"
|
||||
|
||||
check(a)
|
||||
check(b)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue