mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-24 12:49:18 +02:00
* allocate/initialize implicit pointer type fields (arrays, records) in
JVM classes after calling the inherited constructor (before doing so, self is not yet valid) git-svn-id: branches/jvmbackend@18456 -
This commit is contained in:
parent
a5af71a8d8
commit
cc6a303ee2
@ -29,7 +29,7 @@ interface
|
|||||||
uses
|
uses
|
||||||
globtype,
|
globtype,
|
||||||
aasmbase,aasmdata,
|
aasmbase,aasmdata,
|
||||||
symtype,symdef,
|
symbase,symconst,symtype,symdef,
|
||||||
cpubase, hlcgobj, cgbase, cgutils, parabase;
|
cpubase, hlcgobj, cgbase, cgutils, parabase;
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -147,7 +147,9 @@ uses
|
|||||||
|
|
||||||
property maxevalstackheight: longint read fmaxevalstackheight;
|
property maxevalstackheight: longint read fmaxevalstackheight;
|
||||||
|
|
||||||
|
procedure gen_initialize_fields_code(list:TAsmList);
|
||||||
protected
|
protected
|
||||||
|
procedure allocate_implicit_structs_for_st_with_base_ref(list: TAsmList; st: tsymtable; ref: treference; allocvartyp: tsymtyp);
|
||||||
procedure gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara); override;
|
procedure gen_load_uninitialized_function_result(list: TAsmList; pd: tprocdef; resdef: tdef; const resloc: tcgpara); override;
|
||||||
|
|
||||||
procedure inittempvariables(list:TAsmList);override;
|
procedure inittempvariables(list:TAsmList);override;
|
||||||
@ -197,7 +199,7 @@ implementation
|
|||||||
verbose,cutils,globals,
|
verbose,cutils,globals,
|
||||||
defutil,
|
defutil,
|
||||||
aasmtai,aasmcpu,
|
aasmtai,aasmcpu,
|
||||||
symconst,symtable,symsym,jvmdef,
|
symtable,symsym,jvmdef,
|
||||||
procinfo,cgcpu,tgobj;
|
procinfo,cgcpu,tgobj;
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -1133,7 +1135,7 @@ implementation
|
|||||||
{ self }
|
{ self }
|
||||||
a_load_ref_stack(list,size,source,prepare_stack_for_ref(list,source,false));
|
a_load_ref_stack(list,size,source,prepare_stack_for_ref(list,source,false));
|
||||||
{ result }
|
{ result }
|
||||||
a_load_ref_stack(list,size,dest,prepare_stack_for_ref(list,source,false));
|
a_load_ref_stack(list,size,dest,prepare_stack_for_ref(list,dest,false));
|
||||||
{ call fpcDeepCopy helper }
|
{ call fpcDeepCopy helper }
|
||||||
srsym:=search_struct_member(tabstractrecorddef(size),'FPCDEEPCOPY');
|
srsym:=search_struct_member(tabstractrecorddef(size),'FPCDEEPCOPY');
|
||||||
if not assigned(srsym) or
|
if not assigned(srsym) or
|
||||||
@ -1675,6 +1677,59 @@ implementation
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure thlcgjvm.allocate_implicit_structs_for_st_with_base_ref(list: TAsmList; st: tsymtable; ref: treference; allocvartyp: tsymtyp);
|
||||||
|
var
|
||||||
|
tmpref: treference;
|
||||||
|
vs: tabstractvarsym;
|
||||||
|
i: longint;
|
||||||
|
begin
|
||||||
|
for i:=0 to st.symlist.count-1 do
|
||||||
|
begin
|
||||||
|
if (tsym(st.symlist[i]).typ<>allocvartyp) then
|
||||||
|
continue;
|
||||||
|
vs:=tabstractvarsym(st.symlist[i]);
|
||||||
|
if not jvmimplicitpointertype(vs.vardef) then
|
||||||
|
continue;
|
||||||
|
ref.symbol:=current_asmdata.RefAsmSymbol(vs.mangledname);
|
||||||
|
tg.gethltemp(list,vs.vardef,vs.vardef.size,tt_persistent,tmpref);
|
||||||
|
{ only copy the reference, not the actual data }
|
||||||
|
a_load_ref_ref(list,java_jlobject,java_jlobject,tmpref,ref);
|
||||||
|
{ remains live since there's still a reference to the created
|
||||||
|
entity }
|
||||||
|
tg.ungettemp(list,tmpref);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure thlcgjvm.gen_initialize_fields_code(list: TAsmList);
|
||||||
|
var
|
||||||
|
selfpara: tparavarsym;
|
||||||
|
selfreg: tregister;
|
||||||
|
ref: treference;
|
||||||
|
obj: tabstractrecorddef;
|
||||||
|
i: longint;
|
||||||
|
needinit: boolean;
|
||||||
|
begin
|
||||||
|
obj:=tabstractrecorddef(current_procinfo.procdef.owner.defowner);
|
||||||
|
{ check whether there are any fields that need initialisation }
|
||||||
|
needinit:=false;
|
||||||
|
for i:=0 to obj.symtable.symlist.count-1 do
|
||||||
|
if (tsym(obj.symtable.symlist[i]).typ=fieldvarsym) and
|
||||||
|
jvmimplicitpointertype(tfieldvarsym(obj.symtable.symlist[i]).vardef) then
|
||||||
|
begin
|
||||||
|
needinit:=true;
|
||||||
|
break;
|
||||||
|
end;
|
||||||
|
if not needinit then
|
||||||
|
exit;
|
||||||
|
selfpara:=tparavarsym(current_procinfo.procdef.parast.find('self'));
|
||||||
|
if not assigned(selfpara) then
|
||||||
|
internalerror(2011033001);
|
||||||
|
selfreg:=getaddressregister(list,selfpara.vardef);
|
||||||
|
a_load_loc_reg(list,obj,obj,selfpara.localloc,selfreg);
|
||||||
|
reference_reset_base(ref,selfreg,0,1);
|
||||||
|
allocate_implicit_structs_for_st_with_base_ref(list,obj.symtable,ref,fieldvarsym);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure thlcgjvm.resizestackfpuval(list: TAsmList; fromsize, tosize: tcgsize);
|
procedure thlcgjvm.resizestackfpuval(list: TAsmList; fromsize, tosize: tcgsize);
|
||||||
begin
|
begin
|
||||||
if (fromsize=OS_F32) and
|
if (fromsize=OS_F32) and
|
||||||
|
@ -50,6 +50,7 @@ implementation
|
|||||||
cgbase,cgutils,tgobj,procinfo,
|
cgbase,cgutils,tgobj,procinfo,
|
||||||
cpubase,aasmdata,aasmcpu,
|
cpubase,aasmdata,aasmcpu,
|
||||||
hlcgobj,hlcgcpu,
|
hlcgobj,hlcgcpu,
|
||||||
|
node,
|
||||||
jvmdef;
|
jvmdef;
|
||||||
|
|
||||||
|
|
||||||
@ -134,6 +135,12 @@ implementation
|
|||||||
thlcgjvm(hlcg).decstack(current_asmdata.CurrAsmList,totalremovesize)
|
thlcgjvm(hlcg).decstack(current_asmdata.CurrAsmList,totalremovesize)
|
||||||
else if totalremovesize<0 then
|
else if totalremovesize<0 then
|
||||||
thlcgjvm(hlcg).incstack(current_asmdata.CurrAsmList,-totalremovesize);
|
thlcgjvm(hlcg).incstack(current_asmdata.CurrAsmList,-totalremovesize);
|
||||||
|
|
||||||
|
{ if this was an inherited constructor call, initialise all fields that
|
||||||
|
are wrapped types following it }
|
||||||
|
if (tprocdef(procdefinition).proctypeoption=potype_constructor) and
|
||||||
|
(cnf_inherited in callnodeflags) then
|
||||||
|
thlcgjvm(hlcg).gen_initialize_fields_code(current_asmdata.CurrAsmList);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user