Standardkonstruktor enthält nun SuperCall

This commit is contained in:
JanUlrich 2015-06-16 17:44:27 +02:00
parent 4191c8d8b2
commit 1c2ac73dbd
3 changed files with 15 additions and 7 deletions

View File

@ -27,6 +27,7 @@ import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.Expr; import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.statement.Statement; import de.dhbwstuttgart.syntaxtree.statement.Statement;
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar; import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
@ -90,7 +91,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
//ByteCodeResult bc = new ByteCodeResult(); //ByteCodeResult bc = new ByteCodeResult();
//_cg = new ClassGen(pkgName.get_Name() + "/" + name, superClass.get_Name(), name + ".java", Constants.ACC_PUBLIC , new String[] { }); //_cg = new ClassGen(pkgName.get_Name() + "/" + name, superClass.get_Name(), name + ".java", Constants.ACC_PUBLIC , new String[] { });
//_cg zurückgeben //_cg zur<EFBFBD>ckgeben
//bc.append(BCELByteCodeOutput); //bc.append(BCELByteCodeOutput);
//return _cg; //return _cg;
} }
@ -1247,7 +1248,11 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
} }
} }
if(!constructorVorhanden){//Falls kein Konstruktor vorhanden ist, muss noch der Standardkonstruktor angefügt werden: if(!constructorVorhanden){//Falls kein Konstruktor vorhanden ist, muss noch der Standardkonstruktor angefügt werden:
Block konstruktorBlock = new Block();
konstruktorBlock.statements.add(new SuperCall(konstruktorBlock));
//Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(konstruktorBlock,this.getName().toString(), this));
Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(this.getName().toString(), this)); Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(this.getName().toString(), this));
this.addField(standardKonstruktor); this.addField(standardKonstruktor);
} }

View File

@ -58,19 +58,19 @@ public class Constructor extends Method {
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
Class parentClass = this.getParentClass(); Class parentClass = this.getParentClass();
//Hier müsste drin stehen: Kreiere einen Block, welcher ein Statement enthält, welches ein Super Statement ist. //Hier m<EFBFBD>sste drin stehen: Kreiere einen Block, welcher ein Statement enth<EFBFBD>lt, welches ein Super Statement ist.
//TODO: Alles dynamisch gestalten //TODO: Alles dynamisch gestalten
//init darf nur drin stehen, wenn Konstruktor; //init darf nur drin stehen, wenn Konstruktor;
methode.method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.getReturnType(methode.getType().get_Name()), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp); methode.method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.getReturnType(methode.getType().get_Name()), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
methode.genByteCode(cg); //Aufrufen um Iteration über Block zu starten methode.genByteCode(cg); //Aufrufen um Iteration <EFBFBD>ber Block zu starten
} }
// super statement muss drin sein // super statement muss drin sein
// stmt genByteCode + im block genByteCode implementieren & dann Hierarchie ausprobieren // stmt genByteCode + im block genByteCode implementieren & dann Hierarchie ausprobieren
// de.dhbw.systanxtree.stmts supercall // de.dhbw.systanxtree.stmts supercall
// Aufrufhierarchie: Class->Felder->Konstruktor->Methode innerhalb Konstruktor->Block->Statements (in diesem Fall nur super())->hier wird bytecode für superaufruf generiert // Aufrufhierarchie: Class->Felder->Konstruktor->Methode innerhalb Konstruktor->Block->Statements (in diesem Fall nur super())->hier wird bytecode f<EFBFBD>r superaufruf generiert
@ -316,7 +316,6 @@ public class Constructor extends Method {
@Override @Override
public void set_Method_Name(String string) { public void set_Method_Name(String string) {
this.methode.set_Method_Name(string); this.methode.set_Method_Name(string);
} }

View File

@ -705,7 +705,11 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// Methode und Block teilen sich einen ReturnType: // Methode und Block teilen sich einen ReturnType:
return this.returntype; return this.returntype;
} }
public static Method createEmptyMethod(Block withBlock, String withSignature, Class parent) {
Method ret = Method.createEmptyMethod(withSignature, parent);
ret.set_Block(withBlock);
return ret;
}
public static Method createEmptyMethod(String withSignature, Class parent) { public static Method createEmptyMethod(String withSignature, Class parent) {
Method ret = new Method(0); Method ret = new Method(0);
DeclId DImethod = new DeclId(); DeclId DImethod = new DeclId();
@ -745,7 +749,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
//oben steht MethodGen method als Variable (Z. 71) //oben steht MethodGen method als Variable (Z. 71)
// Über Statements iterieren um Block abzurufen // <EFBFBD>ber Statements iterieren um Block abzurufen
for (Statement statements : block.get_Statement()) { for (Statement statements : block.get_Statement()) {
statements.genByteCode(cg); statements.genByteCode(cg);
} }