Renamed 'considerAcc' to 'considerAccents' for clarity

Added documentation string to 'considerAccents'
Modified renderParamType's assertion to allow nkAcc nodes.
This commit is contained in:
Clay Sweetser 2014-05-24 08:10:40 -04:00
commit 055cdb2cdf
12 changed files with 33 additions and 33 deletions

View file

@ -93,7 +93,7 @@ proc rawImportSymbol(c: PContext, s: PSym) =
if hasPattern(s): addPattern(c, s) if hasPattern(s): addPattern(c, s)
proc importSymbol(c: PContext, n: PNode, fromMod: PSym) = proc importSymbol(c: PContext, n: PNode, fromMod: PSym) =
let ident = lookups.considerAcc(n) let ident = lookups.considerAccents(n)
let s = strTableGet(fromMod.tab, ident) let s = strTableGet(fromMod.tab, ident)
if s == nil: if s == nil:
localError(n.info, errUndeclaredIdentifier, ident.s) localError(n.info, errUndeclaredIdentifier, ident.s)
@ -193,7 +193,7 @@ proc evalImportExcept*(c: PContext, n: PNode): PNode =
addDecl(c, m) # add symbol to symbol table of module addDecl(c, m) # add symbol to symbol table of module
var exceptSet = initIntSet() var exceptSet = initIntSet()
for i in countup(1, sonsLen(n) - 1): for i in countup(1, sonsLen(n) - 1):
let ident = lookups.considerAcc(n.sons[i]) let ident = lookups.considerAccents(n.sons[i])
exceptSet.incl(ident.id) exceptSet.incl(ident.id)
importAllSymbolsExcept(c, m, exceptSet) importAllSymbolsExcept(c, m, exceptSet)
importForwarded(c, m.ast, exceptSet) importForwarded(c, m.ast, exceptSet)

View file

@ -15,14 +15,14 @@ import
proc ensureNoMissingOrUnusedSymbols(scope: PScope) proc ensureNoMissingOrUnusedSymbols(scope: PScope)
proc considerAcc*(n: PNode): PIdent = proc considerAccents*(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 nkAccQuoted: of nkAccQuoted:
case n.len case n.len
of 0: globalError(n.info, errIdentifierExpected, renderTree(n)) of 0: globalError(n.info, errIdentifierExpected, renderTree(n))
of 1: result = considerAcc(n.sons[0]) of 1: result = considerAccents(n.sons[0])
else: else:
var id = "" var id = ""
for i in 0.. <n.len: for i in 0.. <n.len:
@ -82,10 +82,10 @@ proc searchInScopes*(c: PContext, s: PIdent, filter: TSymKinds): PSym =
proc errorSym*(c: PContext, n: PNode): PSym = proc errorSym*(c: PContext, n: PNode): PSym =
## creates an error symbol to avoid cascading errors (for IDE support) ## creates an error symbol to avoid cascading errors (for IDE support)
var m = n var m = n
# ensure that 'considerAcc' can't fail: # ensure that 'considerAccents' can't fail:
if m.kind == nkDotExpr: m = m.sons[1] if m.kind == nkDotExpr: m = m.sons[1]
let ident = if m.kind in {nkIdent, nkSym, nkAccQuoted}: let ident = if m.kind in {nkIdent, nkSym, nkAccQuoted}:
considerAcc(m) considerAccents(m)
else: else:
getIdent("err:" & renderTree(m)) getIdent("err:" & renderTree(m))
result = newSym(skError, ident, getCurrOwner(), n.info) result = newSym(skError, ident, getCurrOwner(), n.info)
@ -189,7 +189,7 @@ proc lookUp*(c: PContext, n: PNode): PSym =
of nkSym: of nkSym:
result = n.sym result = n.sym
of nkAccQuoted: of nkAccQuoted:
var ident = considerAcc(n) var ident = considerAccents(n)
result = searchInScopes(c, ident) result = searchInScopes(c, ident)
if result == nil: if result == nil:
localError(n.info, errUndeclaredIdentifier, ident.s) localError(n.info, errUndeclaredIdentifier, ident.s)
@ -208,7 +208,7 @@ type
proc qualifiedLookUp*(c: PContext, n: PNode, flags = {checkUndeclared}): PSym = proc qualifiedLookUp*(c: PContext, n: PNode, flags = {checkUndeclared}): PSym =
case n.kind case n.kind
of nkIdent, nkAccQuoted: of nkIdent, nkAccQuoted:
var ident = considerAcc(n) var ident = considerAccents(n)
result = searchInScopes(c, ident) result = searchInScopes(c, ident)
if result == nil and checkUndeclared in flags: if result == nil and checkUndeclared in flags:
localError(n.info, errUndeclaredIdentifier, ident.s) localError(n.info, errUndeclaredIdentifier, ident.s)
@ -228,7 +228,7 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags = {checkUndeclared}): PSym =
if n.sons[1].kind == nkIdent: if n.sons[1].kind == nkIdent:
ident = n.sons[1].ident ident = n.sons[1].ident
elif n.sons[1].kind == nkAccQuoted: elif n.sons[1].kind == nkAccQuoted:
ident = considerAcc(n.sons[1]) ident = considerAccents(n.sons[1])
if ident != nil: if ident != nil:
if m == c.module: if m == c.module:
result = strTableGet(c.topLevelScope.symbols, ident) result = strTableGet(c.topLevelScope.symbols, ident)
@ -251,7 +251,7 @@ proc qualifiedLookUp*(c: PContext, n: PNode, flags = {checkUndeclared}): PSym =
proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym = proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
case n.kind case n.kind
of nkIdent, nkAccQuoted: of nkIdent, nkAccQuoted:
var ident = considerAcc(n) var ident = considerAccents(n)
o.scope = c.currentScope o.scope = c.currentScope
o.mode = oimNoQualifier o.mode = oimNoQualifier
while true: while true:
@ -272,7 +272,7 @@ proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
if n.sons[1].kind == nkIdent: if n.sons[1].kind == nkIdent:
ident = n.sons[1].ident ident = n.sons[1].ident
elif n.sons[1].kind == nkAccQuoted: elif n.sons[1].kind == nkAccQuoted:
ident = considerAcc(n.sons[1]) ident = considerAccents(n.sons[1])
if ident != nil: if ident != nil:
if o.m == c.module: if o.m == c.module:
# a module may access its private members: # a module may access its private members:
@ -354,5 +354,5 @@ when false:
if sfImmediate in a.flags: return a if sfImmediate in a.flags: return a
a = nextOverloadIter(o, c, n) a = nextOverloadIter(o, c, n)
if result == nil and checkUndeclared in flags: if result == nil and checkUndeclared in flags:
localError(n.info, errUndeclaredIdentifier, n.considerAcc.s) localError(n.info, errUndeclaredIdentifier, n.considerAccents.s)
result = errorSym(c, n) result = errorSym(c, n)

View file

@ -517,7 +517,7 @@ proc pragmaUses(c: PContext, n: PNode) =
proc processExc(c: PContext, x: PNode): PNode = proc processExc(c: PContext, x: PNode): PNode =
if x.kind in {nkAccQuoted, nkIdent, nkSym, if x.kind in {nkAccQuoted, nkIdent, nkSym,
nkOpenSymChoice, nkClosedSymChoice}: nkOpenSymChoice, nkClosedSymChoice}:
if considerAcc(x).s == "*": if considerAccents(x).s == "*":
return newSymNode(ast.anyGlobal) return newSymNode(ast.anyGlobal)
result = c.semExpr(c, x) result = c.semExpr(c, x)
if result.kind != nkSym or sfGlobal notin result.sym.flags: if result.kind != nkSym or sfGlobal notin result.sym.flags:

View file

@ -134,7 +134,7 @@ proc isTopLevel(c: PContext): bool {.inline.} =
result = c.currentScope.depthLevel <= 2 result = c.currentScope.depthLevel <= 2
proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym = proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym =
result = newSym(kind, considerAcc(n), getCurrOwner(), n.info) result = newSym(kind, considerAccents(n), getCurrOwner(), n.info)
proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym = proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
# like newSymS, but considers gensym'ed symbols # like newSymS, but considers gensym'ed symbols
@ -147,7 +147,7 @@ proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym =
# template; we must fix it here: see #909 # template; we must fix it here: see #909
result.owner = getCurrOwner() result.owner = getCurrOwner()
else: else:
result = newSym(kind, considerAcc(n), getCurrOwner(), n.info) result = newSym(kind, considerAccents(n), getCurrOwner(), n.info)
proc semIdentVis(c: PContext, kind: TSymKind, n: PNode, proc semIdentVis(c: PContext, kind: TSymKind, n: PNode,
allowed: TSymFlags): PSym allowed: TSymFlags): PSym

View file

@ -168,7 +168,7 @@ proc resolveOverloads(c: PContext, n, orig: PNode,
pickBest(callOp) pickBest(callOp)
if overloadsState == csEmpty and result.state == csEmpty: if overloadsState == csEmpty and result.state == csEmpty:
localError(n.info, errUndeclaredIdentifier, considerAcc(f).s) localError(n.info, errUndeclaredIdentifier, considerAccents(f).s)
return return
elif result.state != csMatch: elif result.state != csMatch:
if nfExprCall in n.flags: if nfExprCall in n.flags:

View file

@ -387,7 +387,7 @@ proc semOpAux(c: PContext, n: PNode) =
var a = n.sons[i] var a = n.sons[i]
if a.kind == nkExprEqExpr and sonsLen(a) == 2: if a.kind == nkExprEqExpr and sonsLen(a) == 2:
var info = a.sons[0].info var info = a.sons[0].info
a.sons[0] = newIdentNode(considerAcc(a.sons[0]), info) a.sons[0] = newIdentNode(considerAccents(a.sons[0]), info)
a.sons[1] = semExprWithType(c, a.sons[1], flags) a.sons[1] = semExprWithType(c, a.sons[1], flags)
a.typ = a.sons[1].typ a.typ = a.sons[1].typ
else: else:
@ -970,7 +970,7 @@ proc builtinFieldAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
n.sons[0] = semExprWithType(c, n.sons[0], flags+{efDetermineType}) n.sons[0] = semExprWithType(c, n.sons[0], flags+{efDetermineType})
#restoreOldStyleType(n.sons[0]) #restoreOldStyleType(n.sons[0])
var i = considerAcc(n.sons[1]) var i = considerAccents(n.sons[1])
var ty = n.sons[0].typ var ty = n.sons[0].typ
var f: PSym = nil var f: PSym = nil
result = nil result = nil
@ -1051,7 +1051,7 @@ proc dotTransformation(c: PContext, n: PNode): PNode =
addSon(result, n.sons[1]) addSon(result, n.sons[1])
addSon(result, copyTree(n[0])) addSon(result, copyTree(n[0]))
else: else:
var i = considerAcc(n.sons[1]) var i = considerAccents(n.sons[1])
result = newNodeI(nkDotCall, n.info) result = newNodeI(nkDotCall, n.info)
result.flags.incl nfDotField result.flags.incl nfDotField
addSon(result, newIdentNode(i, n[1].info)) addSon(result, newIdentNode(i, n[1].info))
@ -1135,7 +1135,7 @@ proc semArrayAccess(c: PContext, n: PNode, flags: TExprFlags): PNode =
result = semExpr(c, buildOverloadedSubscripts(n, getIdent"[]")) result = semExpr(c, buildOverloadedSubscripts(n, getIdent"[]"))
proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode = proc propertyWriteAccess(c: PContext, n, nOrig, a: PNode): PNode =
var id = considerAcc(a[1]) var id = considerAccents(a[1])
var setterId = newIdentNode(getIdent(id.s & '='), n.info) var setterId = newIdentNode(getIdent(id.s & '='), n.info)
# a[0] is already checked for semantics, that does ``builtinFieldAccess`` # a[0] is already checked for semantics, that does ``builtinFieldAccess``
# this is ugly. XXX Semantic checking should use the ``nfSem`` flag for # this is ugly. XXX Semantic checking should use the ``nfSem`` flag for
@ -1369,7 +1369,7 @@ proc lookUpForDefined(c: PContext, n: PNode, onlyCurrentScope: bool): PSym =
else: else:
localError(n.sons[1].info, errIdentifierExpected, "") localError(n.sons[1].info, errIdentifierExpected, "")
of nkAccQuoted: of nkAccQuoted:
result = lookUpForDefined(c, considerAcc(n), onlyCurrentScope) result = lookUpForDefined(c, considerAccents(n), onlyCurrentScope)
of nkSym: of nkSym:
result = n.sym result = n.sym
else: else:

View file

@ -69,7 +69,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym): PNode =
proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags, proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags,
ctx: var TIntSet): PNode = ctx: var TIntSet): PNode =
result = n result = n
let ident = considerAcc(n) let ident = considerAccents(n)
var s = searchInScopes(c, ident) var s = searchInScopes(c, ident)
if s == nil: if s == nil:
if ident.id notin ctx and withinMixin notin flags: if ident.id notin ctx and withinMixin notin flags:
@ -114,7 +114,7 @@ proc semGenericStmt(c: PContext, n: PNode,
let fn = n.sons[0] let fn = n.sons[0]
var s = qualifiedLookUp(c, fn, {}) var s = qualifiedLookUp(c, fn, {})
if s == nil and withinMixin notin flags and if s == nil and withinMixin notin flags and
fn.kind in {nkIdent, nkAccQuoted} and considerAcc(fn).id notin ctx: fn.kind in {nkIdent, nkAccQuoted} and considerAccents(fn).id notin ctx:
localError(n.info, errUndeclaredIdentifier, fn.renderTree) localError(n.info, errUndeclaredIdentifier, fn.renderTree)
var first = 0 var first = 0

View file

@ -868,7 +868,7 @@ proc lookupMacro(c: PContext, n: PNode): PSym =
result = n.sym result = n.sym
if result.kind notin {skMacro, skTemplate}: result = nil if result.kind notin {skMacro, skTemplate}: result = nil
else: else:
result = searchInScopes(c, considerAcc(n), {skMacro, skTemplate}) result = searchInScopes(c, considerAccents(n), {skMacro, skTemplate})
proc semProcAnnotation(c: PContext, prc: PNode): PNode = proc semProcAnnotation(c: PContext, prc: PNode): PNode =
var n = prc.sons[pragmasPos] var n = prc.sons[pragmasPos]
@ -879,7 +879,7 @@ proc semProcAnnotation(c: PContext, prc: PNode): PNode =
let m = lookupMacro(c, key) let m = lookupMacro(c, key)
if m == nil: if m == nil:
if key.kind == nkIdent and key.ident.id == ord(wDelegator): if key.kind == nkIdent and key.ident.id == ord(wDelegator):
if considerAcc(prc.sons[namePos]).s == "()": if considerAccents(prc.sons[namePos]).s == "()":
prc.sons[namePos] = newIdentNode(idDelegator, prc.info) prc.sons[namePos] = newIdentNode(idDelegator, prc.info)
prc.sons[pragmasPos] = copyExcept(n, i) prc.sons[pragmasPos] = copyExcept(n, i)
else: else:

View file

@ -93,7 +93,7 @@ proc semBindStmt(c: PContext, n: PNode, toBind: var TIntSet): PNode =
proc semMixinStmt(c: PContext, n: PNode, toMixin: var TIntSet): PNode = proc semMixinStmt(c: PContext, n: PNode, toMixin: var TIntSet): PNode =
for i in 0 .. < n.len: for i in 0 .. < n.len:
toMixin.incl(considerAcc(n.sons[i]).id) toMixin.incl(considerAccents(n.sons[i]).id)
result = newNodeI(nkEmpty, n.info) result = newNodeI(nkEmpty, n.info)
proc replaceIdentBySym(n: var PNode, s: PNode) = proc replaceIdentBySym(n: var PNode, s: PNode) =
@ -151,7 +151,7 @@ proc onlyReplaceParams(c: var TemplCtx, n: PNode): PNode =
result.sons[i] = onlyReplaceParams(c, n.sons[i]) result.sons[i] = onlyReplaceParams(c, n.sons[i])
proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym = proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym =
result = newSym(kind, considerAcc(n), c.owner, n.info) result = newSym(kind, considerAccents(n), c.owner, n.info)
incl(result.flags, sfGenSym) incl(result.flags, sfGenSym)
incl(result.flags, sfShadowed) incl(result.flags, sfShadowed)

View file

@ -116,7 +116,7 @@ proc semVarargs(c: PContext, n: PNode, prev: PType): PType =
var base = semTypeNode(c, n.sons[1], nil) var base = semTypeNode(c, n.sons[1], nil)
addSonSkipIntLit(result, base) addSonSkipIntLit(result, base)
if sonsLen(n) == 3: if sonsLen(n) == 3:
result.n = newIdentNode(considerAcc(n.sons[2]), n.sons[2].info) result.n = newIdentNode(considerAccents(n.sons[2]), n.sons[2].info)
else: else:
localError(n.info, errXExpectsOneTypeParam, "varargs") localError(n.info, errXExpectsOneTypeParam, "varargs")
addSonSkipIntLit(result, errorType(c)) addSonSkipIntLit(result, errorType(c))

View file

@ -497,11 +497,11 @@ proc matchUserTypeClass*(c: PContext, m: var TCandidate,
proc shouldSkipDistinct(rules: PNode, callIdent: PIdent): bool = proc shouldSkipDistinct(rules: PNode, callIdent: PIdent): bool =
if rules.kind == nkWith: if rules.kind == nkWith:
for r in rules: for r in rules:
if r.considerAcc == callIdent: return true if r.considerAccents == callIdent: return true
return false return false
else: else:
for r in rules: for r in rules:
if r.considerAcc == callIdent: return false if r.considerAccents == callIdent: return false
return true return true
proc maybeSkipDistinct(t: PType, callee: PSym): PType = proc maybeSkipDistinct(t: PType, callee: PSym): PType =
@ -1302,7 +1302,7 @@ proc prepareOperand(c: PContext; a: PNode): PNode =
proc prepareNamedParam(a: PNode) = proc prepareNamedParam(a: PNode) =
if a.sons[0].kind != nkIdent: if a.sons[0].kind != nkIdent:
var info = a.sons[0].info var info = a.sons[0].info
a.sons[0] = newIdentNode(considerAcc(a.sons[0]), info) a.sons[0] = newIdentNode(considerAccents(a.sons[0]), info)
proc arrayConstr(c: PContext, n: PNode): PType = proc arrayConstr(c: PContext, n: PNode): PType =
result = newTypeS(tyArrayConstr, c) result = newTypeS(tyArrayConstr, c)

View file

@ -1,4 +1,4 @@
import renderer, strutils, ast, msgs, types import renderer, strutils, ast, msgs, types, astalgo
const defaultParamSeparator* = "," const defaultParamSeparator* = ","
@ -92,7 +92,7 @@ proc renderParamTypes(found: var seq[string], n: PNode) =
if not typ.isNil: typeStr = typeToString(typ, preferExported) if not typ.isNil: typeStr = typeToString(typ, preferExported)
if typeStr.len < 1: return if typeStr.len < 1: return
for i in 0 .. <typePos: for i in 0 .. <typePos:
assert n[i].kind == nkIdent assert ((n[i].kind == nkIdent) or (n[i].kind == nkAccQuoted))
found.add(typeStr) found.add(typeStr)
else: else:
internalError(n.info, "renderParamTypes(found,n) with " & $n.kind) internalError(n.info, "renderParamTypes(found,n) with " & $n.kind)