Merge mit bytecode

This commit is contained in:
JanUlrich 2015-07-14 14:51:15 +02:00
commit e891551b4e
56 changed files with 1266 additions and 359 deletions

View File

@ -6,7 +6,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="lib/junit-4.0.jar" sourcepath="/home/janulrich/.m2/repository/junit/junit/4.0/junit-4.0-sources.jar"/>
<classpathentry kind="lib" path="lib/cloning.jar"/>
<classpathentry kind="lib" path="lib/bcel-5.2.jar"/>
<classpathentry kind="lib" path="lib/guava-10.0.1.jar"/>
<classpathentry kind="lib" path="lib/bcel-6.0-SNAPSHOT.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

BIN
lib/bcel-6.0-SNAPSHOT.jar Normal file

Binary file not shown.

View File

@ -744,6 +744,7 @@ 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));
@ -1250,8 +1251,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
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(konstruktorBlock,this.getName().toString(), this));
//Constructor standardKonstruktor = new Constructor(Method.createEmptyMethod(this.getName().toString(), this));
this.addField(standardKonstruktor);
}

View File

@ -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 block = this.get_Block();
InstructionList blockInstructions = block.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

View File

@ -741,19 +741,27 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
@Override
public void genByteCode(ClassGen cg) {
/*ConstantPoolGen _cp = cg.getConstantPool();
* InstructionFactory _factory = new InstructionFactory(cg, _cp);
* InstructionList il = new InstructionList();
* Class parentClass = this.getParentClass();
*/
ConstantPoolGen _cp = cg.getConstantPool();
InstructionFactory _factory = new InstructionFactory(cg, _cp);
InstructionList il = new InstructionList();
Class parentClass = this.getParentClass();
//oben steht MethodGen method als Variable (Z. 71)
MethodGen method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, this.get_Method_Name(), parentClass.name, il, _cp);
// <EFBFBD>ber Statements iterieren um Block abzurufen
for (Statement statements : block.get_Statement()) {
statements.genByteCode(cg);
Block block = this.get_Block();
InstructionList blockInstructions = block.genByteCode(cg);
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
if (block.get_Statement().size() == 0) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
else {
if (!(block.get_Statement().lastElement() instanceof Return)) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
}
method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)
cg.addMethod(method.getMethod());
}
}

View File

@ -6,7 +6,14 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ASTORE;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.DSTORE;
import org.apache.bcel.generic.FSTORE;
import org.apache.bcel.generic.ISTORE;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.LSTORE;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -168,13 +175,40 @@ public class Assign extends Expr
}
public static int counterAssign = 0; //Zaehlvariable für ISTORE
@Override
public void genByteCode(ClassGen _cg) {
public InstructionList genByteCode(ClassGen cg) {
// TODO Auto-generated method stub
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr
counterAssign++; //macht STORE für meherere Variable nutzbar (nicht nur ISTORE_1, ISTORE_2, etc.)
String expr2Type = expr2.getType().get_Name().toString();
switch(expr2Type){
case "java.lang.Integer":
il.append(new ISTORE(counterAssign));
break;
case "java.lang.String":
il.append(new ASTORE(counterAssign));
break;
case "java.lang.Double":
il.append(new DSTORE(counterAssign));
break;
case "java.lang.Float":
il.append(new FSTORE(counterAssign));
break;
case "java.lang.Long":
il.append(new LSTORE(counterAssign));
break;
}
return il;
}
}

View File

@ -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));
il.dispose();
for(Statement stmt : this.get_Statement()){
il.append(stmt.genByteCode(cg));
}
//il.dispose();
return il;
}
}
// ino.end

View File

@ -5,6 +5,8 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -29,11 +31,7 @@ public class BoolLiteral extends Literal
// ino.end
// ino.class.BoolLiteral.25089.body
{
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
}
@ -129,6 +127,20 @@ public class BoolLiteral extends Literal
}
@Override
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
if (Bool == true){
il.append(_factory.ICONST_1);
}else {
il.append(_factory.ICONST_0);
}
return il;
}
}
// ino.end

View File

@ -4,7 +4,10 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.CharLiteral.8628.import
import java.util.Hashtable;
import org.apache.bcel.generic.BIPUSH;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -111,10 +114,19 @@ public class CharLiteral extends Literal
}
//Char-Getter fuer genByteCode
public char get_Char()
// ino.end
// ino.method.get_Int.25463.body
{
return Char;
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
il.append(new BIPUSH((byte) get_Char()));
return il;
}
}
// ino.end

View File

@ -4,7 +4,13 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.IntLiteral.8635.import
import java.util.Hashtable;
import org.apache.bcel.generic.BIPUSH;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.LDC;
import org.apache.bcel.generic.LDC2_W;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -128,10 +134,26 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
return ret;
}
//alter Double-Versuch vermutlich inkorrekt
/*@Override
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
il.append(new BIPUSH(new Double(get_Double()).byteValue()));
return il;
}*/
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
ConstantPoolGen cp = cg.getConstantPool();
//InstructionFactory _factory = new InstructionFactory(cg, cp);
InstructionList il = new InstructionList();
cp.addDouble(get_Double());
il.append(new LDC2_W(cp.getSize()-1));
return il;
}
}
// ino.end

View File

@ -4,8 +4,11 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.Expr.8630.import
import java.util.Hashtable;
import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
@ -109,5 +112,7 @@ public abstract class Expr extends ExprStmt
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions){
throw new NotImplementedException(); //wird die TYPEStmt-Methode innerhalb einer Expr aufgerufen, dann ist etwas schief gelaufen.
}
public abstract InstructionList genByteCode(ClassGen _cg);
}
// ino.end

View File

@ -5,6 +5,10 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.LDC;
import org.apache.bcel.generic.LDC2_W;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -128,8 +132,13 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
ConstantPoolGen cp = cg.getConstantPool();
InstructionList il = new InstructionList();
cp.addFloat(get_Float());
il.append(new LDC(cp.getSize()-1));
return il;
}
}

View File

@ -4,7 +4,10 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.IntLiteral.8635.import
import java.util.Hashtable;
import org.apache.bcel.generic.BIPUSH;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -131,9 +134,11 @@ public class IntLiteral extends Literal
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
il.append(new BIPUSH(new Integer(get_Int()).byteValue()));
return il;
}
}
// ino.end

View File

@ -2,7 +2,13 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.bcel.classfile.ConstantPool;
import org.apache.bcel.generic.BIPUSH;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.INVOKEDYNAMIC;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
@ -208,9 +214,24 @@ public class LambdaExpression extends Expr{
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
ConstantPoolGen cp = cg.getConstantPool();
InstructionList il = new InstructionList();
/*
* Bytecode:
* 0: invokedynamic #2, 0 //#2 führt zu einem InvokeDynamic im KP - wildes Referenzieren
* 5: astore_1 //Speichert wahrscheinlich den String meiner TestEXPR
* 6: return
*/
//---Variante 1 mit opcode----
short opcode = 186;//opcode - was genau ist das?
il.append(new INVOKEDYNAMIC(opcode, 0));//Invokedynamic lässt sich bei mir weder automatisch noch manuell importieren
//---Variante 2 mit Konstantenpool-Referenz---
//int cpSize = cp.getSize()-1;//Vermutlich ist die benötigte Referenz das aktuellste Element?
//il.append(new INVOKEDYNAMIC((short) cpSize, 0));
return il;
}
}

View File

@ -6,6 +6,7 @@ import java.util.Enumeration;
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;
@ -427,9 +428,9 @@ public class LocalVarDecl extends Statement implements TypeInsertable
}
@Override
public void genByteCode(ClassGen _cg) {
public InstructionList genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
return new InstructionList();
}
}
// ino.end

View File

@ -5,6 +5,9 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.LDC2_W;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -125,8 +128,14 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
ConstantPoolGen cp = cg.getConstantPool();
//InstructionFactory _factory = new InstructionFactory(cg, cp);
InstructionList il = new InstructionList();
cp.addLong(get_Long());
il.append(new LDC2_W(cp.getSize()-1));
return il;
}
}

View File

@ -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
}

View File

@ -5,6 +5,8 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -144,9 +146,16 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
il.append(expr.elementAt(0).genByteCode(cg));
il.append(_factory.createNewArray(org.apache.bcel.generic.Type.getType(getTypeName()), (short)1));
return il;
}
}

View File

@ -5,6 +5,8 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -91,9 +93,14 @@ public class Null extends Literal
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
il.append(_factory.ACONST_NULL);
return il;
}
}

View File

@ -5,7 +5,11 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.BIPUSH;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.IINC;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -95,10 +99,17 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
return ret;
}
public static int counterPostInc = 0;
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
counterPostInc++;
il.append(new IINC(counterPostInc,1));
//Tests aufgrund fehlener TypInferenz-Funktionalität nicht möglich
//Vermutlich muss der Counter noch angepasst werden, da nicht incrementierende Variablen nicht mitgezählt werden, und zu falschen aufrufen führen
//Gibt es einen Compiler-internen Variablenindex, der den Counter effektiver ersetzen könnte
return il;
}
}

View File

@ -4,6 +4,9 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.Return.8651.import
import java.util.Hashtable;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
@ -130,9 +133,17 @@ public class Return extends Statement
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
InstructionList il = retexpr.genByteCode(cg);
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
//Stimmt das VOID hier eigentlich? --> Wie wäre es mit getReturnType o.ä.? + evtl. von Type zu bcelType casten?
il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID));
return il;
}
}
// ino.end

View File

@ -129,7 +129,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
}
public abstract void genByteCode(ClassGen _cg);
public abstract InstructionList genByteCode(ClassGen _cg);
}

View File

@ -1,11 +1,21 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.typeinference.Menge;
// ino.end
// ino.module.StringLiteral.8653.import
import java.util.Hashtable;
import org.apache.bcel.classfile.ConstantPool;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.LDC;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -102,11 +112,29 @@ public class StringLiteral extends Literal
return "\""+this.string+"\"";
}
public String get_String()
// ino.end
// ino.method.get_Name.26246.body
{
return string;
}
//public static int counterString = 0;
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGen cg) {
ConstantPoolGen cp = cg.getConstantPool();
InstructionFactory _factory = new InstructionFactory(cg, cp);
InstructionList il = new InstructionList();
//counterString++;
//il.append(_factory.ASTORE_1, _factory.createNew(string));
cp.addString(get_String());
il.append(new LDC(cp.getSize()-1));
return il;
}
}
// ino.end

View File

@ -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;
@ -76,7 +82,22 @@ public class SuperCall extends ThisCall
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
return new JavaCodeResult("super("+this.getArgumentList().printJavaCode(resultSet)+")");
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;
}
}

View File

@ -37,6 +37,7 @@ public abstract class UnaryExpr extends Expr
ret.add(new RefType("Integer",this,-1));
ret.add(new RefType("Long",this,-1));
ret.add(new RefType("Double",this,-1));
ret.add(new RefType("Float",this,-1));
return ret ;
}
@ -59,7 +60,9 @@ public abstract class UnaryExpr extends Expr
@Override
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
return this.TYPEExpr(assumptions);
ConstraintsSet ret = this.TYPEExpr(assumptions);
this.setType(new de.dhbwstuttgart.syntaxtree.type.Void(this, -1).TYPE(assumptions, this));
return ret;
}

View File

@ -811,6 +811,10 @@ public class RefType extends ObjectType implements IMatchable
}
}
public org.apache.bcel.generic.Type getBytecodeType() {
return new org.apache.bcel.generic.ObjectType(this.getTypeName());
}
}
// ino.end

View File

@ -304,5 +304,7 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
return this;
}
public abstract org.apache.bcel.generic.Type getBytecodeType();
}
// ino.end

View File

@ -79,5 +79,10 @@ public class Void extends RefType
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

View File

@ -424,5 +424,6 @@ public class TypeAssumptions {
return null;
}
*/
}

View File

@ -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"));

6
test/bytecode/Assign.jav Normal file
View File

@ -0,0 +1,6 @@
class Assign{
void method() {a; a = 20;b; b=59;}
}

45
test/bytecode/Assign.java Normal file
View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class Assign {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "Assign.jav";
public final static String outputFile = "Assign.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,7 @@
class BoolLit{
void method() { b; b = false; }
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class BoolLitTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "BoolLit.jav";
public final static String outputFile = "BoolLit.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,7 @@
class CharLitTest{
void method() { c; c = 'A'; }
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class CharLitTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "CharLitTest.jav";
public final static String outputFile = "CharLitTest.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,6 @@
class DoubleLiteral{
void method() {a; a = 20.0d;}
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class DoubleLiteral {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "DoubleLiteral.jav";
public final static String outputFile = "DoubleLiteral.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -1,7 +1,7 @@
class EmptyClass{
public EmptyClass(){}
public void leckMichAmArsch(){}
}

View File

@ -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() {

View File

@ -0,0 +1,6 @@
class FloatLiteral{
void method() {f; f = 20.0f;}
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class FloatLiteral {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "FloatLiteral.jav";
public final static String outputFile = "FloatLiteral.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,8 @@
class LambdaExpr {
void method() {
lambda; lambda = ()-> 1;
}
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class LambdaExpr {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "LambdaExpr.jav";
public final static String outputFile = "LambdaExpr.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,6 @@
class LongLiteral{
void method() {l; l = 20L;}
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class LongLiteral {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "LongLiteral.jav";
public final static String outputFile = "LongLiteral.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,7 @@
class MethodEmpty{
void method() { }
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class MethodEmpty {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "MethodEmpty.jav";
public final static String outputFile = "MethodEmpty.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,7 @@
class MethodEmptyRetType{
Object method() { return null; }
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class MethodEmptyRetType {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "MethodEmptyRetType.jav";
public final static String outputFile = "MethodEmptyRetType.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,11 @@
class NewArray{
void method() {
a;
a = new Integer[2];
a = {1,2};
}
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class NewArrayTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "NewArray.jav";
public final static String outputFile = "NewArray.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,6 @@
class PostIncrement{
void method() {a; a = 20; a++;}
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class PostIncrement {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "PostIncrement.jav";
public final static String outputFile = "PostIncrement.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,7 @@
class StringLitTest{
void method() { s; s = "abcdefg"; t; t ="jfowehfowh"; }
}

View File

@ -0,0 +1,45 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertSet;
public class StringLitTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "StringLitTest.jav";
public final static String outputFile = "StringLitTest.class";
@Test
public void test() {
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(rootDirectory + testFile));
compiler.typeReconstruction();
ByteCodeResult bytecode = compiler.generateBytecode();
System.out.println(bytecode);
bytecode.getByteCode().getJavaClass().dump(new File(rootDirectory + outputFile));
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}