mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 13:09:18 +02:00
+ FpcEnumValueObtainable interface that's implemented by all FPC
enums (for use in set factory helpers) git-svn-id: branches/jvmbackend@18651 -
This commit is contained in:
parent
386136ba7c
commit
5ea497857d
@ -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));
|
||||||
|
@ -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
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
|
||||||
|
@ -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}
|
||||||
|
Loading…
Reference in New Issue
Block a user