* extract checking whether two parameter defs of two procdefs are equal into a separate function

git-svn-id: trunk@45972 -
This commit is contained in:
svenbarth 2020-07-31 15:55:31 +00:00
parent 42f2e5f8ad
commit fa0c9adbf4

View File

@ -29,7 +29,7 @@ interface
cclasses,
globtype,globals,
node,
symconst,symtype,symdef;
symconst,symtype,symdef,symbase;
type
{ if acp is cp_all the var const or nothing are considered equal }
@ -167,6 +167,11 @@ interface
{ - objectdef: if it inherits from otherdef or they are equal }
function def_is_related(curdef,otherdef:tdef):boolean;
{ Checks whether two defs for parameters or result types of a generic }
{ routine can be considered as equal. Requires the symtables of the }
{ procdefs the parameters defs shall belong to. }
function equal_genfunc_paradefs(fwdef,currdef:tdef;fwpdst,currpdst:tsymtable):boolean;
implementation
@ -2097,23 +2102,6 @@ implementation
var
currpara1,
currpara2 : tparavarsym;
function equal_genfunc_paradefs(def1,def2:tdef):boolean;
begin
result:=false;
if (sp_generic_para in def1.typesym.symoptions) and
(sp_generic_para in def2.typesym.symoptions) and
(def1.owner=currpara1.owner) and
(def2.owner=currpara2.owner) then
begin
{ the forward declaration may have constraints }
if not (df_genconstraint in def2.defoptions) and (def2.typ=undefineddef) and
((def1.typ=undefineddef) or (df_genconstraint in def1.defoptions)) then
result:=true;
end
end;
var
eq,lowesteq : tequaltype;
hpd : tprocdef;
convtype : tconverttype;
@ -2254,7 +2242,7 @@ implementation
end
else if (cpo_generic in cpoptions) then
begin
if equal_genfunc_paradefs(currpara1.vardef,currpara2.vardef) then
if equal_genfunc_paradefs(currpara1.vardef,currpara2.vardef,currpara1.owner,currpara2.owner) then
eq:=te_exact
else
exit;
@ -2268,7 +2256,7 @@ implementation
if is_open_array(currpara1.vardef) and
is_open_array(currpara2.vardef) then
begin
if equal_genfunc_paradefs(tarraydef(currpara1.vardef).elementdef,tarraydef(currpara2.vardef).elementdef) then
if equal_genfunc_paradefs(tarraydef(currpara1.vardef).elementdef,tarraydef(currpara2.vardef).elementdef,currpara1.owner,currpara2.owner) then
eq:=te_exact;
end
else
@ -2611,4 +2599,20 @@ implementation
end;
end;
function equal_genfunc_paradefs(fwdef,currdef:tdef;fwpdst,currpdst:tsymtable): boolean;
begin
result:=false;
if (sp_generic_para in fwdef.typesym.symoptions) and
(sp_generic_para in currdef.typesym.symoptions) and
(fwdef.owner=fwpdst) and
(currdef.owner=currpdst) then
begin
{ the forward declaration may have constraints }
if not (df_genconstraint in currdef.defoptions) and (currdef.typ=undefineddef) and
((fwdef.typ=undefineddef) or (df_genconstraint in fwdef.defoptions)) then
result:=true;
end
end;
end.