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
|
|
@ -694,28 +694,25 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
|||
if def.kind != nkEmpty:
|
||||
if sfThread in v.flags: localError(c.config, def.info, errThreadvarCannotInit)
|
||||
setVarType(c, v, typ)
|
||||
# this is needed for the evaluation pass, guard checking
|
||||
# and custom pragmas:
|
||||
b = newNodeI(nkIdentDefs, a.info)
|
||||
if importantComments(c.config):
|
||||
# keep documentation information:
|
||||
b.comment = a.comment
|
||||
b.add newSymNode(v)
|
||||
# postfix not generated here (to generate, get rid of it in transf)
|
||||
if a[j].kind == nkPragmaExpr:
|
||||
var p = newNodeI(nkPragmaExpr, a.info)
|
||||
p.add newSymNode(v)
|
||||
p.add a[j][1]
|
||||
b.add p
|
||||
else:
|
||||
b.add newSymNode(v)
|
||||
# keep type desc for doc generator
|
||||
b.add a[^2]
|
||||
b.add copyTree(def)
|
||||
addToVarSection(c, result, n, b)
|
||||
# this is needed for the evaluation pass, guard checking
|
||||
# and custom pragmas:
|
||||
var ast = newNodeI(nkIdentDefs, a.info)
|
||||
if a[j].kind == nkPragmaExpr:
|
||||
var p = newNodeI(nkPragmaExpr, a.info)
|
||||
p.add newSymNode(v)
|
||||
p.add a[j][1].copyTree
|
||||
ast.add p
|
||||
else:
|
||||
ast.add newSymNode(v)
|
||||
ast.add a[^2].copyTree
|
||||
ast.add def
|
||||
v.ast = ast
|
||||
v.ast = b
|
||||
else:
|
||||
if def.kind in {nkPar, nkTupleConstr}: v.ast = def[j]
|
||||
# bug #7663, for 'nim check' this can be a non-tuple:
|
||||
|
|
@ -811,12 +808,21 @@ proc semConst(c: PContext, n: PNode): PNode =
|
|||
|
||||
if a.kind != nkVarTuple:
|
||||
setVarType(c, v, typ)
|
||||
v.ast = def # no need to copy
|
||||
when false:
|
||||
v.ast = def # no need to copy
|
||||
b = newNodeI(nkConstDef, a.info)
|
||||
if importantComments(c.config): b.comment = a.comment
|
||||
b.add newSymNode(v)
|
||||
# postfix not generated here (to generate, get rid of it in transf)
|
||||
if a[j].kind == nkPragmaExpr:
|
||||
var p = newNodeI(nkPragmaExpr, a.info)
|
||||
p.add newSymNode(v)
|
||||
p.add a[j][1].copyTree
|
||||
b.add p
|
||||
else:
|
||||
b.add newSymNode(v)
|
||||
b.add a[1]
|
||||
b.add copyTree(def)
|
||||
v.ast = b
|
||||
else:
|
||||
setVarType(c, v, typ[j])
|
||||
v.ast = if def[j].kind != nkExprColonExpr: def[j]
|
||||
|
|
@ -2330,6 +2336,11 @@ proc setLine(n: PNode, info: TLineInfo) =
|
|||
for i in 0..<n.safeLen: setLine(n[i], info)
|
||||
n.info = info
|
||||
|
||||
proc recursiveSetFlag(n: PNode, flag: TNodeFlag) =
|
||||
if n != nil:
|
||||
for i in 0..<n.safeLen: recursiveSetFlag(n[i], flag)
|
||||
incl(n.flags, flag)
|
||||
|
||||
proc semPragmaBlock(c: PContext, n: PNode; expectedType: PType = nil): PNode =
|
||||
checkSonsLen(n, 2, c.config)
|
||||
let pragmaList = n[0]
|
||||
|
|
@ -2354,7 +2365,7 @@ proc semPragmaBlock(c: PContext, n: PNode; expectedType: PType = nil): PNode =
|
|||
for i in 0..<pragmaList.len:
|
||||
case whichPragma(pragmaList[i])
|
||||
of wLine: setLine(result, pragmaList[i].info)
|
||||
of wNoRewrite: incl(result.flags, nfNoRewrite)
|
||||
of wNoRewrite: recursiveSetFlag(result, nfNoRewrite)
|
||||
else: discard
|
||||
|
||||
proc semStaticStmt(c: PContext, n: PNode): PNode =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue