summary refs log tree commit diff stats
path: root/compiler/lookups.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/lookups.nim')
-rw-r--r--compiler/lookups.nim123
1 files changed, 69 insertions, 54 deletions
diff --git a/compiler/lookups.nim b/compiler/lookups.nim
index e1ec9e14b..c31eb3121 100644
--- a/compiler/lookups.nim
+++ b/compiler/lookups.nim
@@ -21,7 +21,7 @@ proc considerAcc*(n: PNode): PIdent =
   of nkSym: result = n.sym.name
   of nkAccQuoted:
     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])
     else:
       var id = ""
@@ -30,16 +30,16 @@ proc considerAcc*(n: PNode): PIdent =
         case x.kind
         of nkIdent: id.add(x.ident.s)
         of nkSym: id.add(x.sym.name.s)
-        else: GlobalError(n.info, errIdentifierExpected, renderTree(n))
+        else: globalError(n.info, errIdentifierExpected, renderTree(n))
       result = getIdent(id)
   else:
-    GlobalError(n.info, errIdentifierExpected, renderTree(n))
+    globalError(n.info, errIdentifierExpected, renderTree(n))
  
 template addSym*(scope: PScope, s: PSym) =
-  StrTableAdd(scope.symbols, s)
+  strTableAdd(scope.symbols, s)
 
 proc addUniqueSym*(scope: PScope, s: PSym): TResult =
-  if StrTableIncl(scope.symbols, s):
+  if strTableIncl(scope.symbols, s):
     result = Failure
   else:
     result = Success
@@ -64,17 +64,17 @@ iterator walkScopes*(scope: PScope): PScope =
     current = current.parent
 
 proc localSearchInScope*(c: PContext, s: PIdent): PSym =
-  result = StrTableGet(c.currentScope.symbols, s)
+  result = strTableGet(c.currentScope.symbols, s)
 
 proc searchInScopes*(c: PContext, s: PIdent): PSym =
   for scope in walkScopes(c.currentScope):
-    result = StrTableGet(scope.symbols, s)
+    result = strTableGet(scope.symbols, s)
     if result != nil: return
   result = nil
 
 proc searchInScopes*(c: PContext, s: PIdent, filter: TSymKinds): PSym =
   for scope in walkScopes(c.currentScope):
-    result = StrTableGet(scope.symbols, s)
+    result = strTableGet(scope.symbols, s)
     if result != nil and result.kind in filter: return
   result = nil
 
@@ -114,65 +114,65 @@ proc getSymRepr*(s: PSym): string =
 proc ensureNoMissingOrUnusedSymbols(scope: PScope) =
   # check if all symbols have been used and defined:
   var it: TTabIter
-  var s = InitTabIter(it, scope.symbols)
+  var s = initTabIter(it, scope.symbols)
   var missingImpls = 0
   while s != nil:
     if sfForward in s.flags:
       # too many 'implementation of X' errors are annoying
       # and slow 'suggest' down:
       if missingImpls == 0:
-        LocalError(s.info, errImplOfXexpected, getSymRepr(s))
+        localError(s.info, errImplOfXexpected, getSymRepr(s))
       inc missingImpls
     elif {sfUsed, sfExported} * s.flags == {} and optHints in s.options: 
       # BUGFIX: check options in s!
       if s.kind notin {skForVar, skParam, skMethod, skUnknown, skGenericParam}:
-        Message(s.info, hintXDeclaredButNotUsed, getSymRepr(s))
-    s = NextIter(it, scope.symbols)
+        message(s.info, hintXDeclaredButNotUsed, getSymRepr(s))
+    s = nextIter(it, scope.symbols)
   
-proc WrongRedefinition*(info: TLineInfo, s: string) =
+proc wrongRedefinition*(info: TLineInfo, s: string) =
   if gCmd != cmdInteractive:
     localError(info, errAttemptToRedefine, s)
   
 proc addDecl*(c: PContext, sym: PSym) =
   if c.currentScope.addUniqueSym(sym) == Failure:
-    WrongRedefinition(sym.info, sym.Name.s)
+    wrongRedefinition(sym.info, sym.name.s)
 
 proc addPrelimDecl*(c: PContext, sym: PSym) =
   discard c.currentScope.addUniqueSym(sym)
 
 proc addDeclAt*(scope: PScope, sym: PSym) =
   if scope.addUniqueSym(sym) == Failure:
-    WrongRedefinition(sym.info, sym.Name.s)
+    wrongRedefinition(sym.info, sym.name.s)
 
-proc AddInterfaceDeclAux(c: PContext, sym: PSym) = 
+proc addInterfaceDeclAux(c: PContext, sym: PSym) = 
   if sfExported in sym.flags:
     # add to interface:
-    if c.module != nil: StrTableAdd(c.module.tab, sym)
-    else: InternalError(sym.info, "AddInterfaceDeclAux")
+    if c.module != nil: strTableAdd(c.module.tab, sym)
+    else: internalError(sym.info, "AddInterfaceDeclAux")
 
 proc addInterfaceDeclAt*(c: PContext, scope: PScope, sym: PSym) =
   addDeclAt(scope, sym)
-  AddInterfaceDeclAux(c, sym)
+  addInterfaceDeclAux(c, sym)
 
 proc addOverloadableSymAt*(scope: PScope, fn: PSym) =
   if fn.kind notin OverloadableSyms: 
-    InternalError(fn.info, "addOverloadableSymAt")
+    internalError(fn.info, "addOverloadableSymAt")
     return
-  var check = StrTableGet(scope.symbols, fn.name)
-  if check != nil and check.Kind notin OverloadableSyms: 
-    WrongRedefinition(fn.info, fn.Name.s)
+  var check = strTableGet(scope.symbols, fn.name)
+  if check != nil and check.kind notin OverloadableSyms: 
+    wrongRedefinition(fn.info, fn.name.s)
   else:
     scope.addSym(fn)
   
 proc addInterfaceDecl*(c: PContext, sym: PSym) = 
   # it adds the symbol to the interface if appropriate
   addDecl(c, sym)
-  AddInterfaceDeclAux(c, sym)
+  addInterfaceDeclAux(c, sym)
 
 proc addInterfaceOverloadableSymAt*(c: PContext, scope: PScope, sym: PSym) =
   # it adds the symbol to the interface if appropriate
   addOverloadableSymAt(scope, sym)
-  AddInterfaceDeclAux(c, sym)
+  addInterfaceDeclAux(c, sym)
 
 proc lookUp*(c: PContext, n: PNode): PSym = 
   # Looks up a symbol. Generates an error in case of nil.
@@ -180,7 +180,7 @@ proc lookUp*(c: PContext, n: PNode): PSym =
   of nkIdent:
     result = searchInScopes(c, n.ident)
     if result == nil: 
-      LocalError(n.info, errUndeclaredIdentifier, n.ident.s)
+      localError(n.info, errUndeclaredIdentifier, n.ident.s)
       result = errorSym(c, n)
   of nkSym:
     result = n.sym
@@ -188,34 +188,34 @@ proc lookUp*(c: PContext, n: PNode): PSym =
     var ident = considerAcc(n)
     result = searchInScopes(c, ident)
     if result == nil:
-      LocalError(n.info, errUndeclaredIdentifier, ident.s)
+      localError(n.info, errUndeclaredIdentifier, ident.s)
       result = errorSym(c, n)
   else:
-    InternalError(n.info, "lookUp")
+    internalError(n.info, "lookUp")
     return
-  if Contains(c.AmbiguousSymbols, result.id): 
-    LocalError(n.info, errUseQualifier, result.name.s)
+  if contains(c.ambiguousSymbols, result.id): 
+    localError(n.info, errUseQualifier, result.name.s)
   if result.kind == skStub: loadStub(result)
   
 type 
   TLookupFlag* = enum 
     checkAmbiguity, checkUndeclared
 
-proc QualifiedLookUp*(c: PContext, n: PNode, flags = {checkUndeclared}): PSym = 
+proc qualifiedLookUp*(c: PContext, n: PNode, flags = {checkUndeclared}): PSym = 
   case n.kind
   of nkIdent, nkAccQuoted:
     var ident = considerAcc(n)
     result = searchInScopes(c, ident)
     if result == nil and checkUndeclared in flags: 
-      LocalError(n.info, errUndeclaredIdentifier, ident.s)
+      localError(n.info, errUndeclaredIdentifier, ident.s)
       result = errorSym(c, n)
     elif checkAmbiguity in flags and result != nil and 
-        Contains(c.AmbiguousSymbols, result.id): 
-      LocalError(n.info, errUseQualifier, ident.s)
+        contains(c.ambiguousSymbols, result.id): 
+      localError(n.info, errUseQualifier, ident.s)
   of nkSym:
     result = n.sym
-    if checkAmbiguity in flags and Contains(c.AmbiguousSymbols, result.id): 
-      LocalError(n.info, errUseQualifier, n.sym.name.s)
+    if checkAmbiguity in flags and contains(c.ambiguousSymbols, result.id): 
+      localError(n.info, errUseQualifier, n.sym.name.s)
   of nkDotExpr: 
     result = nil
     var m = qualifiedLookUp(c, n.sons[0], flags*{checkUndeclared})
@@ -227,28 +227,31 @@ proc QualifiedLookUp*(c: PContext, n: PNode, flags = {checkUndeclared}): PSym =
         ident = considerAcc(n.sons[1])
       if ident != nil: 
         if m == c.module: 
-          result = StrTableGet(c.topLevelScope.symbols, ident)
+          result = strTableGet(c.topLevelScope.symbols, ident)
         else: 
-          result = StrTableGet(m.tab, ident)
+          result = strTableGet(m.tab, ident)
         if result == nil and checkUndeclared in flags: 
-          LocalError(n.sons[1].info, errUndeclaredIdentifier, ident.s)
+          localError(n.sons[1].info, errUndeclaredIdentifier, ident.s)
           result = errorSym(c, n.sons[1])
-      elif checkUndeclared in flags:
-        LocalError(n.sons[1].info, errIdentifierExpected, 
+      elif n.sons[1].kind == nkSym:
+        result = n.sons[1].sym
+      elif checkUndeclared in flags and
+           n.sons[1].kind notin {nkOpenSymChoice, nkClosedSymChoice}:
+        localError(n.sons[1].info, errIdentifierExpected,
                    renderTree(n.sons[1]))
         result = errorSym(c, n.sons[1])
   else:
     result = nil
   if result != nil and result.kind == skStub: loadStub(result)
   
-proc InitOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
+proc initOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
   case n.kind
   of nkIdent, nkAccQuoted:
     var ident = considerAcc(n)
     o.scope = c.currentScope
     o.mode = oimNoQualifier
     while true:
-      result = InitIdentIter(o.it, o.scope.symbols, ident)
+      result = initIdentIter(o.it, o.scope.symbols, ident)
       if result != nil:
         break
       else:
@@ -269,12 +272,12 @@ proc InitOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
       if ident != nil: 
         if o.m == c.module: 
           # a module may access its private members:
-          result = InitIdentIter(o.it, c.topLevelScope.symbols, ident)
+          result = initIdentIter(o.it, c.topLevelScope.symbols, ident)
           o.mode = oimSelfModule
         else: 
-          result = InitIdentIter(o.it, o.m.tab, ident)
+          result = initIdentIter(o.it, o.m.tab, ident)
       else: 
-        LocalError(n.sons[1].info, errIdentifierExpected, 
+        localError(n.sons[1].info, errIdentifierExpected, 
                    renderTree(n.sons[1]))
         result = errorSym(c, n.sons[1])
   of nkClosedSymChoice, nkOpenSymChoice:
@@ -282,8 +285,8 @@ proc InitOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
     result = n.sons[0].sym
     o.symChoiceIndex = 1
     o.inSymChoice = initIntSet()
-    Incl(o.inSymChoice, result.id)
-  else: nil
+    incl(o.inSymChoice, result.id)
+  else: discard
   if result != nil and result.kind == skStub: loadStub(result)
 
 proc lastOverloadScope*(o: TOverloadIter): int =
@@ -303,7 +306,7 @@ proc nextOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
       while result == nil:
         o.scope = o.scope.parent
         if o.scope == nil: break
-        result = InitIdentIter(o.it, o.scope.symbols, o.it.name)
+        result = initIdentIter(o.it, o.scope.symbols, o.it.name)
         # BUGFIX: o.it.name <-> n.ident
     else: 
       result = nil
@@ -314,26 +317,38 @@ proc nextOverloadIter*(o: var TOverloadIter, c: PContext, n: PNode): PSym =
   of oimSymChoice: 
     if o.symChoiceIndex < sonsLen(n):
       result = n.sons[o.symChoiceIndex].sym
-      Incl(o.inSymChoice, result.id)
+      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,
+      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,
+        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,
+      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)