1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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;
|