refactoring: remove idents.legacy global variable and pass the IdentCache around explicitly

This commit is contained in:
Andreas Rumpf 2018-05-27 22:09:15 +02:00
commit 40ec7be45c
41 changed files with 338 additions and 353 deletions

View file

@ -22,13 +22,13 @@ proc noidentError(conf: ConfigRef; n, origin: PNode) =
m.add "identifier expected, but found '" & n.renderTree & "'"
localError(conf, n.info, m)
proc considerQuotedIdent*(conf: ConfigRef; n: PNode, origin: PNode = nil): PIdent =
proc considerQuotedIdent*(c: PContext; n: PNode, origin: PNode = nil): PIdent =
## Retrieve a PIdent from a PNode, taking into account accent nodes.
## ``origin`` can be nil. If it is not nil, it is used for a better
## error message.
template handleError(n, origin: PNode) =
noidentError(conf, n, origin)
result = getIdent"<Error>"
noidentError(c.config, n, origin)
result = getIdent(c.cache, "<Error>")
case n.kind
of nkIdent: result = n.ident
@ -36,7 +36,7 @@ proc considerQuotedIdent*(conf: ConfigRef; n: PNode, origin: PNode = nil): PIden
of nkAccQuoted:
case n.len
of 0: handleError(n, origin)
of 1: result = considerQuotedIdent(conf, n.sons[0], origin)
of 1: result = considerQuotedIdent(c, n.sons[0], origin)
else:
var id = ""
for i in 0..<n.len:
@ -46,7 +46,7 @@ proc considerQuotedIdent*(conf: ConfigRef; n: PNode, origin: PNode = nil): PIden
of nkSym: id.add(x.sym.name.s)
of nkLiterals - nkFloatLiterals: id.add(x.renderTree)
else: handleError(n, origin)
result = getIdent(id)
result = getIdent(c.cache, id)
of nkOpenSymChoice, nkClosedSymChoice:
if n[0].kind == nkSym:
result = n.sons[0].sym.name
@ -126,9 +126,9 @@ proc errorSym*(c: PContext, n: PNode): PSym =
# ensure that 'considerQuotedIdent' can't fail:
if m.kind == nkDotExpr: m = m.sons[1]
let ident = if m.kind in {nkIdent, nkSym, nkAccQuoted}:
considerQuotedIdent(c.config, m)
considerQuotedIdent(c, m)
else:
getIdent("err:" & renderTree(m))
getIdent(c.cache, "err:" & renderTree(m))
result = newSym(skError, ident, getCurrOwner(c), n.info, {})
result.typ = errorType(c)
incl(result.flags, sfDiscardable)
@ -140,7 +140,7 @@ type
TOverloadIterMode* = enum
oimDone, oimNoQualifier, oimSelfModule, oimOtherModule, oimSymChoice,
oimSymChoiceLocalLookup
TOverloadIter*{.final.} = object
TOverloadIter* = object
it*: TIdentIter
m*: PSym
mode*: TOverloadIterMode
@ -277,7 +277,7 @@ proc lookUp*(c: PContext, n: PNode): PSym =
of nkSym:
result = n.sym
of nkAccQuoted:
var ident = considerQuotedIdent(c.config, n)
var ident = considerQuotedIdent(c, n)
result = searchInScopes(c, ident).skipAlias(n, c.config)
if result == nil:
fixSpelling(n, ident, searchInScopes)
@ -298,7 +298,7 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym =
const allExceptModule = {low(TSymKind)..high(TSymKind)}-{skModule,skPackage}
case n.kind
of nkIdent, nkAccQuoted:
var ident = considerQuotedIdent(c.config, n)
var ident = considerQuotedIdent(c, n)
if checkModule in flags:
result = searchInScopes(c, ident).skipAlias(n, c.config)
else:
@ -324,7 +324,7 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym =
if n.sons[1].kind == nkIdent:
ident = n.sons[1].ident
elif n.sons[1].kind == nkAccQuoted:
ident = considerQuotedIdent(c.config, n.sons[1])
ident = considerQuotedIdent(c, n.sons[1])
if ident != nil:
if m == c.module:
result = strTableGet(c.topLevelScope.symbols, ident).skipAlias(n, c.config)
@ -348,7 +348,7 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags: set[TLookupFlag]): PSym =
proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
case n.kind
of nkIdent, nkAccQuoted:
var ident = considerQuotedIdent(c.config, n)
var ident = considerQuotedIdent(c, n)
o.scope = c.currentScope
o.mode = oimNoQualifier
while true:
@ -369,7 +369,7 @@ proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
if n.sons[1].kind == nkIdent:
ident = n.sons[1].ident
elif n.sons[1].kind == nkAccQuoted:
ident = considerQuotedIdent(c.config, n.sons[1], n)
ident = considerQuotedIdent(c, n.sons[1], n)
if ident != nil:
if o.m == c.module:
# a module may access its private members: