* moved jvm-specific classdef-related fields from tenumdef to a platform-

specific descendant

git-svn-id: trunk@27439 -
This commit is contained in:
Jonas Maebe 2014-04-01 21:41:30 +00:00
parent 9c7c64a3af
commit 93d50bc287
12 changed files with 71 additions and 46 deletions

View File

@ -2315,7 +2315,7 @@ implementation
sym: tstaticvarsym;
begin
result:=false;
sym:=tstaticvarsym(tenumdef(def).getbasedef.classdef.symtable.Find('__FPC_ZERO_INITIALIZER'));
sym:=tstaticvarsym(tcpuenumdef(tenumdef(def).getbasedef).classdef.symtable.Find('__FPC_ZERO_INITIALIZER'));
{ no enum with ordinal value 0 -> exit }
if not assigned(sym) then
exit;
@ -2429,7 +2429,7 @@ implementation
(checkdef.typ=formaldef) then
checkdef:=java_jlobject
else if checkdef.typ=enumdef then
checkdef:=tenumdef(checkdef).classdef
checkdef:=tcpuenumdef(checkdef).classdef
else if checkdef.typ=setdef then
begin
if tsetdef(checkdef).elementdef.typ=enumdef then

View File

@ -230,7 +230,7 @@ implementation
end;
enumdef:
begin
result:=jvmaddencodedtype(tenumdef(def).getbasedef.classdef,false,encodedstr,forcesignature,founderror);
result:=jvmaddencodedtype(tcpuenumdef(tenumdef(def).getbasedef).classdef,false,encodedstr,forcesignature,founderror);
end;
orddef :
begin
@ -683,7 +683,7 @@ implementation
end;
enumdef:
begin
result:=tenumdef(def).getbasedef.classdef;
result:=tcpuenumdef(tenumdef(def).getbasedef).classdef;
end;
pointerdef :
begin

View File

@ -54,7 +54,7 @@ interface
uses
systems,
cutils,verbose,constexp,globtype,
symconst,symtable,symdef,
symconst,symtable,symdef,symcpu,
paramgr,procinfo,pass_1,
aasmtai,aasmdata,aasmcpu,defutil,
hlcgobj,hlcgcpu,cgutils,
@ -231,7 +231,7 @@ interface
procname:='OF';
if isenum then
begin
inserttypeconv_explicit(tsetelementnode(right).left,tenumdef(tsetelementnode(right).left.resultdef).getbasedef.classdef);
inserttypeconv_explicit(tsetelementnode(right).left,tcpuenumdef(tenumdef(tsetelementnode(right).left.resultdef).getbasedef).classdef);
result:=cloadvmtaddrnode.create(ctypenode.create(java_juenumset));
end
else
@ -247,7 +247,7 @@ interface
procname:='RANGE';
if isenum then
begin
inserttypeconv_explicit(tsetelementnode(right).right,tenumdef(tsetelementnode(right).right.resultdef).getbasedef.classdef);
inserttypeconv_explicit(tsetelementnode(right).right,tcpuenumdef(tenumdef(tsetelementnode(right).right.resultdef).getbasedef).classdef);
end
else
begin
@ -268,7 +268,7 @@ interface
procname:='ADD';
if isenum then
begin
inserttypeconv_explicit(tsetelementnode(right).left,tenumdef(tsetelementnode(right).left.resultdef).getbasedef.classdef);
inserttypeconv_explicit(tsetelementnode(right).left,tcpuenumdef(tenumdef(tsetelementnode(right).left.resultdef).getbasedef).classdef);
end
else
begin
@ -284,7 +284,7 @@ interface
factory method, then add all of its elements }
if isenum then
begin
inserttypeconv_explicit(tsetelementnode(right).right,tenumdef(tsetelementnode(right).right.resultdef).getbasedef.classdef);
inserttypeconv_explicit(tsetelementnode(right).right,tcpuenumdef(tenumdef(tsetelementnode(right).right.resultdef).getbasedef).classdef);
tmpn:=cloadvmtaddrnode.create(ctypenode.create(java_juenumset));
end
else

View File

@ -880,12 +880,12 @@ implementation
left:=nil;
end;
function ord_enum_explicit_typecast(fdef: torddef; todef: tenumdef): tnode;
function ord_enum_explicit_typecast(fdef: torddef; todef: tcpuenumdef): tnode;
var
psym: tsym;
begin
{ we only create a class for the basedefs }
todef:=todef.getbasedef;
todef:=tcpuenumdef(todef.getbasedef);
psym:=search_struct_member(todef.classdef,'FPCVALUEOF');
if not assigned(psym) or
(psym.typ<>procsym) then
@ -899,12 +899,12 @@ implementation
left:=nil;
end;
function enum_ord_explicit_typecast(fdef: tenumdef; todef: torddef): tnode;
function enum_ord_explicit_typecast(fdef: tcpuenumdef; todef: torddef): tnode;
var
psym: tsym;
begin
{ we only create a class for the basedef }
fdef:=fdef.getbasedef;
fdef:=tcpuenumdef(fdef.getbasedef);
psym:=search_struct_member(fdef.classdef,'FPCORDINAL');
if not assigned(psym) or
(psym.typ<>procsym) then
@ -950,7 +950,7 @@ implementation
if tsetdef(resultdef).elementdef.typ=enumdef then
begin
inserttypeconv_explicit(left,s64inttype);
enumclassdef:=tenumdef(tsetdef(resultdef).elementdef).getbasedef.classdef;
enumclassdef:=tcpuenumdef(tenumdef(tsetdef(resultdef).elementdef).getbasedef).classdef;
mp:=cloadvmtaddrnode.create(ctypenode.create(enumclassdef));
helpername:='fpcLongToEnumSet';
{ enumclass.fpcLongToEnumSet(left,setbase,setsize) }
@ -1343,14 +1343,14 @@ implementation
if left.resultdef.typ=orddef then
begin
if not check_only then
resnode:=ord_enum_explicit_typecast(torddef(left.resultdef),tenumdef(resultdef));
resnode:=ord_enum_explicit_typecast(torddef(left.resultdef),tcpuenumdef(resultdef));
result:=true;
exit;
end
else if resultdef.typ=orddef then
begin
if not check_only then
resnode:=enum_ord_explicit_typecast(tenumdef(left.resultdef),torddef(resultdef));
resnode:=enum_ord_explicit_typecast(tcpuenumdef(left.resultdef),torddef(resultdef));
result:=true;
exit;
end

View File

@ -85,7 +85,7 @@ implementation
uses
globals,cutils,widestr,verbose,constexp,fmodule,
symdef,symsym,symtable,symconst,
symdef,symsym,symcpu,symtable,symconst,
aasmdata,aasmcpu,defutil,
nutils,ncnv,nld,nmem,pjvm,pass_1,
cgbase,hlcgobj,hlcgcpu,cgutils,cpubase
@ -98,7 +98,7 @@ implementation
function tjvmordconstnode.pass_1: tnode;
var
basedef: tenumdef;
basedef: tcpuenumdef;
sym: tenumsym;
classfield: tsym;
begin
@ -120,7 +120,7 @@ implementation
exit;
end;
{ b) find the corresponding class field }
basedef:=tenumdef(resultdef).getbasedef;
basedef:=tcpuenumdef(tenumdef(resultdef).getbasedef);
classfield:=search_struct_member(basedef.classdef,sym.name);
{ c) create loadnode of the field }
@ -313,7 +313,7 @@ implementation
mp:=cloadvmtaddrnode.create(ctypenode.create(java_juenumset));
if len=0 then
begin
enumele:=cloadvmtaddrnode.create(ctypenode.create(tenumdef(eledef).getbasedef.classdef));
enumele:=cloadvmtaddrnode.create(ctypenode.create(tcpuenumdef(tenumdef(eledef).getbasedef).classdef));
inserttypeconv_explicit(enumele,search_system_type('JLCLASS').typedef);
paras:=ccallparanode.create(enumele,nil);
result:=ccallnode.createinternmethod(mp,'NONEOF',paras)

View File

@ -73,7 +73,7 @@ implementation
uses
cutils,globals,verbose,globtype,constexp,fmodule,
aasmbase,aasmtai,aasmdata,aasmcpu,
symtype,symconst,symdef,symsym,symtable,jvmdef,
symtype,symconst,symdef,symsym,symcpu,symtable,jvmdef,
defutil,
nadd,nbas,ncon,ncnv,nmat,nmem,ncal,nld,nflw,nutils,
cgbase,pass_1,pass_2,
@ -362,7 +362,7 @@ implementation
if seteledef.typ=enumdef then
begin
inserttypeconv_explicit(setpara,java_juenumset);
inserttypeconv_explicit(valuepara.left,tenumdef(seteledef).getbasedef.classdef);
inserttypeconv_explicit(valuepara.left,tcpuenumdef(tenumdef(seteledef).getbasedef).classdef);
end
else
begin

View File

@ -410,7 +410,7 @@ implementation
begin
if (right.location.loc<>LOC_CONSTANT) then
begin
psym:=search_struct_member(tenumdef(right.resultdef).getbasedef.classdef,'FPCORDINAL');
psym:=search_struct_member(tcpuenumdef(tenumdef(right.resultdef).getbasedef).classdef,'FPCORDINAL');
if not assigned(psym) or
(psym.typ<>procsym) or
(tprocsym(psym).ProcdefList.count<>1) then

View File

@ -223,7 +223,7 @@ implementation
{ in case of enum type, initialize with enum(0) if it exists }
if sym.vardef.typ=enumdef then
begin
enuminitsym:=tstaticvarsym(tenumdef(sym.vardef).getbasedef.classdef.symtable.Find('__FPC_ZERO_INITIALIZER'));
enuminitsym:=tstaticvarsym(tcpuenumdef(tenumdef(sym.vardef).getbasedef).classdef.symtable.Find('__FPC_ZERO_INITIALIZER'));
if assigned(enuminitsym) then
initnode:=cloadnode.create(enuminitsym,enuminitsym.owner);
end

View File

@ -305,7 +305,7 @@ implementation
clash; at unit level because we don't want its methods to be nested
inside a function in case its a local type) }
enumclass:=cobjectdef.create(odt_javaclass,'$'+current_module.realmodulename^+'$'+name+'$InternEnum$'+tostr(def.defid),java_jlenum);
tenumdef(def).classdef:=enumclass;
tcpuenumdef(def).classdef:=enumclass;
include(enumclass.objectoptions,oo_is_enum_class);
include(enumclass.objectoptions,oo_is_sealed);
{ implement FpcEnumValueObtainable interface }

View File

@ -118,6 +118,16 @@ type
tcpustringdefclass = class of tcpustringdef;
tcpuenumdef = class(tenumdef)
protected
procedure ppuload_platform(ppufile: tcompilerppufile); override;
procedure ppuwrite_platform(ppufile: tcompilerppufile); override;
public
{ class representing this enum on the Java side }
classdef : tobjectdef;
classdefderef : tderef;
function getcopy: tstoreddef; override;
procedure buildderef; override;
procedure deref; override;
end;
tcpuenumdefclass = class of tcpuenumdef;
@ -194,6 +204,41 @@ implementation
symconst,symbase,jvmdef,
paramgr;
procedure tcpuenumdef.ppuload_platform(ppufile: tcompilerppufile);
begin
inherited;
ppufile.getderef(classdefderef);
end;
procedure tcpuenumdef.ppuwrite_platform(ppufile: tcompilerppufile);
begin
inherited;
ppufile.putderef(classdefderef);
end;
function tcpuenumdef.getcopy: tstoreddef;
begin
result:=inherited;
tcpuenumdef(result).classdef:=classdef;
end;
procedure tcpuenumdef.buildderef;
begin
inherited;
classdefderef.build(classdef);
end;
procedure tcpuenumdef.deref;
begin
inherited;
classdef:=tobjectdef(classdefderef.resolve);
end;
{****************************************************************************
tcpuprocdef
****************************************************************************}

View File

@ -135,7 +135,7 @@ unit tgcpu;
if tsetdef(def).elementdef.typ=enumdef then
begin
{ load enum class type }
list.concat(taicpu.op_sym(a_ldc,current_asmdata.RefAsmSymbol(tenumdef(tsetdef(def).elementdef).getbasedef.classdef.jvm_full_typename(true))));
list.concat(taicpu.op_sym(a_ldc,current_asmdata.RefAsmSymbol(tcpuenumdef(tenumdef(tsetdef(def).elementdef).getbasedef).classdef.jvm_full_typename(true))));
thlcgjvm(hlcg).incstack(current_asmdata.CurrAsmList,1);
{ call tenumset.noneOf() class method }
sym:=tsym(tobjectdef(java_juenumset).symtable.find('NONEOF'));

View File

@ -827,11 +827,6 @@ interface
basedef : tenumdef;
basedefderef : tderef;
symtable : TSymtable;
{$ifdef jvm}
{ class representing this enum on the Java side }
classdef : tobjectdef;
classdefderef : tderef;
{$endif}
has_jumps : boolean;
constructor create;virtual;
constructor create_subrange(_basedef:tenumdef;_min,_max:asizeint);virtual;
@ -2339,9 +2334,6 @@ implementation
maxval:=ppufile.getaint;
savesize:=ppufile.getaint;
has_jumps:=false;
{$ifdef jvm}
ppufile.getderef(classdefderef);
{$endif}
if df_copied_def in defoptions then
begin
symtable:=nil;
@ -2379,9 +2371,6 @@ implementation
tenumdef(result).symtable:=symtable.getcopy;
tenumdef(result).basedef:=self;
end;
{$ifdef jvm}
tenumdef(result).classdef:=classdef;
{$endif}
tenumdef(result).has_jumps:=has_jumps;
tenumdef(result).basedefderef:=basedefderef;
include(tenumdef(result).defoptions,df_copied_def);
@ -2507,9 +2496,6 @@ implementation
basedefderef.build(basedef)
else
tenumsymtable(symtable).buildderef;
{$ifdef jvm}
classdefderef.build(classdef);
{$endif}
end;
@ -2523,9 +2509,6 @@ implementation
end
else
tenumsymtable(symtable).deref;
{$ifdef jvm}
classdef:=tobjectdef(classdefderef.resolve);
{$endif}
end;
@ -2535,9 +2518,6 @@ implementation
ppufile.putaint(min);
ppufile.putaint(max);
ppufile.putaint(savesize);
{$ifdef jvm}
ppufile.putderef(classdefderef);
{$endif}
if df_copied_def in defoptions then
ppufile.putderef(basedefderef);
writeentry(ppufile,ibenumdef);