diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-04-05 15:46:56 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2015-04-05 15:46:56 +0100 |
commit | c35fc2bb03860a4f1e1f81cda050d899652bce20 (patch) | |
tree | 3a8d6f10a596c243a4bfb35cc11a36f58f6ec41d /compiler | |
parent | b38eb2e2a84537c315f28e9f823c10363be8cdb1 (diff) | |
download | Nim-c35fc2bb03860a4f1e1f81cda050d899652bce20.tar.gz |
Rewrite in order to not introduce a new node kind.
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ast.nim | 1 | ||||
-rw-r--r-- | compiler/lookups.nim | 1 | ||||
-rw-r--r-- | compiler/parser.nim | 6 | ||||
-rw-r--r-- | compiler/renderer.nim | 3 | ||||
-rw-r--r-- | compiler/semstmts.nim | 6 |
5 files changed, 9 insertions, 8 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 8ff38a12f..10f2a71da 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -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 diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 8cfb5ed25..88e32404a 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -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: diff --git a/compiler/parser.nim b/compiler/parser.nim index 0b2619b01..49b4430ab 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -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 diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 2e614dde0..ce818e3cd 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -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)) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 5b7cca338..f49ab264d 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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: |