Rewrite in order to not introduce a new node kind.
This commit is contained in:
parent
b38eb2e2a8
commit
c35fc2bb03
5 changed files with 9 additions and 8 deletions
|
|
@ -221,7 +221,6 @@ type
|
||||||
nkGotoState, # used for the state machine (for iterators)
|
nkGotoState, # used for the state machine (for iterators)
|
||||||
nkState, # give a label to a code section (for iterators)
|
nkState, # give a label to a code section (for iterators)
|
||||||
nkBreakState, # special break statement for easier code generation
|
nkBreakState, # special break statement for easier code generation
|
||||||
nkUnderscore, # underscore inside a tuple unpack ``(_, x) = foo()``
|
|
||||||
TNodeKinds* = set[TNodeKind]
|
TNodeKinds* = set[TNodeKind]
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,6 @@ proc considerQuotedIdent*(n: PNode): PIdent =
|
||||||
case n.kind
|
case n.kind
|
||||||
of nkIdent: result = n.ident
|
of nkIdent: result = n.ident
|
||||||
of nkSym: result = n.sym.name
|
of nkSym: result = n.sym.name
|
||||||
of nkUnderscore: result = getIdent"_"
|
|
||||||
of nkAccQuoted:
|
of nkAccQuoted:
|
||||||
case n.len
|
case n.len
|
||||||
of 0:
|
of 0:
|
||||||
|
|
|
||||||
|
|
@ -296,14 +296,14 @@ proc colcom(p: var TParser, n: PNode) =
|
||||||
skipComment(p, n)
|
skipComment(p, n)
|
||||||
|
|
||||||
proc parseSymbol(p: var TParser, allowNil = false): PNode =
|
proc parseSymbol(p: var TParser, allowNil = false): PNode =
|
||||||
#| symbol = '`' (KEYW|IDENT|literal|(operator|'('|')'|'['|']'|'{'|'}'|'='|'_')+)+ '`'
|
#| symbol = '`' (KEYW|IDENT|literal|(operator|'('|')'|'['|']'|'{'|'}'|'=')+)+ '`'
|
||||||
#| | IDENT | 'addr' | 'type'
|
#| | IDENT | 'addr' | 'type'
|
||||||
case p.tok.tokType
|
case p.tok.tokType
|
||||||
of tkSymbol, tkAddr, tkType:
|
of tkSymbol, tkAddr, tkType:
|
||||||
result = newIdentNodeP(p.tok.ident, p)
|
result = newIdentNodeP(p.tok.ident, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
of tkUnderscore:
|
of tkUnderscore:
|
||||||
result = newNodeP(nkUnderscore, p)
|
result = newIdentNodeP(getIdent("_"), p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
of tkAccent:
|
of tkAccent:
|
||||||
result = newNodeP(nkAccQuoted, p)
|
result = newNodeP(nkAccQuoted, p)
|
||||||
|
|
@ -647,7 +647,7 @@ proc identOrLiteral(p: var TParser, mode: TPrimaryMode): PNode =
|
||||||
result = newNodeP(nkNilLit, p)
|
result = newNodeP(nkNilLit, p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
of tkUnderscore:
|
of tkUnderscore:
|
||||||
result = newNodeP(nkUnderscore, p)
|
result = newIdentNodeP(getIdent("_"), p)
|
||||||
getTok(p)
|
getTok(p)
|
||||||
of tkParLe:
|
of tkParLe:
|
||||||
# () constructor
|
# () constructor
|
||||||
|
|
|
||||||
|
|
@ -349,7 +349,6 @@ proc atom(n: PNode): string =
|
||||||
else:
|
else:
|
||||||
result = litAux(n, (cast[PInt64](addr(n.floatVal)))[], 8) & "\'f64"
|
result = litAux(n, (cast[PInt64](addr(n.floatVal)))[], 8) & "\'f64"
|
||||||
of nkNilLit: result = "nil"
|
of nkNilLit: result = "nil"
|
||||||
of nkUnderscore: result = "_"
|
|
||||||
of nkType:
|
of nkType:
|
||||||
if (n.typ != nil) and (n.typ.sym != nil): result = n.typ.sym.name.s
|
if (n.typ != nil) and (n.typ.sym != nil): result = n.typ.sym.name.s
|
||||||
else: result = "[type node]"
|
else: result = "[type node]"
|
||||||
|
|
@ -806,7 +805,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
of nkTripleStrLit: putRawStr(g, tkTripleStrLit, n.strVal)
|
of nkTripleStrLit: putRawStr(g, tkTripleStrLit, n.strVal)
|
||||||
of nkEmpty: discard
|
of nkEmpty: discard
|
||||||
of nkType: put(g, tkInvalid, atom(n))
|
of nkType: put(g, tkInvalid, atom(n))
|
||||||
of nkSym, nkIdent, nkUnderscore: gident(g, n)
|
of nkSym, nkIdent: gident(g, n)
|
||||||
of nkIntLit: put(g, tkIntLit, atom(n))
|
of nkIntLit: put(g, tkIntLit, atom(n))
|
||||||
of nkInt8Lit: put(g, tkInt8Lit, atom(n))
|
of nkInt8Lit: put(g, tkInt8Lit, atom(n))
|
||||||
of nkInt16Lit: put(g, tkInt16Lit, atom(n))
|
of nkInt16Lit: put(g, tkInt16Lit, atom(n))
|
||||||
|
|
|
||||||
|
|
@ -340,6 +340,10 @@ proc checkNilable(v: PSym) =
|
||||||
elif tfNotNil in v.typ.flags and tfNotNil notin v.ast.typ.flags:
|
elif tfNotNil in v.typ.flags and tfNotNil notin v.ast.typ.flags:
|
||||||
message(v.info, warnProveInit, v.name.s)
|
message(v.info, warnProveInit, v.name.s)
|
||||||
|
|
||||||
|
proc isDiscardUnderscore(n: PNode): bool =
|
||||||
|
if n.kind != nkIdent: return false
|
||||||
|
return n.ident.s == "_"
|
||||||
|
|
||||||
proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||||
var b: PNode
|
var b: PNode
|
||||||
result = copyNode(n)
|
result = copyNode(n)
|
||||||
|
|
@ -404,7 +408,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
|
||||||
for j in countup(0, length-3):
|
for j in countup(0, length-3):
|
||||||
var v = semIdentDef(c, a.sons[j], symkind)
|
var v = semIdentDef(c, a.sons[j], symkind)
|
||||||
if sfGenSym notin v.flags and
|
if sfGenSym notin v.flags and
|
||||||
a.sons[j].kind != nkUnderscore: addInterfaceDecl(c, v)
|
not isDiscardUnderscore(a.sons[j]): addInterfaceDecl(c, v)
|
||||||
when oKeepVariableNames:
|
when oKeepVariableNames:
|
||||||
if c.inUnrolledContext > 0: v.flags.incl(sfShadowed)
|
if c.inUnrolledContext > 0: v.flags.incl(sfShadowed)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue