Fehler in NewClass und Constructor beheben

This commit is contained in:
JanUlrich 2015-11-13 16:29:41 +01:00
parent c646a34745
commit ed246e0f88
2 changed files with 5 additions and 3 deletions

View File

@ -66,7 +66,7 @@ public class Constructor extends Method {
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
Class parentClass = this.getParentClass();
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg), org.apache.commons.bcel6.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg), this.parameterlist.getBytecodeTypeList(cg) , this.parameterlist.getParameterNameArray(), "<init>", parentClass.name, il, _cp);
//FieldInitializations an Block anfügen
Block block = this.get_Block();

View File

@ -195,13 +195,15 @@ public class NewClass extends Expr
@Override
public InstructionList genByteCode(ClassGenerator _cg) {
InstructionList il = new InstructionList();
il.append(_cg.getInstructionFactory().createNew(this.getType().getBytecodeType(_cg).toString()));
il.append(InstructionConstants.DUP);
if(arglist!=null){
il.append(arglist.generateBytecode(_cg));
il.append(_cg.getInstructionFactory().createInvoke(this.get_Name(), "<init>",
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(), "<init>",
org.apache.commons.bcel6.generic.Type.VOID,
this.arglist.getBytecodeTypeList(_cg), Constants.INVOKESPECIAL));
}else{
il.append(_cg.getInstructionFactory().createInvoke(this.get_Name(), "<init>",
il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(), "<init>",
org.apache.commons.bcel6.generic.Type.VOID,
new org.apache.commons.bcel6.generic.Type[]{}, Constants.INVOKESPECIAL));
}