compiler: prepare collect_overloads_in_struct to work with operators, replace tprocsym argument in proc_add to tsymtable because tprocsym is only used to get the symtable

git-svn-id: trunk@16623 -
This commit is contained in:
paul 2010-12-24 03:17:43 +00:00
parent d97cf8ed9d
commit 525f4fea43

View File

@ -66,10 +66,10 @@ interface
FParaNode : tnode; FParaNode : tnode;
FParaLength : smallint; FParaLength : smallint;
FAllowVariant : boolean; FAllowVariant : boolean;
procedure collect_overloads_in_struct(ProcdefOverloadList:TFPObjectList); procedure collect_overloads_in_struct(structdef:tabstractrecorddef;ProcdefOverloadList:TFPObjectList);
procedure collect_overloads_in_units(ProcdefOverloadList:TFPObjectList; objcidcall,explicitunit: boolean); procedure collect_overloads_in_units(ProcdefOverloadList:TFPObjectList; objcidcall,explicitunit: boolean);
procedure create_candidate_list(ignorevisibility,allowdefaultparas,objcidcall,explicitunit:boolean); procedure create_candidate_list(ignorevisibility,allowdefaultparas,objcidcall,explicitunit:boolean);
function proc_add(ps:tprocsym;pd:tprocdef;objcidcall: boolean):pcandidate; function proc_add(st:tsymtable;pd:tprocdef;objcidcall: boolean):pcandidate;
public public
constructor create(sym:tprocsym;st:TSymtable;ppn:tnode;ignorevisibility,allowdefaultparas,objcidcall,explicitunit:boolean); constructor create(sym:tprocsym;st:TSymtable;ppn:tnode;ignorevisibility,allowdefaultparas,objcidcall,explicitunit:boolean);
constructor create_operator(op:ttoken;ppn:tnode); constructor create_operator(op:ttoken;ppn:tnode);
@ -1742,17 +1742,18 @@ implementation
end; end;
procedure tcallcandidates.collect_overloads_in_struct(ProcdefOverloadList:TFPObjectList); procedure tcallcandidates.collect_overloads_in_struct(structdef:tabstractrecorddef;ProcdefOverloadList:TFPObjectList);
var var
j : integer; j : integer;
pd : tprocdef; pd : tprocdef;
srsym : tsym; srsym : tsym;
structdef : tabstractrecorddef;
hashedid : THashedIDString; hashedid : THashedIDString;
hasoverload : boolean; hasoverload : boolean;
begin begin
structdef:=tabstractrecorddef(fprocsym.owner.defowner); if FOperator=NOTOKEN then
hashedid.id:=fprocsym.name; hashedid.id:=FProcsym.name
else
hashedid.id:=overloaded_names[FOperator];
hasoverload:=false; hasoverload:=false;
while assigned(structdef) do while assigned(structdef) do
begin begin
@ -1761,6 +1762,9 @@ implementation
{ Delphi allows hiding a property by a procedure with the same name } { Delphi allows hiding a property by a procedure with the same name }
(srsym.typ=procsym) then (srsym.typ=procsym) then
begin begin
{ Store first procsym found }
if not assigned(FProcsym) then
FProcsym:=tprocsym(srsym);
{ add all definitions } { add all definitions }
hasoverload:=false; hasoverload:=false;
for j:=0 to tprocsym(srsym).ProcdefList.Count-1 do for j:=0 to tprocsym(srsym).ProcdefList.Count-1 do
@ -1861,6 +1865,7 @@ implementation
hp : pcandidate; hp : pcandidate;
pt : tcallparanode; pt : tcallparanode;
found : boolean; found : boolean;
st : TSymtable;
contextstructdef : tabstractrecorddef; contextstructdef : tabstractrecorddef;
ProcdefOverloadList : TFPObjectList; ProcdefOverloadList : TFPObjectList;
begin begin
@ -1871,7 +1876,7 @@ implementation
if not objcidcall and if not objcidcall and
(FOperator=NOTOKEN) and (FOperator=NOTOKEN) and
(FProcsym.owner.symtabletype in [objectsymtable,recordsymtable]) then (FProcsym.owner.symtabletype in [objectsymtable,recordsymtable]) then
collect_overloads_in_struct(ProcdefOverloadList) collect_overloads_in_struct(tabstractrecorddef(FProcsym.owner.defowner),ProcdefOverloadList)
else else
collect_overloads_in_units(ProcdefOverloadList,objcidcall,explicitunit); collect_overloads_in_units(ProcdefOverloadList,objcidcall,explicitunit);
@ -1905,6 +1910,11 @@ implementation
else else
contextstructdef:=current_structdef; contextstructdef:=current_structdef;
{ symtable is needed later to calculate the distance }
if assigned(FProcsym) then
st:=FProcsym.Owner
else
st:=nil;
{ Process all found overloads } { Process all found overloads }
for j:=0 to ProcdefOverloadList.Count-1 do for j:=0 to ProcdefOverloadList.Count-1 do
begin begin
@ -1947,7 +1957,7 @@ implementation
hp:=hp^.next; hp:=hp^.next;
end; end;
if not found then if not found then
proc_add(fprocsym,pd,objcidcall); proc_add(st,pd,objcidcall);
end; end;
end; end;
@ -1955,10 +1965,9 @@ implementation
end; end;
function tcallcandidates.proc_add(ps:tprocsym;pd:tprocdef;objcidcall: boolean):pcandidate; function tcallcandidates.proc_add(st:tsymtable;pd:tprocdef;objcidcall: boolean):pcandidate;
var var
defaultparacnt : integer; defaultparacnt : integer;
parentst : tsymtable;
begin begin
{ generate new candidate entry } { generate new candidate entry }
new(result); new(result);
@ -1985,15 +1994,14 @@ implementation
end; end;
{ Give a small penalty for overloaded methods not in { Give a small penalty for overloaded methods not in
defined the current class/unit } defined the current class/unit }
parentst:=ps.owner;
{ when calling Objective-C methods via id.method, then the found { when calling Objective-C methods via id.method, then the found
procsym will be inside an arbitrary ObjectSymtable, and we don't procsym will be inside an arbitrary ObjectSymtable, and we don't
want togive the methods of that particular objcclass precedence over want togive the methods of that particular objcclass precedence over
other methods, so instead check against the symtable in which this other methods, so instead check against the symtable in which this
objcclass is defined } objcclass is defined }
if objcidcall then if objcidcall then
parentst:=parentst.defowner.owner; st:=st.defowner.owner;
if (parentst<>pd.owner) then if (st<>pd.owner) then
result^.ordinal_distance:=result^.ordinal_distance+1.0; result^.ordinal_distance:=result^.ordinal_distance+1.0;
end; end;