* factored out getting a previously created internal type by name

git-svn-id: trunk@31247 -
This commit is contained in:
Jonas Maebe 2015-07-30 16:57:52 +00:00
parent ddeab221c0
commit 413680f593
2 changed files with 28 additions and 12 deletions

View File

@ -1328,25 +1328,19 @@ implementation
function ttai_typedconstbuilder.begin_anonymous_record(const optionalname: string; packrecords, recordalignmin, maxcrecordalign: shortint): trecorddef;
var
anonrecorddef: trecorddef;
srsym: tsym;
srsymtable: tsymtable;
found: boolean;
typesym: ttypesym;
begin
{ if the name is specified, we create a typesym with that name in order
to ensure we can find it again later with that name -> reuse here as
well if possible (and that also avoids duplicate type name issues) }
if optionalname<>'' then
begin
if optionalname[1]='$' then
found:=searchsym_in_module(current_module,copy(optionalname,2,length(optionalname)),srsym,srsymtable)
else
found:=searchsym_in_module(current_module,optionalname,srsym,srsymtable);
if found then
typesym:=try_search_current_module_type(optionalname);
if assigned(typesym) then
begin
if (srsym.typ<>typesym) or
(ttypesym(srsym).typedef.typ<>recorddef) then
internalerror(2014091207);
result:=trecorddef(ttypesym(srsym).typedef);
if typesym.typedef.typ<>recorddef then
internalerror(2015071401);
result:=trecorddef(typesym.typedef);
maybe_begin_aggregate(result);
exit;
end;

View File

@ -318,6 +318,7 @@ interface
function searchsym_in_helper(classh,contextclassh:tobjectdef;const s: TIDString;out srsym:tsym;out srsymtable:TSymtable;flags:tsymbol_search_flags):boolean;
function search_system_type(const s: TIDString): ttypesym;
function try_search_system_type(const s: TIDString): ttypesym;
function try_search_current_module_type(const s: TIDString): ttypesym;
function search_system_proc(const s: TIDString): tprocdef;
function search_named_unit_globaltype(const unitname, typename: TIDString; throwerror: boolean): ttypesym;
function search_struct_member(pd : tabstractrecorddef;const s : string):tsym;
@ -3599,6 +3600,27 @@ implementation
end;
function try_search_current_module_type(const s: TIDString): ttypesym;
var
found: boolean;
srsymtable: tsymtable;
srsym: tsym;
begin
if s[1]='$' then
found:=searchsym_in_module(current_module,copy(s,2,length(s)),srsym,srsymtable)
else
found:=searchsym_in_module(current_module,s,srsym,srsymtable);
if found then
begin
if (srsym.typ<>typesym) then
internalerror(2014091207);
result:=ttypesym(srsym);
end
else
result:=nil;
end;
function search_system_proc(const s: TIDString): tprocdef;
var
srsym: tsym;