Rewrite in order to not introduce a new node kind.

This commit is contained in:
Dominik Picheta
2015-04-05 15:46:56 +01:00
parent b38eb2e2a8
commit c35fc2bb03
5 changed files with 9 additions and 8 deletions

View File

@@ -221,7 +221,6 @@ type
nkGotoState, # used for the state machine (for iterators)
nkState, # give a label to a code section (for iterators)
nkBreakState, # special break statement for easier code generation
nkUnderscore, # underscore inside a tuple unpack ``(_, x) = foo()``
TNodeKinds* = set[TNodeKind]
type

View File

@@ -20,7 +20,6 @@ proc considerQuotedIdent*(n: PNode): PIdent =
case n.kind
of nkIdent: result = n.ident
of nkSym: result = n.sym.name
of nkUnderscore: result = getIdent"_"
of nkAccQuoted:
case n.len
of 0:

View File

@@ -296,14 +296,14 @@ proc colcom(p: var TParser, n: PNode) =
skipComment(p, n)
proc parseSymbol(p: var TParser, allowNil = false): PNode =
#| symbol = '`' (KEYW|IDENT|literal|(operator|'('|')'|'['|']'|'{'|'}'|'='|'_')+)+ '`'
#| symbol = '`' (KEYW|IDENT|literal|(operator|'('|')'|'['|']'|'{'|'}'|'=')+)+ '`'
#| | IDENT | 'addr' | 'type'
case p.tok.tokType
of tkSymbol, tkAddr, tkType:
result = newIdentNodeP(p.tok.ident, p)
getTok(p)
of tkUnderscore:
result = newNodeP(nkUnderscore, p)
result = newIdentNodeP(getIdent("_"), p)
getTok(p)
of tkAccent:
result = newNodeP(nkAccQuoted, p)
@@ -647,7 +647,7 @@ proc identOrLiteral(p: var TParser, mode: TPrimaryMode): PNode =
result = newNodeP(nkNilLit, p)
getTok(p)
of tkUnderscore:
result = newNodeP(nkUnderscore, p)
result = newIdentNodeP(getIdent("_"), p)
getTok(p)
of tkParLe:
# () constructor

View File

@@ -349,7 +349,6 @@ proc atom(n: PNode): string =
else:
result = litAux(n, (cast[PInt64](addr(n.floatVal)))[], 8) & "\'f64"
of nkNilLit: result = "nil"
of nkUnderscore: result = "_"
of nkType:
if (n.typ != nil) and (n.typ.sym != nil): result = n.typ.sym.name.s
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 nkEmpty: discard
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 nkInt8Lit: put(g, tkInt8Lit, atom(n))
of nkInt16Lit: put(g, tkInt16Lit, atom(n))

View File

@@ -340,6 +340,10 @@ proc checkNilable(v: PSym) =
elif tfNotNil in v.typ.flags and tfNotNil notin v.ast.typ.flags:
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 =
var b: PNode
result = copyNode(n)
@@ -404,7 +408,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
for j in countup(0, length-3):
var v = semIdentDef(c, a.sons[j], symkind)
if sfGenSym notin v.flags and
a.sons[j].kind != nkUnderscore: addInterfaceDecl(c, v)
not isDiscardUnderscore(a.sons[j]): addInterfaceDecl(c, v)
when oKeepVariableNames:
if c.inUnrolledContext > 0: v.flags.incl(sfShadowed)
else: