diff options
Diffstat (limited to 'compiler/semstmts.nim')
-rw-r--r-- | compiler/semstmts.nim | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index fd8f2180b..faf8e3baa 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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) - # 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) + # 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 - ast.add p + p.add a[j][1] + b.add p else: - ast.add newSymNode(v) - ast.add a[^2].copyTree - ast.add def - v.ast = ast + b.add newSymNode(v) + # keep type desc for doc generator + b.add a[^2] + b.add copyTree(def) + addToVarSection(c, result, n, b) + 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 = |