diff --git a/compiler/pdecvar.pas b/compiler/pdecvar.pas index 5b06c1f712..41c4a0b0f9 100644 --- a/compiler/pdecvar.pas +++ b/compiler/pdecvar.pas @@ -576,6 +576,14 @@ implementation if (ppo_hasparameters in p.propoptions) or ((sp_static in p.symoptions) <> (sp_static in sym.symoptions)) then Message(parser_e_ill_property_access_sym); +{$ifdef jvm} + { if the visibility of the field is lower than the + visibility of the property, wrap it in a getter + so that we can access it from all contexts in + which the property is visibile } + if (tfieldvarsym(sym).visibility (sp_static in sym.symoptions)) then Message(parser_e_ill_property_access_sym); +{$ifdef jvm} + { if the visibility of the field is lower than the + visibility of the property, wrap it in a getter + so that we can access it from all contexts in + which the property is visibile } + if (tfieldvarsym(sym).visibility static class method } + if sp_static in p.symoptions then + pd.procoptions:=pd.procoptions+[po_classmethod,po_staticmethod]; + { calling convention, self, ... } + handle_calling_convention(pd); + { register forward declaration with procsym } + proc_add_definition(pd); + + { make the property call this new function } + p.propaccesslist[accesstyp].addsym(sl_call,ps); + p.propaccesslist[accesstyp].procdef:=pd; + + symtablestack.pop(obj.symtable); + end; + + + procedure jvm_create_getter_for_property(p: tpropertysym); + begin + jvm_create_getter_or_setter_for_property(p,true); + end; + + + procedure jvm_create_setter_for_property(p: tpropertysym); + begin + jvm_create_getter_or_setter_for_property(p,false); + end; + end. diff --git a/compiler/symcreat.pas b/compiler/symcreat.pas index ea0b1495f3..4f6dcedfb2 100644 --- a/compiler/symcreat.pas +++ b/compiler/symcreat.pas @@ -783,6 +783,27 @@ implementation end; {$endif jvm} + procedure implement_field_getter(pd: tprocdef); + var + str: ansistring; + callthroughprop: tpropertysym; + begin + callthroughprop:=tpropertysym(pd.skpara); + str:='begin result:='+callthroughprop.realname+'; end;'; + str_parse_method_impl(str,pd,po_classmethod in pd.procoptions) + end; + + + procedure implement_field_setter(pd: tprocdef); + var + str: ansistring; + callthroughprop: tpropertysym; + begin + callthroughprop:=tpropertysym(pd.skpara); + str:='begin '+callthroughprop.realname+':=__fpc_newval__; end;'; + str_parse_method_impl(str,pd,po_classmethod in pd.procoptions) + end; + procedure add_synthetic_method_implementations_for_struct(struct: tabstractrecorddef); var @@ -837,6 +858,10 @@ implementation tsk_jvm_virtual_clmethod: implement_jvm_virtual_clmethod(pd); {$endif jvm} + tsk_field_getter: + implement_field_getter(pd); + tsk_field_setter: + implement_field_setter(pd); else internalerror(2011032801); end; diff --git a/compiler/symdef.pas b/compiler/symdef.pas index ce1b025df1..d1903b1f95 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -529,7 +529,9 @@ interface tsk_jvm_enum_bitset2set, // Java fpcBitSetToEnumSet function that returns an enumset corresponding to a BitSet tsk_jvm_enum_set2Set, // Java fpcEnumSetToEnumSet function that returns an enumset corresponding to another enumset (different enum kind) tsk_jvm_procvar_invoke, // Java invoke method that calls a wrapped procvar - tsk_jvm_virtual_clmethod // Java wrapper for virtual class method + tsk_jvm_virtual_clmethod, // Java wrapper for virtual class method + tsk_field_getter, // getter for a field (callthrough property is passed in skpara) + tsk_field_setter // Setter for a field (callthrough property is passed in skpara) ); {$ifdef oldregvars}