# # # The Nimrod Compiler # (c) Copyright 2012 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. # # This module implements lookup helpers. import intsets, ast, astalgo, idents, semdata, types, msgs, options, rodread, renderer, wordrecg, idgen proc ensureNoMissingOrUnusedSymbols(scope: PScope) proc considerAcc*(n: PNode): PIdent = case n.kind of nkIdent: result = n.ident of nkSym: result = n.sym.name of nkAccQuoted: case n.len of 0: globalError(n.info, errIdentifierExpected, renderTree(n)) of 1: result = considerAcc(n.sons[0]) else: var id = "" for i in 0.. n.ident else: result = nil of oimSelfModule: result = nextIdentIter(o.it, c.topLevelScope.symbols) of oimOtherModule: result = nextIdentIter(o.it, o.m.tab) of oimSymChoice: if o.symChoiceIndex < sonsLen(n): result = n.sons[o.symChoiceIndex].sym incl(o.inSymChoice, result.id) inc o.symChoiceIndex elif n.kind == nkOpenSymChoice: # try 'local' symbols too for Koenig's lookup: o.mode = oimSymChoiceLocalLookup o.scope = c.currentScope result = firstIdentExcluding(o.it, o.scope.symbols, n.sons[0].sym.name, o.inSymChoice) while result == nil: o.scope = o.scope.parent if o.scope == nil: break result = firstIdentExcluding(o.it, o.scope.symbols, n.sons[0].sym.name, o.inSymChoice) of oimSymChoiceLocalLookup: result = nextIdentExcluding(o.it, o.scope.symbols, o.inSymChoice) while result == nil: o.scope = o.scope.parent if o.scope == nil: break result = firstIdentExcluding(o.it, o.scope.symbols, n.sons[0].sym.name, o.inSymChoice) if result != nil and result.kind == skStub: loadStub(result) when false: proc qualifiedLookUpPreferImmediate*(c: PContext, n: PNode, flags = {checkUndeclared}): PSym = var o: TOverloadIter result = initOverloadIter(o, c, n) var a = result while a != nil: if sfImmediate in a.flags: return a a = nextOverloadIter(o, c, n) if result == nil and checkUndeclared in flags: localError(n.info, errUndeclaredIdentifier, n.considerAcc.s) result = errorSym(c, n)