EmptyClass Test funktionsfähig
This commit is contained in:
parent
bfac3c8145
commit
24671ceca4
@ -721,7 +721,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
assumptions.add(globalAssumptions);
|
||||
|
||||
ConstraintsSet oderConstraints = new ConstraintsSet();
|
||||
|
||||
|
||||
for(Type gparam : this.get_ParaList()){
|
||||
if(gparam instanceof GenericTypeVar)assumptions.add(((GenericTypeVar)gparam).createAssumptions()); //Constraints für die Generischen Variablen erstellen und diese dem AssumptionsSet hinzufügen
|
||||
}
|
||||
@ -744,7 +744,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
|
||||
|
||||
//ConstraintsSet oderConstraints = this.TYPE(this.getMethodList(), fieldInitializers, assumptions);
|
||||
|
||||
|
||||
this.superClass = this.superClass.TYPE(assumptions, this);
|
||||
|
||||
for(Field f:this.getFields()){
|
||||
oderConstraints.add(f.TYPE(assumptions));
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import de.dhbwstuttgart.parser.JavaClassName;
|
||||
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
||||
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
@ -39,6 +40,10 @@ public class Constructor extends Method {
|
||||
*/
|
||||
public Constructor(Method methode){
|
||||
super(methode.get_Method_Name(), methode.getType(), methode.getParameterList(),methode.get_Block(), methode.getGenericDeclarationList(), methode.getOffset());
|
||||
//Sicherstellen, dass das erste Statement in der Methode ein SuperCall ist:
|
||||
if(this.get_Block().get_Statement().size() <1 || ! (this.get_Block().get_Statement().firstElement() instanceof SuperCall)){
|
||||
this.get_Block().statements.add(0, new SuperCall(this.get_Block()));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public TypeAssumptions createTypeAssumptions(Class classmember) {
|
||||
@ -52,18 +57,22 @@ public class Constructor extends Method {
|
||||
@Override
|
||||
public void genByteCode(ClassGen cg) {
|
||||
ConstantPoolGen _cp = cg.getConstantPool();
|
||||
//InstructionFactory _factory = new InstructionFactory(cg, _cp);
|
||||
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
|
||||
Class parentClass = this.getParentClass();
|
||||
|
||||
//Hier m<EFBFBD>sste drin stehen: Kreiere einen Block, welcher ein Statement enth<EFBFBD>lt, welches ein Super Statement ist.
|
||||
|
||||
//TODO: Alles dynamisch gestalten
|
||||
//init darf nur drin stehen, wenn Konstruktor;
|
||||
this.method = new MethodGen(Constants.ACC_PUBLIC, org.apache.bcel.generic.Type.getReturnType(this.getType().get_Name()), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
|
||||
this.method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
|
||||
|
||||
super.genByteCode(cg); //Aufrufen um Iteration <EFBFBD>ber Block zu starten
|
||||
|
||||
//Iteration <EFBFBD>ber Block starten
|
||||
Block instructions = this.get_Block();
|
||||
InstructionList blockInstructions = instructions.genByteCode(cg);
|
||||
|
||||
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
|
||||
|
||||
this.method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)
|
||||
|
||||
cg.addMethod(this.method.getMethod());
|
||||
}
|
||||
// super statement muss drin sein
|
||||
// stmt genByteCode + im block genByteCode implementieren & dann Hierarchie ausprobieren
|
||||
|
@ -255,20 +255,16 @@ public class Block extends Statement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genByteCode(ClassGen cg) {
|
||||
public InstructionList genByteCode(ClassGen cg) {
|
||||
//ConstantPoolGen _cp = cg.getConstantPool();
|
||||
InstructionFactory _factory = new InstructionFactory(cg, _cp);
|
||||
InstructionList il = new InstructionList();
|
||||
|
||||
//Frage: Wenn Block von Statements erbt, und Block selbst keinen BCEL Code besitzt, ist das hier dann nicht eine Sackgasse?
|
||||
|
||||
//Instructionhandle dynamisch
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(org.apache.bcel.generic.Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke(this.getParentClass().superclassid.toString(), "<init>", org.apache.bcel.generic.Type.VOID, org.apache.bcel.generic.Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID));
|
||||
for(Statement stmt : this.get_Statement()){
|
||||
il.append(stmt.genByteCode(cg));
|
||||
}
|
||||
//il.dispose();
|
||||
|
||||
il.dispose();
|
||||
|
||||
return il;
|
||||
}
|
||||
}
|
||||
// ino.end
|
||||
|
@ -5,6 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
@ -304,7 +305,7 @@ public class MethodCall extends Expr
|
||||
}
|
||||
|
||||
@Override
|
||||
public void genByteCode(ClassGen _cg) {
|
||||
public InstructionList genByteCode(ClassGen _cg) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
|
||||
}
|
||||
|
||||
|
||||
public abstract void genByteCode(ClassGen _cg);
|
||||
public abstract InstructionList genByteCode(ClassGen _cg);
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,14 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
||||
// ino.end
|
||||
// ino.module.This.8654.import
|
||||
import java.util.Hashtable;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
|
||||
import org.apache.bcel.Constants;
|
||||
import org.apache.bcel.generic.ClassGen;
|
||||
import org.apache.bcel.generic.InstructionFactory;
|
||||
import org.apache.bcel.generic.InstructionHandle;
|
||||
import org.apache.bcel.generic.InstructionList;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.logger.Logger;
|
||||
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
|
||||
import de.dhbwstuttgart.myexception.JVMCodeException;
|
||||
@ -79,6 +85,19 @@ public class SuperCall extends ThisCall
|
||||
String argList = "";
|
||||
if(this.getArgumentList() != null)argList = this.getArgumentList().printJavaCode(resultSet).getJavaCode();
|
||||
return new JavaCodeResult("super("+argList+")");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InstructionList genByteCode(ClassGen cg) {
|
||||
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
|
||||
InstructionList il = new InstructionList();
|
||||
Type superClass = this.getParentClass().getSuperClass();
|
||||
//Instructionhandle dynamisch
|
||||
InstructionHandle ih_0 = il.append(_factory.createLoad(org.apache.bcel.generic.Type.OBJECT, 0));
|
||||
il.append(_factory.createInvoke(superClass.getName().toString(), "<init>", org.apache.bcel.generic.Type.VOID, org.apache.bcel.generic.Type.NO_ARGS, Constants.INVOKESPECIAL));
|
||||
InstructionHandle ih_4 = il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID));
|
||||
|
||||
return il;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -304,5 +304,7 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract org.apache.bcel.generic.Type getBytecodeType();
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -78,6 +78,11 @@ public class Void extends RefType
|
||||
public Type checkTYPE(TypeAssumptions ass, SyntaxTreeNode method) {
|
||||
return this;//VOID ist immer korrekt, das wird vom Parser geprüft
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.apache.bcel.generic.Type getBytecodeType() {
|
||||
return org.apache.bcel.generic.Type.VOID;
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -6,6 +6,8 @@ import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import de.dhbwstuttgart.typeinference.EinzelElement;
|
||||
import de.dhbwstuttgart.typeinference.KomplexeMenge;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.OderMenge;
|
||||
import de.dhbwstuttgart.typeinference.UndMenge;
|
||||
@ -25,11 +27,45 @@ class TestKlasse {
|
||||
}
|
||||
}
|
||||
|
||||
class TestKlasseOderMenge extends OderMenge<TestKlasse>{
|
||||
Menge<TestKlasseUndMenge> set = new Menge<>();
|
||||
|
||||
@Override
|
||||
public Menge<? extends KomplexeMenge<TestKlasse>> getSet() {
|
||||
return set;
|
||||
}
|
||||
|
||||
public void addItem(TestKlasse string) {
|
||||
TestUndMenge toAdd = new TestKlasseUndMenge();
|
||||
toAdd.addItem(string);
|
||||
set.add(toAdd);
|
||||
}
|
||||
public void addItems(TestKlasseUndMenge undMenge) {
|
||||
set.add(undMenge);
|
||||
}
|
||||
}
|
||||
|
||||
class TestKlasseUndMenge extends UndMenge<TestKlasse>{
|
||||
Menge<KomplexeMenge<TestKlasse>> set = new Menge<>();
|
||||
|
||||
@Override
|
||||
public Menge<? extends KomplexeMenge<TestKlasse>> getSet() {
|
||||
return set;
|
||||
}
|
||||
public void addItem(TestKlasse string) {
|
||||
set.add(new EinzelElement<TestKlasse>(string));
|
||||
}
|
||||
|
||||
public void addItems(KomplexeMenge<TestKlasse> oderMenge) {
|
||||
set.add(oderMenge);
|
||||
}
|
||||
}
|
||||
|
||||
public class KeineDoppeltenVerweise {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
OderMenge<TestKlasse> oM1 = new OderMenge<>();
|
||||
OderMenge<TestKlasse> oM1 = new TestOderMenge();
|
||||
OderMenge<TestKlasse> oM2 = new OderMenge<>();
|
||||
UndMenge<TestKlasse> oM3 = new UndMenge<>();
|
||||
oM1.addItem(new TestKlasse("Menge 1, Item 1"));
|
||||
|
@ -20,11 +20,11 @@ import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
|
||||
|
||||
public class EmptyClass {
|
||||
public class EmptyClassTest {
|
||||
|
||||
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
|
||||
public final static String testFile = "EmptyClass.jav";
|
||||
public final static String outputFile = "EmptyClassTest.class";
|
||||
public final static String outputFile = "EmptyClass.class";
|
||||
|
||||
@Test
|
||||
public void test() {
|
Loading…
Reference in New Issue
Block a user