Преглед изворни кода

+ FpcEnumValueObtainable interface that's implemented by all FPC
enums (for use in set factory helpers)

git-svn-id: branches/jvmbackend@18651 -

Jonas Maebe пре 14 година
родитељ
комит
5ea497857d
4 измењених фајлова са 22 додато и 6 уклоњено
  1. 5 4
      compiler/agjasmin.pas
  2. 6 0
      compiler/pjvm.pas
  3. 6 2
      compiler/symcreat.pas
  4. 5 0
      rtl/java/system.pp

+ 5 - 4
compiler/agjasmin.pas

@@ -603,10 +603,6 @@ implementation
                   AsmWrite(superclass.import_lib^+'/');
                   AsmWrite(superclass.import_lib^+'/');
                 AsmWriteln(superclass.objextname^);
                 AsmWriteln(superclass.objextname^);
               end;
               end;
-            { signature for enum classes (must come after superclass) }
-            if (obj.typ=objectdef) and
-               (oo_is_enum_class in tobjectdef(obj).objectoptions) then
-              AsmWriteln('.signature "Ljava/lang/Enum<'+obj.jvm_full_typename(true)+';>;"');
             { implemented interfaces }
             { implemented interfaces }
             if (obj.typ=objectdef) and
             if (obj.typ=objectdef) and
                assigned(tobjectdef(obj).ImplementedInterfaces) then
                assigned(tobjectdef(obj).ImplementedInterfaces) then
@@ -620,6 +616,11 @@ implementation
                     AsmWriteln(intf.objextname^);
                     AsmWriteln(intf.objextname^);
                   end;
                   end;
               end;
               end;
+            { signature for enum classes (must come after superclass and
+              implemented interfaces) }
+            if (obj.typ=objectdef) and
+               (oo_is_enum_class in tobjectdef(obj).objectoptions) then
+              AsmWriteln('.signature "Ljava/lang/Enum<'+obj.jvm_full_typename(true)+';>;"');
             { in case of nested class: relation to parent class }
             { in case of nested class: relation to parent class }
             if obj.owner.symtabletype in [objectsymtable,recordsymtable] then
             if obj.owner.symtabletype in [objectsymtable,recordsymtable] then
               AsmWriteln(InnerStructDef(obj));
               AsmWriteln(InnerStructDef(obj));

+ 6 - 0
compiler/pjvm.pas

@@ -241,6 +241,8 @@ implementation
         tenumdef(def).classdef:=enumclass;
         tenumdef(def).classdef:=enumclass;
         include(enumclass.objectoptions,oo_is_enum_class);
         include(enumclass.objectoptions,oo_is_enum_class);
         include(enumclass.objectoptions,oo_is_sealed);
         include(enumclass.objectoptions,oo_is_sealed);
+        { implement FpcEnumValueObtainable interface }
+        enumclass.ImplementedInterfaces.add(TImplementedInterface.Create(tobjectdef(search_system_type('FPCENUMVALUEOBTAINABLE').typedef)));
         { create an alias for this type inside itself: this way we can choose a
         { 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
           name that can be used in generated Pascal code without risking an
           identifier conflict (since it is local to this class; the global name
           identifier conflict (since it is local to this class; the global name
@@ -334,6 +336,10 @@ implementation
         if not str_parse_method_dec('function FPCValueOf(__fpc_int: longint): __FPC_TEnumClassAlias; static;',potype_function,true,enumclass,pd) then
         if not str_parse_method_dec('function FPCValueOf(__fpc_int: longint): __FPC_TEnumClassAlias; static;',potype_function,true,enumclass,pd) then
           internalerror(2011062402);
           internalerror(2011062402);
         pd.synthetickind:=tsk_jvm_enum_fpcvalueof;
         pd.synthetickind:=tsk_jvm_enum_fpcvalueof;
+        { similar (instance) function for use in set factories; implements FpcEnumValueObtainable interface }
+        if not str_parse_method_dec('function fpcGenericValueOf(__fpc_int: longint): JLEnum;',potype_function,false,enumclass,pd) then
+          internalerror(2011062402);
+        pd.synthetickind:=tsk_jvm_enum_fpcvalueof;
 
 
         { insert "public static valueOf(string): tenumclass" that returns tenumclass(inherited valueOf(tenumclass,string)) }
         { insert "public static valueOf(string): tenumclass" that returns tenumclass(inherited valueOf(tenumclass,string)) }
         if not str_parse_method_dec('function valueOf(const __fpc_str: JLString): __FPC_TEnumClassAlias; static;',potype_function,true,enumclass,pd) then
         if not str_parse_method_dec('function valueOf(const __fpc_str: JLString): __FPC_TEnumClassAlias; static;',potype_function,true,enumclass,pd) then

+ 6 - 2
compiler/symcreat.pas

@@ -458,16 +458,20 @@ implementation
     var
     var
       enumclass: tobjectdef;
       enumclass: tobjectdef;
       enumdef: tenumdef;
       enumdef: tenumdef;
+      isclassmethod: boolean;
     begin
     begin
+      isclassmethod:=
+        (po_classmethod in pd.procoptions) and
+        not(pd.proctypeoption in [potype_constructor,potype_destructor]);
       enumclass:=tobjectdef(pd.owner.defowner);
       enumclass:=tobjectdef(pd.owner.defowner);
       enumdef:=tenumdef(ttypesym(search_struct_member(enumclass,'__FPC_TENUMALIAS')).typedef);
       enumdef:=tenumdef(ttypesym(search_struct_member(enumclass,'__FPC_TENUMALIAS')).typedef);
       { convert integer to corresponding enum instance: in case of no jumps
       { convert integer to corresponding enum instance: in case of no jumps
         get it from the $VALUES array, otherwise from the __fpc_ord2enum
         get it from the $VALUES array, otherwise from the __fpc_ord2enum
         hashmap }
         hashmap }
       if not enumdef.has_jumps then
       if not enumdef.has_jumps then
-        str_parse_method_impl('begin result:=__fpc_FVALUES[__fpc_int] end;',pd,false)
+        str_parse_method_impl('begin result:=__fpc_FVALUES[__fpc_int] end;',pd,isclassmethod)
       else
       else
-        str_parse_method_impl('begin result:=__FPC_TEnumClassAlias(__fpc_ord2enum.get(JLInteger.valueOf(__fpc_int))) end;',pd,true);
+        str_parse_method_impl('begin result:=__FPC_TEnumClassAlias(__fpc_ord2enum.get(JLInteger.valueOf(__fpc_int))) end;',pd,isclassmethod);
     end;
     end;
 
 
 
 

+ 5 - 0
rtl/java/system.pp

@@ -121,6 +121,11 @@ type
     procedure finalize; override;
     procedure finalize; override;
   end;
   end;
 
 
+  FpcEnumValueObtainable = interface
+    function fpcOrdinal: jint;
+    function fpcGenericValueOf(__fpc_int: longint): JLEnum;
+  end;
+
 {$i innr.inc}
 {$i innr.inc}
 {$i jmathh.inc}
 {$i jmathh.inc}
 {$i jrech.inc}
 {$i jrech.inc}