diff --git a/compiler/ast.nim b/compiler/ast.nim index 90885a71f2..36cafe6f35 100755 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -259,7 +259,10 @@ const sfImmediate* = sfDeadCodeElim # macro or template is immediately expanded # without considering any possible overloads - + + sfDirty* = sfPure + # template is not hygienic (old styled template) + sfAnon* = sfDiscardable # symbol name that was generated by the compiler # the compiler will avoid printing such names @@ -691,7 +694,8 @@ const # creator procs: -proc NewSym*(symKind: TSymKind, Name: PIdent, owner: PSym): PSym +proc NewSym*(symKind: TSymKind, Name: PIdent, owner: PSym, + info: TLineInfo): PSym proc NewType*(kind: TTypeKind, owner: PSym): PType proc newNode*(kind: TNodeKind): PNode proc newIntNode*(kind: TNodeKind, intVal: BiggestInt): PNode @@ -922,11 +926,10 @@ proc copyType(t: PType, owner: PSym, keepId: bool): PType = result.sym = t.sym # backend-info should not be copied proc copySym(s: PSym, keepId: bool = false): PSym = - result = newSym(s.kind, s.name, s.owner) + result = newSym(s.kind, s.name, s.owner, s.info) result.ast = nil # BUGFIX; was: s.ast which made problems - result.info = s.info result.typ = s.typ - if keepId: + if keepId: result.id = s.id else: result.id = getID() @@ -939,13 +942,14 @@ proc copySym(s: PSym, keepId: bool = false): PSym = result.loc = s.loc result.annex = s.annex # BUGFIX -proc NewSym(symKind: TSymKind, Name: PIdent, owner: PSym): PSym = +proc NewSym(symKind: TSymKind, Name: PIdent, owner: PSym, + info: TLineInfo): PSym = # generates a symbol and initializes the hash field too new(result) result.Name = Name result.Kind = symKind result.flags = {} - result.info = UnknownLineInfo() + result.info = info result.options = gOptions result.owner = owner result.offset = - 1 diff --git a/compiler/evals.nim b/compiler/evals.nim index e17ab2c6c6..58f797e14d 100755 --- a/compiler/evals.nim +++ b/compiler/evals.nim @@ -254,7 +254,7 @@ proc getNullValue(typ: PType, info: TLineInfo): PNode = for i in countup(0, sonsLen(t) - 1): var p = newNodeIT(nkExprColonExpr, info, t.sons[i]) var field = if t.n != nil: t.n.sons[i].sym else: newSym( - skField, getIdent(":tmp" & $i), t.owner) + skField, getIdent(":tmp" & $i), t.owner, info) addSon(p, newSymNode(field, info)) addSon(p, getNullValue(t.sons[i], info)) addSon(result, p) @@ -1358,7 +1358,7 @@ proc evalMacroCall*(c: PEvalContext, n: PNode, sym: PSym): PNode = if evalTemplateCounter > 100: GlobalError(n.info, errTemplateInstantiationTooNested) - inc genSymBaseId + #inc genSymBaseId var s = newStackFrame() s.call = n setlen(s.params, 2) diff --git a/compiler/idgen.nim b/compiler/idgen.nim index d2e322796d..fbf450c903 100644 --- a/compiler/idgen.nim +++ b/compiler/idgen.nim @@ -11,7 +11,7 @@ import idents, strutils, os, options -var gFrontEndId, gBackendId*, genSymBaseId*: int +var gFrontEndId, gBackendId*: int const debugIds* = false @@ -34,9 +34,6 @@ proc backendId*(): int {.inline.} = result = gBackendId inc(gBackendId) -proc genSym*(basename: string): PIdent = - result = getIdent(basename & $genSymBaseId) - proc setId*(id: int) {.inline.} = gFrontEndId = max(gFrontEndId, id + 1) @@ -66,4 +63,3 @@ proc loadMaxIds*(project: string) = gFrontEndId = max(gFrontEndId, frontEndId) gBackEndId = max(gBackEndId, backEndId) f.close() - diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 057444b2a5..0748b99b3f 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -162,7 +162,7 @@ proc newEnv(outerProc: PSym, up: PEnv, n: PNode): PEnv = result.attachedNode = n proc addField(tup: PType, s: PSym) = - var field = newSym(skField, s.name, s.owner) + var field = newSym(skField, s.name, s.owner, s.info) let t = skipIntLit(s.typ) field.typ = t field.position = sonsLen(tup) @@ -179,7 +179,7 @@ proc addDep(e, d: PEnv, owner: PSym): PSym = for x, field in items(e.deps): if x == d: return field var pos = sonsLen(e.tup) - result = newSym(skField, getIdent(upName & $pos), owner) + result = newSym(skField, getIdent(upName & $pos), owner, owner.info) result.typ = newType(tyRef, owner) result.position = pos assert d.tup != nil @@ -220,8 +220,7 @@ proc isInnerProc(s, outerProc: PSym): bool {.inline.} = #s.typ.callConv == ccClosure proc addClosureParam(i: PInnerContext, e: PEnv) = - var cp = newSym(skParam, getIdent(paramname), i.fn) - cp.info = i.fn.info + var cp = newSym(skParam, getIdent(paramname), i.fn, i.fn.info) incl(cp.flags, sfFromGeneric) cp.typ = newType(tyRef, i.fn) rawAddSon(cp.typ, e.tup) @@ -449,9 +448,8 @@ proc addVar*(father, v: PNode) = proc getClosureVar(o: POuterContext, e: PEnv): PSym = if e.closure == nil: - result = newSym(skVar, getIdent(envName), o.fn) + result = newSym(skVar, getIdent(envName), o.fn, e.attachedNode.info) incl(result.flags, sfShadowed) - result.info = e.attachedNode.info result.typ = newType(tyRef, o.fn) result.typ.rawAddSon(e.tup) e.closure = result @@ -590,8 +588,7 @@ type tup: PType proc newIterResult(iter: PSym): PSym = - result = newSym(skResult, getIdent":result", iter) - result.info = iter.info + result = newSym(skResult, getIdent":result", iter, iter.info) result.typ = iter.typ.sons[0] incl(result.flags, sfUsed) @@ -650,15 +647,14 @@ proc liftIterator*(iter: PSym, body: PNode): PNode = c.tup = newType(tyTuple, iter) c.tup.n = newNodeI(nkRecList, iter.info) - var cp = newSym(skParam, getIdent(paramname), iter) - cp.info = iter.info + var cp = newSym(skParam, getIdent(paramname), iter, iter.info) incl(cp.flags, sfFromGeneric) cp.typ = newType(tyRef, iter) rawAddSon(cp.typ, c.tup) c.closureParam = cp addHiddenParam(iter, cp) - c.state = newSym(skField, getIdent(":state"), iter) + c.state = newSym(skField, getIdent(":state"), iter, iter.info) c.state.typ = getStateType(iter) addField(c.tup, c.state) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 556f6eb4aa..9ab5d2c48e 100755 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -22,18 +22,14 @@ proc considerAcc*(n: PNode): PIdent = of 0: GlobalError(n.info, errIdentifierExpected, renderTree(n)) of 1: result = considerAcc(n.sons[0]) else: - if n.len == 2 and n[0].kind == nkIdent and n[0].ident.id == ord(wStar): - # XXX find a better way instead of `*x` for 'genSym' - result = genSym(n[1].ident.s) - else: - var id = "" - for i in 0..