From 7de854ef1ec86310c67192a734cd1114ef03ad26 Mon Sep 17 00:00:00 2001 From: Sven/Sarah Barth Date: Mon, 17 Jan 2022 22:41:06 +0100 Subject: [PATCH] + add method register_implemented_interface to tobjectdef which registers an implemented interface and - if desired - also initializes the GUID related fields of the objectdef * use that method in all locations outside symdef that add add an implemented interface Based on work by Blaise.ru --- compiler/jvm/pjvm.pas | 2 +- compiler/pdecobj.pas | 12 ++---------- compiler/pgenutil.pas | 3 +-- compiler/symdef.pas | 12 ++++++++++++ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/compiler/jvm/pjvm.pas b/compiler/jvm/pjvm.pas index ada345ea48..c24778e01e 100644 --- a/compiler/jvm/pjvm.pas +++ b/compiler/jvm/pjvm.pas @@ -170,7 +170,7 @@ implementation include(enumclass.objectoptions,oo_is_enum_class); include(enumclass.objectoptions,oo_is_sealed); { implement FpcEnumValueObtainable interface } - enumclass.ImplementedInterfaces.add(TImplementedInterface.Create(tobjectdef(search_system_type('FPCENUMVALUEOBTAINABLE').typedef))); + enumclass.register_implemented_interface(tobjectdef(search_system_type('FPCENUMVALUEOBTAINABLE').typedef),false); { create an alias for this type inside itself: this way we can choose a name that can be used in generated Pascal code without risking an identifier conflict (since it is local to this class; the global name diff --git a/compiler/pdecobj.pas b/compiler/pdecobj.pas index 62d275501a..fe95240eec 100644 --- a/compiler/pdecobj.pas +++ b/compiler/pdecobj.pas @@ -342,13 +342,7 @@ implementation if find_implemented_interface(current_objectdef,intfdef)<>nil then Message1(sym_e_duplicate_id,intfdef.objname^) else - begin - { allocate and prepare the GUID only if the class - implements some interfaces. } - if current_objectdef.ImplementedInterfaces.count = 0 then - current_objectdef.prepareguid; - current_objectdef.ImplementedInterfaces.Add(TImplementedInterface.Create(intfdef)); - end; + current_objectdef.register_implemented_interface(intfdef,true); end; @@ -382,9 +376,7 @@ implementation if find_implemented_interface(current_objectdef,intfdef)<>nil then Message1(sym_e_duplicate_id,intfdef.objname^) else - begin - current_objectdef.ImplementedInterfaces.Add(TImplementedInterface.Create(intfdef)); - end; + current_objectdef.register_implemented_interface(intfdef,false); end; diff --git a/compiler/pgenutil.pas b/compiler/pgenutil.pas index f618ffad9d..afb14759d2 100644 --- a/compiler/pgenutil.pas +++ b/compiler/pgenutil.pas @@ -2303,8 +2303,7 @@ uses internalerror(2012101101); basedef:=cobjectdef.create(tobjectdef(basedef).objecttype,defname,tobjectdef(basedef),false); for i:=0 to constraintdata.interfaces.count-1 do - tobjectdef(basedef).implementedinterfaces.add( - timplementedinterface.create(tobjectdef(constraintdata.interfaces[i]))); + tobjectdef(basedef).register_implemented_interface(tobjectdef(constraintdata.interfaces[i]),false); end else if constraintdata.interfaces.count=1 then diff --git a/compiler/symdef.pas b/compiler/symdef.pas index 8b94f0a3da..ae9349dbfc 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -535,6 +535,7 @@ interface procedure set_parent(c : tobjectdef); function find_destructor: tprocdef; function implements_any_interfaces: boolean; + function register_implemented_interface(intfdef:tobjectdef;useguid:boolean):timplementedinterface; { dispinterface support } function get_next_dispid: longint; { enumerator support } @@ -8115,6 +8116,17 @@ implementation (assigned(childof) and childof.implements_any_interfaces); end; + + function tobjectdef.register_implemented_interface(intfdef:tobjectdef;useguid:boolean):timplementedinterface; + begin + { allocate the GUID only if the class implements at least one interface } + if useguid then + prepareguid; + result:=timplementedinterface.create(intfdef); + ImplementedInterfaces.Add(result); + end; + + function tobjectdef.size : asizeint; begin if objecttype in [odt_class,odt_interfacecom,odt_interfacecorba,odt_dispinterface,odt_objcclass,odt_objcprotocol,odt_helper,odt_javaclass,odt_interfacejava] then