* move determine_generic_def out from pdecl.types_dec to pgenutil

This commit is contained in:
Sven/Sarah Barth 2022-02-18 16:17:14 +01:00
parent ab013b6b69
commit 7f1e420bb0
2 changed files with 49 additions and 46 deletions

View File

@ -613,52 +613,6 @@ implementation
procedure types_dec(in_structure: boolean;out had_generic:boolean;var rtti_attrs_def: trtti_attribute_list);
function determine_generic_def(const name:tidstring):tstoreddef;
var
hashedid : THashedIDString;
pd : tprocdef;
sym : tsym;
begin
result:=nil;
{ check whether this is a declaration of a type inside a
specialization }
if assigned(current_structdef) and
(df_specialization in current_structdef.defoptions) then
begin
if not assigned(current_structdef.genericdef) or
not (current_structdef.genericdef.typ in [recorddef,objectdef]) then
internalerror(2011052301);
hashedid.id:=name;
{ we could be inside a method of the specialization
instead of its declaration, so check that first (as
local nested types aren't allowed we don't need to
walk the symtablestack to find the localsymtable) }
if symtablestack.top.symtabletype=localsymtable then
begin
{ we are in a method }
if not assigned(symtablestack.top.defowner) or
(symtablestack.top.defowner.typ<>procdef) then
internalerror(2011120701);
pd:=tprocdef(symtablestack.top.defowner);
if not assigned(pd.genericdef) or (pd.genericdef.typ<>procdef) then
internalerror(2011120702);
sym:=tsym(tprocdef(pd.genericdef).localst.findwithhash(hashedid));
end
else
sym:=nil;
if not assigned(sym) or not (sym.typ=typesym) then
begin
{ now search in the declaration of the generic }
sym:=tsym(tabstractrecorddef(current_structdef.genericdef).symtable.findwithhash(hashedid));
if not assigned(sym) or not (sym.typ=typesym) then
internalerror(2011052302);
end;
{ use the corresponding type in the generic's symtable as
genericdef for the specialized type }
result:=tstoreddef(ttypesym(sym).typedef);
end;
end;
procedure finalize_class_external_status(od: tobjectdef);
begin
if [oo_is_external,oo_is_forward] <= od.objectoptions then

View File

@ -55,6 +55,7 @@ uses
procedure generate_specialization_procs;
procedure maybe_add_pending_specialization(def:tdef);
function determine_generic_def(const name:tidstring):tstoreddef;
procedure specialization_init(genericdef:tdef;var state:tspecializationstate);
procedure specialization_done(var state:tspecializationstate);
@ -2069,4 +2070,52 @@ uses
current_module.pendingspecializations.add(def.typename,def);
end;
function determine_generic_def(const name:tidstring):tstoreddef;
var
hashedid : THashedIDString;
pd : tprocdef;
sym : tsym;
begin
result:=nil;
{ check whether this is a declaration of a type inside a
specialization }
if assigned(current_structdef) and
(df_specialization in current_structdef.defoptions) then
begin
if not assigned(current_structdef.genericdef) or
not (current_structdef.genericdef.typ in [recorddef,objectdef]) then
internalerror(2011052301);
hashedid.id:=name;
{ we could be inside a method of the specialization
instead of its declaration, so check that first (as
local nested types aren't allowed we don't need to
walk the symtablestack to find the localsymtable) }
if symtablestack.top.symtabletype=localsymtable then
begin
{ we are in a method }
if not assigned(symtablestack.top.defowner) or
(symtablestack.top.defowner.typ<>procdef) then
internalerror(2011120701);
pd:=tprocdef(symtablestack.top.defowner);
if not assigned(pd.genericdef) or (pd.genericdef.typ<>procdef) then
internalerror(2011120702);
sym:=tsym(tprocdef(pd.genericdef).localst.findwithhash(hashedid));
end
else
sym:=nil;
if not assigned(sym) or not (sym.typ=typesym) then
begin
{ now search in the declaration of the generic }
sym:=tsym(tabstractrecorddef(current_structdef.genericdef).symtable.findwithhash(hashedid));
if not assigned(sym) or not (sym.typ=typesym) then
internalerror(2011052302);
end;
{ use the corresponding type in the generic's symtable as
genericdef for the specialized type }
result:=tstoreddef(ttypesym(sym).typedef);
end;
end;
end.