From d36fe53d85ff6b7313b216034a285b962faf239b Mon Sep 17 00:00:00 2001 From: Jonas Maebe Date: Fri, 9 Dec 2016 13:39:35 +0000 Subject: [PATCH] * factored out the code to create an complete alias for a procdef to symcreat.create_procdef_alias() git-svn-id: trunk@35087 - --- compiler/ncgvmt.pas | 23 ++++++----------------- compiler/symcreat.pas | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/compiler/ncgvmt.pas b/compiler/ncgvmt.pas index 6625ab14e2..cd239fe9f0 100644 --- a/compiler/ncgvmt.pas +++ b/compiler/ncgvmt.pas @@ -1293,26 +1293,15 @@ implementation tmps:=make_mangledname('WRPR',_class.owner,_class.objname^+'_$_'+ ImplIntf.IntfDef.objname^+'_$_'+tostr(j)+'_$_'+pd.mangledname); {$ifdef cpuhighleveltarget} - { bare copy so we don't copy the aliasnames } - wrapperpd:=tprocdef(pd.getcopyas(procdef,pc_bareproc)); - { set the mangled name to the wrapper name } - wrapperpd.setmangledname(tmps); - { insert the wrapper procdef in the current unit's local - symbol table, but set the owning "struct" to the current - class (so self will have the correct type) } - finish_copied_procdef(wrapperpd,tmps,current_module.localsymtable,_class); - { now insert self/vmt } - insert_self_and_vmt_para(wrapperpd); - { and the function result } - insert_funcret_para(wrapperpd); - { recalculate the parameters now that we've added the above } - wrapperpd.calcparas; - { set the info required to generate the implementation } - wrapperpd.synthetickind:=tsk_interface_wrapper; new(wrapperinfo); wrapperinfo^.pd:=pd; wrapperinfo^.offset:=ImplIntf.ioffset; - wrapperpd.skpara:=wrapperinfo; + { insert the wrapper procdef in the current unit's local + symbol table, but set the owning "struct" to the current + class (so self will have the correct type) } + wrapperpd:=create_procdef_alias(pd,tmps,tmps, + current_module.localsymtable,_class, + tsk_interface_wrapper,wrapperinfo); {$else cpuhighleveltarget} { create wrapper code } new_section(list,sec_code,tmps,target_info.alignment.procalign); diff --git a/compiler/symcreat.pas b/compiler/symcreat.pas index c7590ac483..ef18434a99 100644 --- a/compiler/symcreat.pas +++ b/compiler/symcreat.pas @@ -84,6 +84,14 @@ interface added earlier } procedure add_synthetic_method_implementations(st: tsymtable); + { create an alias for a procdef with Pascal name "newrealname", + mangledname "newmangledname", in symtable newparentst, part of the + record/class/.. "newstruct" (nil if none), and with synthetickind "sk" and + synthetic kind para "skpara" to create the implementation (tsk_none and nil + in case not necessary). Returns the new procdef; finish_copied_procdef() is + not required/must not be called for the result. } + function create_procdef_alias(pd: tprocdef; const newrealname: string; const newmangledname: TSymStr; newparentst: tsymtable; newstruct: tabstractrecorddef; sk: tsynthetickind; skpara: pointer): tprocdef; + { finalize a procdef that has been copied with tprocdef.getcopyas(procdef,pc_bareproc) } procedure finish_copied_procdef(var pd: tprocdef; const realname: string; newparentst: tsymtable; newstruct: tabstractrecorddef); @@ -1116,6 +1124,27 @@ implementation end; + function create_procdef_alias(pd: tprocdef; const newrealname: string; const newmangledname: TSymStr; newparentst: tsymtable; newstruct: tabstractrecorddef; + sk: tsynthetickind; skpara: pointer): tprocdef; + begin + { bare copy so we don't copy the aliasnames } + result:=tprocdef(pd.getcopyas(procdef,pc_bareproc)); + { set the mangled name to the wrapper name } + result.setmangledname(newmangledname); + { finish creating the copy } + finish_copied_procdef(result,newrealname,newparentst,newstruct); + { now insert self/vmt } + insert_self_and_vmt_para(result); + { and the function result } + insert_funcret_para(result); + { recalculate the parameters now that we've added the missing ones } + result.calcparas; + { set the info required to generate the implementation } + result.synthetickind:=sk; + result.skpara:=skpara; + end; + + procedure finish_copied_procdef(var pd: tprocdef; const realname: string; newparentst: tsymtable; newstruct: tabstractrecorddef); var sym: tsym;