summary refs log tree commit diff stats
path: root/compiler/procfind.nim
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/procfind.nim')
-rw-r--r--compiler/procfind.nim54
1 files changed, 39 insertions, 15 deletions
diff --git a/compiler/procfind.nim b/compiler/procfind.nim
index aefccd140..0354d585d 100644
--- a/compiler/procfind.nim
+++ b/compiler/procfind.nim
@@ -17,52 +17,76 @@ proc equalGenericParams(procA, procB: PNode): bool =
   if sonsLen(procA) != sonsLen(procB): return
   for i in countup(0, sonsLen(procA) - 1):
     if procA.sons[i].kind != nkSym:
-      InternalError(procA.info, "equalGenericParams")
+      internalError(procA.info, "equalGenericParams")
       return
     if procB.sons[i].kind != nkSym:
-      InternalError(procB.info, "equalGenericParams")
+      internalError(procB.info, "equalGenericParams")
       return
     let a = procA.sons[i].sym
     let b = procB.sons[i].sym
     if a.name.id != b.name.id or
-        not sameTypeOrNil(a.typ, b.typ, {TypeDescExactMatch}): return
+        not sameTypeOrNil(a.typ, b.typ, {ExactTypeDescValues}): return
     if a.ast != nil and b.ast != nil:
-      if not ExprStructuralEquivalent(a.ast, b.ast): return
+      if not exprStructuralEquivalent(a.ast, b.ast): return
   result = true
 
-proc SearchForProc*(c: PContext, scope: PScope, fn: PSym): PSym =
+proc searchForProcOld*(c: PContext, scope: PScope, fn: PSym): PSym =
   # Searchs for a forward declaration or a "twin" symbol of fn
   # in the symbol table. If the parameter lists are exactly
   # the same the sym in the symbol table is returned, else nil.
   var it: TIdentIter
-  result = initIdentIter(it, scope.symbols, fn.Name)
+  result = initIdentIter(it, scope.symbols, fn.name)
   if isGenericRoutine(fn):
     # we simply check the AST; this is imprecise but nearly the best what
     # can be done; this doesn't work either though as type constraints are
     # not kept in the AST ..
     while result != nil:
-      if result.Kind == fn.kind and isGenericRoutine(result):
+      if result.kind == fn.kind and isGenericRoutine(result):
         let genR = result.ast.sons[genericParamsPos]
         let genF = fn.ast.sons[genericParamsPos]
-        if ExprStructuralEquivalent(genR, genF) and
-           ExprStructuralEquivalent(result.ast.sons[paramsPos],
+        if exprStructuralEquivalent(genR, genF) and
+           exprStructuralEquivalent(result.ast.sons[paramsPos],
                                     fn.ast.sons[paramsPos]) and
            equalGenericParams(genR, genF):
             return
-      result = NextIdentIter(it, scope.symbols)
+      result = nextIdentIter(it, scope.symbols)
   else:
     while result != nil:
-      if result.Kind == fn.kind and not isGenericRoutine(result):
+      if result.kind == fn.kind and not isGenericRoutine(result):
         case equalParams(result.typ.n, fn.typ.n)
         of paramsEqual:
           return
         of paramsIncompatible:
-          LocalError(fn.info, errNotOverloadable, fn.name.s)
+          localError(fn.info, errNotOverloadable, fn.name.s)
           return
         of paramsNotEqual:
-          nil
-      result = NextIdentIter(it, scope.symbols)
+          discard
+      result = nextIdentIter(it, scope.symbols)
 
+proc searchForProcNew(c: PContext, scope: PScope, fn: PSym): PSym =
+  const flags = {ExactGenericParams, ExactTypeDescValues,
+                 ExactConstraints, IgnoreCC}
+
+  var it: TIdentIter
+  result = initIdentIter(it, scope.symbols, fn.name)
+  while result != nil:
+    if result.kind in skProcKinds and
+       sameType(result.typ, fn.typ, flags): return
+
+    result = nextIdentIter(it, scope.symbols)
+  
+  return nil
+
+proc searchForProc*(c: PContext, scope: PScope, fn: PSym): PSym =
+  result = searchForProcNew(c, scope, fn)
+  when false:
+    let old = searchForProcOld(c, scope, fn)
+    if old != result:
+      echo "Mismatch in searchForProc: ", fn.info
+      debug fn.typ
+      debug if result != nil: result.typ else: nil
+      debug if old != nil: old.typ else: nil
+ 
 when false:
   proc paramsFitBorrow(child, parent: PNode): bool = 
     var length = sonsLen(child)
@@ -77,7 +101,7 @@ when false:
                           dcEqOrDistinctOf): return
       result = true
 
-  proc SearchForBorrowProc*(c: PContext, startScope: PScope, fn: PSym): PSym =
+  proc searchForBorrowProc*(c: PContext, startScope: PScope, fn: PSym): PSym =
     # Searchs for the fn in the symbol table. If the parameter lists are suitable
     # for borrowing the sym in the symbol table is returned, else nil.
     var it: TIdentIter