summary refs log tree commit diff stats
path: root/nim/procfind.pas
diff options
context:
space:
mode:
Diffstat (limited to 'nim/procfind.pas')
-rwxr-xr-xnim/procfind.pas56
1 files changed, 56 insertions, 0 deletions
diff --git a/nim/procfind.pas b/nim/procfind.pas
new file mode 100755
index 000000000..f7a78c8b9
--- /dev/null
+++ b/nim/procfind.pas
@@ -0,0 +1,56 @@
+//
+//
+//           The Nimrod Compiler
+//        (c) Copyright 2008 Andreas Rumpf
+//
+//    See the file "copying.txt", included in this
+//    distribution, for details about the copyright.
+//
+
+// This module implements the searching for procs and iterators.
+// This is needed for proper handling of forward declarations.
+
+function equalGenericParams(procA, procB: PNode): Boolean;
+var
+  a, b: PSym;
+  i: int;
+begin
+  result := procA = procB;
+  if result then exit;
+  if (procA = nil) or (procB = nil) then exit;
+  
+  if sonsLen(procA) <> sonsLen(procB) then exit;
+  for i := 0 to sonsLen(procA)-1 do begin
+    assert(procA.sons[i].kind = nkSym);
+    assert(procB.sons[i].kind = nkSym);
+    a := procA.sons[i].sym;
+    b := procB.sons[i].sym;
+    if (a.name.id <> b.name.id) or not sameType(a.typ, b.typ) then exit;
+  end;
+  result := true
+end;
+
+function SearchForProc(c: PContext; fn: PSym; tos: int): PSym;
+// Searchs for the 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;
+begin
+  result := initIdentIter(it, c.tab.stack[tos], fn.Name);
+  while result <> nil do begin
+    if (result.Kind = fn.kind) then begin
+      if equalGenericParams(result.ast.sons[genericParamsPos], 
+                            fn.ast.sons[genericParamsPos]) then begin
+        case equalParams(result.typ.n, fn.typ.n) of
+          paramsEqual: exit;
+          paramsIncompatible: begin
+            liMessage(fn.info, errNotOverloadable, fn.name.s);
+            exit
+          end;
+          paramsNotEqual: begin end; // continue search
+        end;
+      end
+    end;
+    result := NextIdentIter(it, c.tab.stack[tos])
+  end
+end;