Skip to content

Commit

Permalink
retain postfix node for typed variable/routine AST; save field syms
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Dec 23, 2023
1 parent c0acf3c commit a15c2f0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
1 change: 1 addition & 0 deletions compiler/nir/ast2ir.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,7 @@ proc genVarSection(c: var ProcCon; n: PNode) =
else:
var vn = a[0]
if vn.kind == nkPragmaExpr: vn = vn[0]
if vn.kind == nkPostfix: vn = vn[1]
if vn.kind == nkSym:
let s = vn.sym
if s.kind == skConst:
Expand Down
37 changes: 30 additions & 7 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,22 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
if importantComments(c.config):
# keep documentation information:
b.comment = a.comment
# 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)
var p = newNodeI(nkPragmaExpr, a[j].info)
if a[j][0].kind == nkPostfix:
var pf = newNodeI(nkPostfix, a[j][0].info)
pf.add a[j][0][0]
pf.add newSymNode(v)
p.add pf
else:
p.add newSymNode(v)
p.add a[j][1]
b.add p
elif a[j].kind == nkPostfix:
var pf = newNodeI(nkPostfix, a[j].info)
pf.add a[j][0]
pf.add newSymNode(v)
b.add pf
else:
b.add newSymNode(v)
# keep type desc for doc generator
Expand Down Expand Up @@ -891,12 +901,22 @@ proc semConst(c: PContext, n: PNode): PNode =
setVarType(c, v, typ)
b = newNodeI(nkConstDef, a.info)
if importantComments(c.config): b.comment = a.comment
# 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)
var p = newNodeI(nkPragmaExpr, a[j].info)
if a[j][0].kind == nkPostfix:
var pf = newNodeI(nkPostfix, a[j][0].info)
pf.add a[j][0][0]
pf.add newSymNode(v)
p.add pf
else:
p.add newSymNode(v)
p.add a[j][1].copyTree
b.add p
elif a[j].kind == nkPostfix:
var pf = newNodeI(nkPostfix, a[j].info)
pf.add a[j][0]
pf.add newSymNode(v)
b.add pf
else:
b.add newSymNode(v)
b.add a[1]
Expand Down Expand Up @@ -2201,7 +2221,10 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
# name isn't changed (see taccent_highlight). We don't want to check if this is the
# defintion yet since we are missing some info (comments, side effects)
s = semIdentDef(c, n[namePos], kind, reportToNimsuggest=isHighlight)
n[namePos] = newSymNode(s)
if n[namePos].kind == nkPostfix:
n[namePos][1] = newSymNode(s)
else:
n[namePos] = newSymNode(s)
when false:
# disable for now
if sfNoForward in c.module.flags and
Expand Down
5 changes: 4 additions & 1 deletion compiler/semtempl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,10 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
incl(s.flags, sfNoalias)
pushOwner(c, s)
openScope(c)
n[namePos] = newSymNode(s)
if n[namePos].kind == nkPostfix:
n[namePos][1] = newSymNode(s)
else:
n[namePos] = newSymNode(s)
pragmaCallable(c, s, n, templatePragmas)
implicitPragmas(c, s, n.info, templatePragmas)

Expand Down
10 changes: 10 additions & 0 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,16 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
fSym.sym.ast.flags.incl nfSkipFieldChecking
if a.kind == nkEmpty: father.add fSym
else: a.add fSym
if n[i].kind == nkPragmaExpr:
if n[i][0].kind == nkPostfix:
n[i][0][1] = fSym
else:
n[i][0] = fSym
else:
if n[i].kind == nkPostfix:
n[i][1] = fSym
else:
n[i] = fSym
styleCheckDef(c, f)
onDef(f.info, f)
if a.kind != nkEmpty: father.add a
Expand Down
7 changes: 5 additions & 2 deletions compiler/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ proc transformVarSection(c: PTransf, v: PNode): PNode =
elif it.kind == nkIdentDefs:
var vn = it[0]
if vn.kind == nkPragmaExpr: vn = vn[0]
if vn.kind == nkPostfix: vn = vn[1]
if vn.kind == nkSym:
internalAssert(c.graph.config, it.len == 3)
let x = freshVar(c, vn.sym)
Expand Down Expand Up @@ -327,8 +328,10 @@ proc introduceNewLocalVars(c: PTransf, n: PNode): PNode =
return n
of nkProcDef: # todo optimize nosideeffects?
result = newTransNode(n)
let x = newSymNode(copySym(n[namePos].sym, c.idgen))
idNodeTablePut(c.transCon.mapping, n[namePos].sym, x)
var name = n[namePos]
if name.kind == nkPostfix: name = name[1]
let x = newSymNode(copySym(name.sym, c.idgen))
idNodeTablePut(c.transCon.mapping, name.sym, x)
result[namePos] = x # we have to copy proc definitions for iters
for i in 1..<n.len:
result[i] = introduceNewLocalVars(c, n[i])
Expand Down

0 comments on commit a15c2f0

Please sign in to comment.