Merge branch 'bytecode' into unifyDev

This commit is contained in:
JanUlrich 2015-10-16 14:13:35 +02:00
commit 343ce89f7d
68 changed files with 969 additions and 462 deletions

View File

@ -0,0 +1,6 @@
package bcelifier;
public class BooleanValue {
Boolean c = true;
Boolean b = c.booleanValue();
}

View File

@ -0,0 +1,63 @@
package bcelifier;
import org.apache.commons.bcel6.generic.*;
import org.apache.commons.bcel6.classfile.*;
import org.apache.commons.bcel6.*;
import java.io.*;
public class BooleanValueCreator implements Constants {
private InstructionFactory _factory;
private ConstantPoolGen _cp;
private ClassGen _cg;
public BooleanValueCreator() {
_cg = new ClassGen("bcelifier.BooleanValue", "java.lang.Object", "BooleanValue.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
_cp = _cg.getConstantPool();
_factory = new InstructionFactory(_cg, _cp);
}
public void create(OutputStream out) throws IOException {
createFields();
createMethod_0();
_cg.getJavaClass().dump(out);
}
private void createFields() {
FieldGen field;
field = new FieldGen(0, new ObjectType("java.lang.Boolean"), "c", _cp);
_cg.addField(field.getField());
field = new FieldGen(0, new ObjectType("java.lang.Boolean"), "b", _cp);
_cg.addField(field.getField());
}
private void createMethod_0() {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.BooleanValue", il, _cp);
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
InstructionHandle ih_4 = il.append(_factory.createLoad(Type.OBJECT, 0));
il.append(new PUSH(_cp, 1));
il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new Type[] { Type.BOOLEAN }, Constants.INVOKESTATIC));
il.append(_factory.createFieldAccess("bcelifier.BooleanValue", "c", new ObjectType("java.lang.Boolean"), Constants.PUTFIELD));
InstructionHandle ih_12 = il.append(_factory.createLoad(Type.OBJECT, 0));
il.append(_factory.createLoad(Type.OBJECT, 0));
il.append(_factory.createFieldAccess("bcelifier.BooleanValue", "c", new ObjectType("java.lang.Boolean"), Constants.GETFIELD));
il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(_factory.createInvoke("java.lang.Boolean", "valueOf", new ObjectType("java.lang.Boolean"), new Type[] { Type.BOOLEAN }, Constants.INVOKESTATIC));
il.append(_factory.createFieldAccess("bcelifier.BooleanValue", "b", new ObjectType("java.lang.Boolean"), Constants.PUTFIELD));
InstructionHandle ih_26 = il.append(_factory.createReturn(Type.VOID));
method.setMaxStack();
method.setMaxLocals();
_cg.addMethod(method.getMethod());
il.dispose();
}
public static void main(String[] args) throws Exception {
bcelifier.BooleanValueCreator creator = new bcelifier.BooleanValueCreator();
creator.create(new FileOutputStream("bcelifier.BooleanValue.class"));
}
}

View File

@ -31,6 +31,7 @@ public class JavaToBCEL {
new BCELifier(new ClassParser(rootDirectory+"Null.class").parse(), new FileOutputStream(new File(rootDirectory+"NullCreator.java"))).start();
new BCELifier(new ClassParser(rootDirectory+"LocalVarAccess.class").parse(), new FileOutputStream(new File(rootDirectory+"LocalVarAccessCreator.java"))).start();
new BCELifier(new ClassParser(rootDirectory+"Wildcard.class").parse(), new FileOutputStream(new File(rootDirectory+"WildcardCreator.java"))).start();
new BCELifier(new ClassParser(rootDirectory+"BooleanValue.class").parse(), new FileOutputStream(new File(rootDirectory+"BooleanValueCreator.java"))).start();
} catch (ClassFormatException | IOException e) {
e.printStackTrace();

View File

@ -860,10 +860,10 @@ public class MyCompiler implements MyCompilerAPI
}
@Override
public Menge<ByteCodeResult> generateBytecode(TypeinferenceResultSet typeinferenceResult) {
public Menge<Menge<ByteCodeResult>> generateBytecode(TypeinferenceResultSet typeinferenceResult) {
//SourceFile parsedFile = this.m_AbstractSyntaxTree.firstElement();
//Class parsedClass = parsedFile.KlassenVektor.firstElement();
Menge<ByteCodeResult> ret = new Menge<>();
Menge<Menge<ByteCodeResult>> ret = new Menge<>();
for(SourceFile sf : this.m_AbstractSyntaxTree){
ret.addAll(sf.generateBytecode(typeinferenceResult));
}

View File

@ -127,6 +127,6 @@ public interface MyCompilerAPI
* Dafür müssen die Schritte Parsen und typeReconstruction ausgeführt werden.
* @return
*/
public Menge<ByteCodeResult> generateBytecode(TypeinferenceResultSet rs);
public Menge<Menge<ByteCodeResult>> generateBytecode(TypeinferenceResultSet rs);
}
// ino.end

View File

@ -0,0 +1,10 @@
package de.dhbwstuttgart.myexception;
public class NotImplementedException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;
}

View File

@ -15,7 +15,6 @@ import org.apache.commons.bcel6.generic.InstructionHandle;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.MethodGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.logger.SectionLogger;
@ -75,11 +74,13 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
* @param resultSet - Fehlende Typen im Syntaxbaum werden nach diesem ResultSet aufgelöst
* @return
*/
public ByteCodeResult genByteCode(TypeinferenceResultSet resultSet) {
public Menge<ByteCodeResult> genByteCode(TypeinferenceResultSet resultSet) {
InstructionFactory _factory;
DHBWConstantPoolGen _cp;
ClassGenerator _cg;
Menge<ByteCodeResult> results = new Menge<ByteCodeResult>();
SectionLogger logger = Logger.getSectionLogger(this.getClass().getName(), Section.CODEGEN);
logger.debug("Test");
@ -112,7 +113,11 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
}
ByteCodeResult code = new ByteCodeResult(_cg);
return code;
results.add(code);
results.addAll(getGenericClasses(_cg));
return results;
}
private Menge<Type> superif = new Menge<Type>();
@ -593,112 +598,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
{
return this.parahash;
}
// ino.end
/*static void string_rec(Hashtable ht){
String record="";
boolean isError=false;
record=record.concat("[");
for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){
String s = (String)k.nextElement();
Object o = e.nextElement();
record=record.concat(" "+s);
if(o instanceof Type){
record=record.concat(" = "+((Type)o).getName());
} else if(o instanceof Hashtable){
record=record.concat("= ");
string_rec((Hashtable)o);
if(e.hasMoreElements())
record=record.concat(", ");
} else if(o instanceof String){
record=record.concat(" = "+o);
if(e.hasMoreElements())
record=record.concat(", ");
}
else {
record=("[FEHLER: string_rec: unbekannter Typ!!!!!!");
isError=true;
}
}
record=record.concat("]");
if(isError){
parserlog.error(record);
}else{
parserlog.debug(record);
}
}*/
/*static void string_rec(Menge v){
String record=("{");
for(Enumeration e=v.elements();e.hasMoreElements();){
Type t = (Type)e.nextElement();
record=record.concat(" "+t.getName());
if(e.hasMoreElements())
record=record.concat(",");
}
record=record.concat("}");
parserlog.debug(record);
}*/
/*static void string_rec(String st, Hashtable ht){
String record=(st);
boolean isError=false;
record=record.concat("[");
for(Enumeration e=ht.elements(),k=ht.keys();e.hasMoreElements();){
String s = (String)k.nextElement();
Object o = e.nextElement();
record=record.concat(" "+s);
if(o instanceof Type){
record=record.concat(" = "+((Type)o).getName());
}
else if(o instanceof Hashtable){
record=record.concat("= ");
string_rec((Hashtable)o);
if(e.hasMoreElements())
record=record.concat(", ");
}
else if(o instanceof String){
record=record.concat(" = "+o);
if(e.hasMoreElements())
record=record.concat(", ");
}
else {
record=("[FEHLER: string_rec: unbekannter Typ!!!!!! " +o);
isError = true;
}
}
record=record.concat("]");
if(isError){
parserlog.error(record);
}else{
parserlog.debug(record);
}
}*/
/*static void string_rec(String st,Menge v)
{
String record=(st);
record=record.concat("{");
for(Enumeration e=v.elements();e.hasMoreElements();)
{
Type t = (Type)e.nextElement();
record=record.concat(" "+t.getName());
if(e.hasMoreElements())
{
record=record.concat(", ");
}
}
record=record.concat("}");
parserlog.debug(record);
}*/
/////////////////////////////////////////////////////////////////////////
// TypeReconstructionAlgorithmus
@ -771,165 +670,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
typinferenzLog.debug("Erstellte Constraints: "+oderConstraints, Section.TYPEINFERENCE);
return oderConstraints;
/*
CReconstructionTupleSet retTupleSet = this.TRStart(methodList, V, V_fields_methods, supportData);
inferencelog.debug("Bin aus TRStart() zur�ck in TRProg().");
//////////////////////////////
// Neu Ergebnismenge A aller
// Typannahmen erzeugen:
//////////////////////////////
inferencelog.debug("Erstelle Ergebnismenge...");
Menge<CTypeReconstructionResult> newA = new Menge<CTypeReconstructionResult>();
// Alle bisherigen ¯Â¿Â½glichkeiten an Typkombinationen durchgehen:
Menge<CTypeReconstructionResult> oldA = supportData.getA();
for(int i=0; i<oldA.size(); i++){
CTypeReconstructionResult oneReconResult = oldA.elementAt(i);
// Und mit den neuen ¯Â¿Â½glichen Typkombinationen vereinigen:
Iterator<CReconstructionTuple> retTupleIt = retTupleSet.getIterator();
while(retTupleIt.hasNext()){
CReconstructionTuple possibleTuple = retTupleIt.next();
this.clear(possibleTuple.getAssumSet(), rememberLocals);
// Neue Typinformationen mit alten Typinformationen vereinigen:
CTypeReconstructionResult newReconResult = oneReconResult.shallowCopy();
newReconResult.addDataFromTupel(possibleTuple);
//PL 05-08-02 eingefuegt
//Fuegt Klassen und GenericTypeVars zu A hinzu
newReconResult.addClassName(this.getName());
Menge<GenericTypeVar> genericsList = new Menge<GenericTypeVar>();
for(int ii =0; ii<this.get_ParaList().size(); ii++){
Type para = (Type)this.get_ParaList().elementAt(ii);
if(para instanceof GenericTypeVar){
genericsList.addElement((GenericTypeVar)para);
}
}
newReconResult.addGenericTypeVars(this.getName(), genericsList);
//Hinzuf�gen:
newA.addElement(newReconResult);
}
}
return newA;
*/
}
// ino.end
/**
* @return Eine Liste mit allen Methoden dieser Klasse
private Menge<Method> getMethodList() {
if(this.methodList != null) return this.methodList;
//TODO: UnnÃtige Berechnungen im folgenden Code rauskürzen:
//////////////////////////////
// Die Eingabedaten bauen:
//////////////////////////////
inferencelog.debug("Baue Eingabedaten...");
TypeAssumptions V_fields_methods = new TypeAssumptions(this.getName());
Menge<Method> methodList = new Menge<Method>();
Menge<CTypeAssumptionSet> V = new Menge<CTypeAssumptionSet>();
Menge<CTypeAssumption> rememberLocals = new Menge<CTypeAssumption>();
//////////////////////////////
// Alle Felder durchgehen:
// Zuerst alle Attribute, dann Methoden
// ge�ndert: hoth 06.04.2006
//////////////////////////////
for(Field field : this.getFields())
{
//////////////////////////////
// Attribut:
//////////////////////////////
}
for(Field field : this.getFields())
{
//////////////////////////////
// Methode:
//////////////////////////////
if(field instanceof Method){
Method method = (Method)field;
//if(method.get_Method_Name().equals(this.getName()) && ((method.getReturnType().equals(new mycompiler.mytype.Void(0))) || method.getReturnType() instanceof TypePlaceholder)){
if(method.get_Method_Name().equals(this.getName()) ){
method.set_Method_Name("<init>");
}
//hoth: 06.04.2006
//durchlaufe Block und suche nach Objektvariablen fuer Offset-Markierung
Iterator<CTypeAssumption> fieldVarIterator = V_fields_methods.iterator();
while (fieldVarIterator.hasNext())
{
//Wenn ObjektVariable
CTypeAssumption dieAssum = fieldVarIterator.next();
if(dieAssum instanceof CInstVarTypeAssumption)
{
Class.isFirstLocalVarDecl=false;
if(method.get_Block() != null)
method.get_Block().addOffsetsToAssumption(dieAssum,dieAssum.getIdentifier(),true);
}
}
methodList.addElement(method);
// ¯Â¿Â½r V_fields_methods:
CMethodTypeAssumption methodAssum = new CMethodTypeAssumption(this.getType(), method.get_Method_Name(), method.getReturnType(), method.getParameterCount(),method.getLineNumber(),method.getOffset(),new Menge<Integer>(),method.getGenericMethodParameters()); // Typannahme bauen...
// Methode in V_Fields_methods ablegen
// Dabei wird die OverloadedMethodID ermittelt !!
// => Method setzenuct
V_fields_methods.add(methodAssum);
method.setOverloadedID(methodAssum.getHashSetKey().getOverloadedMethodID());
// ¯Â¿Â½r die V_i:
CTypeAssumptionSet localAssum = new CTypeAssumptionSet();
// Bauen...
ParameterList parameterList = method.getParameterList();
if(parameterList!=null){
for(int i=0; i<parameterList.sc_get_Formalparalist().size(); i++){
FormalParameter para = parameterList.sc_get_Formalparalist().elementAt(i);
// ¯Â¿Â½r V_fields_methods:
CParaTypeAssumption paraAssum = new CParaTypeAssumption(this.getName(), method.get_Method_Name(), method.getParameterCount(), method.getOverloadedID(),para.getIdentifier(), para.getType(), para.getLineNumber(),para.getOffset(),new Menge<Integer>());
//fuege Offsets fuer Parameter hinzu, hoth: 06.04.2006
Class.isFirstLocalVarDecl=false;
if(method.get_Block() != null)
method.get_Block().addOffsetsToAssumption(paraAssum,paraAssum.getIdentifier(),true);
methodAssum.addParaAssumption(paraAssum);
// ¯Â¿Â½r die V_i:
CLocalVarTypeAssumption varAssum = new CLocalVarTypeAssumption(this.getName(), method.get_Method_Name(), method.getParameterCount(), method.getOverloadedID(),"1", para.getIdentifier(),para.getType(), para.getLineNumber(),para.getOffset(),new Menge<Integer>());
localAssum.addElement(varAssum);
rememberLocals.addElement(varAssum);
}
}
// ...und hinzuf�gen:
V.addElement(localAssum);
}
}
this.methodList = methodList;
return methodList;
}
*/
/**
* Ermittelt alle privaten Felder und Methoden der Klasse und Erstellt eine Assumption ¼r diese.
@ -957,49 +698,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
this.typeAssumptions = assumptions; //Diese ¼ssen anschließend nicht wieder generiert werden.
return assumptions;
}
/*
public ConstraintsSet TYPE(Menge<Method> methodList, Menge<Expr> fielddeclarationList, TypeAssumptions assumptions){
ConstraintsSet ret = new ConstraintsSet();
// Die Felddeklarationen werden zu den Assumptions hinzugefügt und gelten danach ¼r jede Methode.
//TypeAssumptions assumptionsPlusFieldAssumptions = new TypeAssumptions(assumptions);
for(Expr expr : fielddeclarationList){
//ret.add(expr.TYPEStmt(assumptionsPlusFieldAssumptions));
ret.add(expr.TYPEStmt(assumptions));
}
for(Method methode : methodList){
//ret.add(methode.TYPE(assumptionsPlusFieldAssumptions));
ret.add(methode.TYPE(assumptions));
}
return ret;
}
*/
// ino.method.RetType.23119.defdescription type=javadoc
/**
* Liefert den berechneten ¯Â¿Â½ckgabetyp ¯Â¿Â½r die �bergebene Methode zur�ck.<br/>
* (siehe Algorithmus RetType, Martin Pl�micke)
* <br/>Author: ¯Â¿Â½rg ¯Â¿Â½uerle
* @param me
* @param V
* @return
// ino.end
// ino.method.RetType.23119.definition
private Type RetType(Method me, CTypeAssumptionSet V)
// ino.end
// ino.method.RetType.23119.body
{
CTypeAssumption assum = V.getElement(new CMethodKey(this.getName(), me.get_Method_Name(), me.getParameterCount(),me.getOverloadedID()));
if(assum instanceof CMethodTypeAssumption){
return ((CMethodTypeAssumption)assum).getAssumedType();
}
else return null;
}
// ino.end
*/
// ino.method.toString.23125.defdescription type=javadoc
/**
* <br/>Author: Martin Pl�micke
@ -1037,48 +737,8 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
for(Field f : this.getFields()){
//f.wandleRefTypeAttributes2GenericAttributes(paralist);
}
/*
Menge fieldsAndMethods=this.getFields();
// Alle Methoden und Instanzvariablen durchgehen
for(int i=0;i<fieldsAndMethods.size();i++){
// Ist es eine Methode?
if(fieldsAndMethods.get(i) instanceof Method){
Method method=(Method)fieldsAndMethods.get(i);
method.wandleRefTypeAttributes2GenericAttributes(paralist);
}// Ist es eine InstanzVariable?
*//*
else if(fieldsAndMethods.get(i) instanceof InstVarDecl){
InstVarDecl instVar=(InstVarDecl)fieldsAndMethods.get(i);
Type type=instVar.getType();
// Nur wenn es sich um ein RefType-Field handelt
if(type instanceof RefType){
GenericTypeVar pendant=ClassHelper.findGenericType((RefType)type,paralist,null);
if(pendant!=null){ //Wenn generisch, dann modifizieren
instVar.setType(pendant);
}
}
}
}*/
}
// ino.end
// private void removeOldLocalVars(CTypeAssumptionSet V_i, CTypeAssumptionSet V_last){
// Enumeration<IHashSetKey> enumer = V_last.getHashtable().keys();
// while(enumer.hasMoreElements()){
// CTypeAssumption currentAssum = V_last.getElement(enumer.nextElement());
// if(currentAssum instanceof CLocalVarTypeAssumption){
// V_i.removeElement(currentAssum);
// }
// }
//
// }
// ino.method.getSimpleName.23140.defdescription type=javadoc
/**
* HOTI
* Liefert bei Klassen die fullyQualified angegeben wurden
@ -1116,18 +776,6 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
public String printJavaCode(TypeinferenceResultSet reconstructionResult){
JavaCodeResult ret = new JavaCodeResult("class ");
//Generiere JavaCode der extends-Typen:
/*
String containedTypesJavaCode = "";
for(Type containedType : containedTypes){
containedTypesJavaCode += containedType.printJavaCode(resultSet)+ ", ";
}
if(containedTypesJavaCode.length()>1)containedTypesJavaCode = containedTypesJavaCode.substring(0, containedTypesJavaCode.length() -2);
*/
JavaCodeResult classBodyCode = new JavaCodeResult();
if(this.modifiers!=null)classBodyCode.attach(this.modifiers.printJavaCode(reconstructionResult.getUnifiedConstraints())).attach(" ");
@ -1382,5 +1030,22 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
public boolean isInterface(){
return false;
}
private Collection<? extends ByteCodeResult> getGenericClasses(ClassGenerator _cg) {
Collection<ByteCodeResult> results = new Menge<>();
//Super Klasse
String name = "java/util/Vectorjava/lang/String"; //getParentClass().getType().getBytecodeSignature(_cg);
Type superClass = new Class("java/util/Vector",-1).getType();
_cg = new ClassGenerator(name, superClass, name + ".java", Constants.ACC_PUBLIC , new String[] { }, new TypeinferenceResultSet(null, null, null));
ByteCodeResult code = new ByteCodeResult(_cg);
results.add(code);
return results;
}
}
// ino.end

View File

@ -1010,8 +1010,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
ret.add(this.block.TYPEStmt(localAss));
// eine Verknüpfung mit der Type Assumption aus dem Assumption Set
// und dem ermittelten Typ der Methode:
ret.add(new SingleConstraint(this.block.getType().TYPE(localAss, this),
this.returntype.TYPE(localAss, this)));
ret.add(new SingleConstraint(this.block.getType().TYPE(localAss, this), this.returntype.TYPE(localAss, this)));
return ret;
}

View File

@ -2005,8 +2005,8 @@ public class SourceFile
* Bisher wird nur der Bytecode der Klassen generiert. Nicht der Interfaces.
* @return
*/
public Collection<? extends ByteCodeResult> generateBytecode(TypeinferenceResultSet rs) {
Menge<ByteCodeResult> ret = new Menge<>();
public Menge<Menge<ByteCodeResult>> generateBytecode(TypeinferenceResultSet rs) {
Menge<Menge<ByteCodeResult>> ret = new Menge<>();
for(Class cl : this.KlassenVektor){
ret.add(cl.genByteCode(rs));
}

View File

@ -6,10 +6,16 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import org.apache.commons.bcel6.generic.BranchInstruction;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.GOTO;
import org.apache.commons.bcel6.generic.IF_ICMPNE;
import org.apache.commons.bcel6.generic.InstructionConstants;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.NOP;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -214,21 +220,35 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
return ret;
}
private InstructionList genUnboxByteCode(ClassGen _cg, Type t){
return null;
}
@Override
public InstructionList genByteCode(ClassGen _cg, TypeAssumptions ass) {
public InstructionList genByteCode(ClassGenerator _cg) {
InstructionList linkeSeite = this.expr1.genByteCode(_cg);
InstructionList rechteSeite = this.expr2.genByteCode(_cg);
if(this.getReturnType().getName().equals(new JavaClassName("String"))){
throw new TypeinferenceException("Zeichenketten zusammenfügen ist noch nicht unterstützt",this);
}
//TODO: Je nachdem welches der Rückgabetyp ist, müssen die linke und rechte Seite unboxt und addiert werden.
return null;
}
private InstructionList genUnboxByteCode(ClassGen _cg, Type t){
return null;
linkeSeite.append(rechteSeite);
//TODO: bytecode (Bis jetzt wird jeder Condition als EQUALS behandelt)
//TODO: bytecode autoboxing
BranchInstruction if_icmpneInstruction = new IF_ICMPNE(null);
linkeSeite.append(if_icmpneInstruction);
linkeSeite.append(InstructionConstants.ICONST_1);
BranchInstruction gotoInstruction = new GOTO(null);
linkeSeite.append(gotoInstruction);
if_icmpneInstruction.setTarget(linkeSeite.append(InstructionConstants.ICONST_0));
gotoInstruction.setTarget(linkeSeite.append(new NOP()));
return linkeSeite;
}
}

View File

@ -5,10 +5,12 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionConstants;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -128,17 +130,16 @@ public class BoolLiteral extends Literal
}
@Override
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
public InstructionList genByteCode(ClassGenerator _cg) {
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
InstructionList il = new InstructionList();
if (Bool == true){
il.append(_factory.ICONST_1);
il.append(InstructionConstants.ICONST_1);
}else {
il.append(_factory.ICONST_0);
il.append(InstructionConstants.ICONST_0);
}
return il;
}

View File

@ -6,11 +6,14 @@ import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.myexception.SCExcept;
import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
@ -119,12 +122,10 @@ public class CastExpr extends UnaryExpr
return ret;
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}

View File

@ -10,6 +10,7 @@ import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -121,9 +122,11 @@ public class CharLiteral extends Literal
{
return Char;
}
@Override
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
public InstructionList genByteCode(ClassGenerator _cg) {
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
InstructionList il = new InstructionList();
il.append(new BIPUSH((byte) get_Char()));
return il;

View File

@ -13,6 +13,7 @@ import org.apache.commons.bcel6.generic.LDC;
import org.apache.commons.bcel6.generic.LDC2_W;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -144,15 +145,14 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}*/
@Override
public InstructionList genByteCode(ClassGen cg) {
ConstantPoolGen cp = cg.getConstantPool();
public InstructionList genByteCode(ClassGenerator _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;
}
}

View File

@ -5,8 +5,10 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -86,11 +88,10 @@ public class EmptyStmt extends Statement
return new Menge<SyntaxTreeNode>();
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}
}

View File

@ -11,6 +11,7 @@ import org.apache.commons.bcel6.generic.LDC;
import org.apache.commons.bcel6.generic.LDC2_W;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -132,14 +133,13 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public InstructionList genByteCode(ClassGen cg) {
ConstantPoolGen cp = cg.getConstantPool();
public InstructionList genByteCode(ClassGenerator _cg) {
ConstantPoolGen cp = _cg.getConstantPool();
InstructionList il = new InstructionList();
cp.addFloat(get_Float());
il.append(new LDC(cp.getSize()-1));
return il;
}
}
// ino.end

View File

@ -4,9 +4,16 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.BranchInstruction;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.GOTO;
import org.apache.commons.bcel6.generic.IF_ICMPGE;
import org.apache.commons.bcel6.generic.InstructionHandle;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.NOP;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -20,10 +27,13 @@ import de.dhbwstuttgart.syntaxtree.operator.RelOp;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.Unify;
@ -89,8 +99,13 @@ public class ForStmt extends Statement
@Override
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
// TODO Auto-generated method stub
return null;
//TODO: TYPEStmt
ConstraintsSet ret = new ConstraintsSet();
this.setType(TypePlaceholder.fresh(this));
ret.add(body_Loop_block.TYPEStmt(assumptions));
return ret;
}
public int getTypeLineNumber() {
@ -98,9 +113,9 @@ public class ForStmt extends Statement
}
@Override
public JavaCodeResult printJavaCode(ResultSet resultSet) {
// TODO Auto-generated method stub
throw new NotImplementedException();
public JavaCodeResult printJavaCode(ResultSet resultSet) {
// TODO printJavaCode
return new JavaCodeResult();
}
@Override
@ -118,8 +133,35 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
/*
0: iconst_0
1: istore_1
2: iload_1
3: bipush 10
5: if_icmpge 14
8: iinc 1, 1
11: goto 2
14: return
*/
InstructionList il = new InstructionList();
il.append(head_Initializer.genByteCode(_cg));
InstructionHandle ih = il.append(head_Condition.genByteCode(_cg));
BranchInstruction branch = new IF_ICMPGE(null);
il.append(branch);
il.append(body_Loop_block.genByteCode(_cg));
il.append(head_Loop_expr.genByteCode(_cg));
il.append(new GOTO(ih));
branch.setTarget(il.append(new NOP()));
return il;
}
}

View File

@ -6,10 +6,26 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.generic.ALOAD;
import org.apache.commons.bcel6.generic.ASTORE;
import org.apache.commons.bcel6.generic.BranchInstruction;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.GOTO;
import org.apache.commons.bcel6.generic.GotoInstruction;
import org.apache.commons.bcel6.generic.IFEQ;
import org.apache.commons.bcel6.generic.IFNONNULL;
import org.apache.commons.bcel6.generic.IfInstruction;
import org.apache.commons.bcel6.generic.Instruction;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionHandle;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.NOP;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.SCExcept;
@ -161,12 +177,28 @@ public class IfStmt extends Statement
return ret;
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
InstructionFactory _factory = _cg.getInstructionFactory();
InstructionList il = new InstructionList();
IfInstruction ifInstruction = new IFEQ(null);
il.append(expr.genByteCode(_cg));
//Anmerkung: expr ist vom Typ java.lang.Boolean (per Definition)
il.append(_factory.createInvoke("java.lang.Boolean", "booleanValue", org.apache.commons.bcel6.generic.Type.BOOLEAN, org.apache.commons.bcel6.generic.Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(ifInstruction);
il.append(then_block.genByteCode(_cg));
if(else_block != null && !(else_block instanceof EmptyStmt)){
GotoInstruction gotoInstruction = new GOTO(null);
il.append(gotoInstruction);
ifInstruction.setTarget(il.append(else_block.genByteCode(_cg)));
gotoInstruction.setTarget(il.append(new NOP()));
}else{
ifInstruction.setTarget(il.append(new NOP()));
}
return il;
}
}
// ino.end

View File

@ -7,11 +7,14 @@ import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.misc.UsedId;
@ -217,9 +220,9 @@ public class InstVar extends Expr
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}
}
// ino.end

View File

@ -6,11 +6,14 @@ import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
@ -116,9 +119,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}

View File

@ -13,6 +13,7 @@ import org.apache.commons.bcel6.generic.ObjectType;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.SCExcept;
@ -152,7 +153,13 @@ public class LocalOrFieldVar extends Expr
if(this.isFieldAccess){
il.append(cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), this.get_Name(), this.getType().getBytecodeType(cg), Constants.GETFIELD));
}
il.append(cg.getInstructionFactory().createLoad(this.getType().getBytecodeType(cg), this.get_Name()));
Type type = this.getType();
org.apache.commons.bcel6.generic.Type byteCodeType = type.getBytecodeType(cg);
String name = this.get_Name();
il.append(cg.getInstructionFactory().createLoad(byteCodeType, name));
return il;
}

View File

@ -10,6 +10,7 @@ import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.LDC2_W;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -128,15 +129,14 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public InstructionList genByteCode(ClassGen cg) {
ConstantPoolGen cp = cg.getConstantPool();
public InstructionList genByteCode(ClassGenerator _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;
}
}
// ino.end

View File

@ -6,11 +6,14 @@ import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.myexception.SCExcept;
import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
@ -109,9 +112,9 @@ public class NegativeExpr extends UnaryExpr
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}
}

View File

@ -9,6 +9,7 @@ import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -146,12 +147,11 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
public InstructionList genByteCode(ClassGenerator _cg) {
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
InstructionList il = new InstructionList();
il.append(expr.elementAt(0).genByteCode(cg));
il.append(expr.elementAt(0).genByteCode(_cg));
il.append(_factory.createNewArray( org.apache.commons.bcel6.generic.Type.getType(getTypeName()), (short)1));

View File

@ -7,11 +7,14 @@ import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.myexception.SCExcept;
import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
@ -204,9 +207,9 @@ public class NewClass extends Expr
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}

View File

@ -6,11 +6,14 @@ import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
@ -133,9 +136,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}
}

View File

@ -5,11 +5,14 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
@ -117,9 +120,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}
}

View File

@ -6,11 +6,14 @@ import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.myexception.SCExcept;
import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
@ -90,9 +93,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}
}

View File

@ -12,6 +12,7 @@ import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -100,9 +101,10 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
public static int counterPostInc = 0;
@Override
public InstructionList genByteCode(ClassGen cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
public InstructionList genByteCode(ClassGenerator _cg) {
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
InstructionList il = new InstructionList();
counterPostInc++;
il.append(new IINC(counterPostInc,1));

View File

@ -6,11 +6,14 @@ import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.myexception.SCExcept;
import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
@ -87,10 +90,11 @@ public class PreDecExpr extends UnaryExpr
ret.add(this.expr);
return ret;
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
@Override
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}
}

View File

@ -6,11 +6,14 @@ import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.NotImplementedException;
import de.dhbwstuttgart.myexception.SCExcept;
import de.dhbwstuttgart.myexception.SCStatementException;
import de.dhbwstuttgart.syntaxtree.Class;
@ -91,9 +94,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}
}

View File

@ -7,8 +7,10 @@ import java.util.Hashtable;
import java.util.Iterator;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -135,9 +137,9 @@ public class WhileStmt extends Statement
}
@Override
public void genByteCode(ClassGen _cg) {
// TODO Auto-generated method stub
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Bytecode
throw new NotImplementedException();
}
}
// ino.end

View File

@ -1,14 +1,14 @@
package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
public class FreshWildcardType extends Type {
public class FreshWildcardType extends ObjectType {
private static String strNextName = "A";
private Menge<Type> upperBounds = new Menge<Type>();
@ -170,4 +170,10 @@ public class FreshWildcardType extends Type {
public JavaCodeResult printJavaCode(ResultSet resultSet) {
throw new NotImplementedException();
}
@Override
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
// TODO: Bytecode
return null;
}
}

View File

@ -17,6 +17,7 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.GTVDeclarationContext;
@ -230,6 +231,12 @@ public class GenericTypeVar extends ObjectType
return this.getGTVDeclarationContext();
}
@Override
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
// TODO Bytecode
return null;
}
}
// ino.end

View File

@ -814,11 +814,27 @@ public class RefType extends ObjectType implements IMatchable
}
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
return new org.apache.commons.bcel6.generic.ObjectType(this.getTypeName());
return new org.apache.commons.bcel6.generic.ObjectType(this.get_Name());
}
@Override
public String getBytecodeSignature(ClassGenerator cg) {
/*
//Bsp.: Ljava/util/Vector<Ljava/lang/String;>;
StringBuilder sb = new StringBuilder();
sb.append(getTypeName());
if(parameter != null){
for(Type type: parameter){
sb.append(""); //TODO: einen geeignete Delemiter suchen
sb.append(type.getBytecodeSignature(cg));
}
}
return sb.toString();
*/
String paramString = "";
if(this.parameter != null && this.parameter.size()>0){
paramString+="<";

View File

@ -119,7 +119,7 @@ public class TypeinferenceResultSet
* Dabei wird die codegen-Methode der inferierten Klasse mit diesem ResultSet aufgerufen.
*/
public ByteCodeResult codegen(){
ByteCodeResult res = this.ownerOfResultSet.genByteCode(this);
ByteCodeResult res = this.ownerOfResultSet.genByteCode(this).firstElement();
return res;
}

View File

@ -0,0 +1,57 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import junit.framework.TestCase;
import org.junit.BeforeClass;
import org.junit.Test;
public abstract class BytecodeTest extends TestCase{
public String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public String testFile;
public String outputDirectory;
protected String testName;
public BytecodeTest(){
init();
if(testName != null){
testFile = testName+".jav";
outputDirectory = "";
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputDirectory);
}else{
throw new RuntimeException("rootDirectory, testFile or outputFile is null.");
}
}
protected abstract void init();
protected Class getClassToTest(){
Class classToTest = null;
try {
File file = new File(rootDirectory);
URL url = file.toURL();
URL[] urls = new URL[]{url};
ClassLoader classLoader = new URLClassLoader(urls);
classToTest = classLoader.loadClass(testName);
} catch (Exception e) {
throw new RuntimeException(e);
}
return classToTest;
}
}

View File

@ -0,0 +1,7 @@
class Condition{
Boolean method() {
return 0 == 1;
}
}

View File

@ -0,0 +1,34 @@
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 ConditionTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "Condition.jav";
public final static String outputFile = "Condition.class";
@Test
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -0,0 +1,7 @@
class IfElse{
method(){
for( i = 0; i < 10 ; i = i++){
}
}
}

View File

@ -0,0 +1,16 @@
package bytecode;
import org.junit.Ignore;
import org.junit.Test;
public class ForTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "ForTest.jav";
public final static String outputFile = "ForTest.class";
@Test
@Ignore
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -0,0 +1,9 @@
class IfElseStatement{
method(flag){
if(flag){
}else if(flag){
}
}
}

View File

@ -0,0 +1,14 @@
package bytecode;
import org.junit.Test;
public class IfElseIfStatementTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "IfElseIfStatement.jav";
public final static String outputFile = "IfElseIfStatement.class";
@Test
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -0,0 +1,9 @@
class IfElseStatement{
method(flag){
if(flag){
return 0;
}else{
return 1;
}
}
}

View File

@ -0,0 +1,14 @@
package bytecode;
import org.junit.Test;
public class IfElseStatementTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "IfElseStatement.jav";
public final static String outputFile = "IfElseStatement.class";
@Test
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -0,0 +1,7 @@
class IfStatement{
method(flag){
if(flag){
}
}
}

View File

@ -0,0 +1,14 @@
package bytecode;
import org.junit.Test;
public class IfStatementTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "IfStatement.jav";
public final static String outputFile = "IfStatement.class";
@Test
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -0,0 +1,9 @@
class IfTest{
public static void main(String[] args){
System.out.println(new IfElseStatement().method(true));
System.out.println(new IfElseStatement().method(false));
}
}

View File

@ -7,6 +7,7 @@ import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Ignore;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
@ -27,6 +28,7 @@ public class LambdaExpr2 {
public final static String outputFile = "LambdaExpr2.class";
@Test
@Ignore
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}

View File

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

View File

@ -0,0 +1,36 @@
package bytecode;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Ignore;
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 PostDecrement {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "PostDecrement.jav";
public final static String outputFile = "PostDecrement.class";
@Test
@Ignore
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -7,6 +7,7 @@ import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Ignore;
import org.junit.Test;
import plugindevelopment.TypeInsertTester;
@ -27,6 +28,7 @@ public class PostIncrement {
public final static String outputFile = "PostIncrement.class";
@Test
@Ignore
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}

View File

@ -3,29 +3,56 @@ package bytecode;
import java.io.File;
import java.io.IOException;
import org.apache.commons.bcel6.classfile.JavaClass;
import com.google.common.io.Files;
import junit.framework.TestCase;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.core.MyCompilerAPI;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.logger.Timewatch;
import de.dhbwstuttgart.parser.JavaParser.yyException;
import de.dhbwstuttgart.typeinference.ByteCodeResult;
import de.dhbwstuttgart.typeinference.Menge;
public class SingleClassTester {
public static void compileToBytecode(String inputFile, String outputFile){
public static void compileToBytecode(String inputFile, String outputDirectory){
LoggerConfiguration logConfig = new LoggerConfiguration().setOutput(Section.PARSER, System.out);
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(inputFile));
Menge<ByteCodeResult> bytecode = compiler.generateBytecode(compiler.typeReconstruction().firstElement());
System.out.println(bytecode);
bytecode.firstElement().getByteCode().getJavaClass().dump(new File(outputFile));
Menge<Menge<ByteCodeResult>> bytecode = compiler.generateBytecode(compiler.typeReconstruction().firstElement());
//System.out.println(bytecode);
for(ByteCodeResult result: bytecode.firstElement()){
JavaClass javaClass = result.getByteCode().getJavaClass();
Logger.getLogger("SingleClassTester").error(result.getByteCode().getJavaClass().toString(), Section.CODEGEN);
javaClass.dump(new File(outputDirectory+javaClass.getClassName()+".class"));
}
} catch (IOException | yyException e) {
Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN);
e.printStackTrace();
TestCase.fail();
}finally{
writeLog(outputDirectory+".log");
}
}
private static void writeLog(String toFile){
String log = Logger.getWholeLog()+"\n";
log+=Timewatch.getTimewatch().dumpTimeData();
try {
Files.write(log.getBytes(),new File(toFile));
} catch (IOException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,7 @@
class IfElse{
method(){
while(true){
}
}
}

View File

@ -0,0 +1,14 @@
package bytecode;
import org.junit.Test;
public class WhileTest {
public final static String rootDirectory = System.getProperty("user.dir")+"/test/bytecode/";
public final static String testFile = "WhileTest.jav";
public final static String outputFile = "WhileTest.class";
@Test
public void test() {
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -0,0 +1,3 @@
class ExtendsObject extends Object{
}

View File

@ -0,0 +1,48 @@
package bytecode.types;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Vector;
import junit.framework.TestCase;
import org.junit.Test;
import bytecode.BytecodeTest;
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 ExtendsObjectTest extends BytecodeTest{
@Override
protected void init() {
testName = "ExtendsObject";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void testConstruct(){
try{
Class cls = getClassToTest();
Constructor method = cls.getConstructor(new Class[]{});
method.newInstance();
assertTrue(true);
}catch(Exception e){
e.printStackTrace();
fail();
}
}
}

View File

@ -0,0 +1,5 @@
import java.util.Vector;
class ExtendsVector extends Vector<Object>{
}

View File

@ -0,0 +1,5 @@
import java.util.Vector;
class ExtendsVectorString extends Vector<String>{
}

View File

@ -0,0 +1,48 @@
package bytecode.types;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Vector;
import junit.framework.TestCase;
import org.junit.Test;
import bytecode.BytecodeTest;
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 ExtendsVectorStringTest extends BytecodeTest{
@Override
protected void init() {
testName = "ExtendsVectorString";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void testConstruct(){
try{
Class cls = getClassToTest();
Constructor method = cls.getConstructor(new Class[]{});
method.newInstance();
assertTrue(true);
}catch(Exception e){
e.printStackTrace();
fail();
}
}
}

View File

@ -0,0 +1,48 @@
package bytecode.types;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Vector;
import junit.framework.TestCase;
import org.junit.Test;
import bytecode.BytecodeTest;
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 ExtendsVectorTest extends BytecodeTest{
@Override
protected void init() {
testName = "ExtendsVector";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void testConstruct(){
try{
Class cls = getClassToTest();
Constructor method = cls.getConstructor(new Class[]{});
method.newInstance();
assertTrue(true);
}catch(Exception e){
e.printStackTrace();
fail();
}
}
}

View File

@ -0,0 +1,12 @@
import java.util.Vector;
class Overloading{
void method(Vector<String> v) {
}
void method(Vector<Integer> v) {
}
}

View File

@ -0,0 +1,59 @@
package bytecode.types;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import java.util.Vector;
import org.junit.Test;
import bytecode.BytecodeTest;
public class OverloadingTest extends BytecodeTest{
@Override
protected void init() {
testName = "Overloading";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void testString() {
try{
Class cls = getClassToTest();
Object obj = cls.newInstance();
Vector<String> stringVector = new Vector<String>();
Class[] params = new Class[1];
params[0] = stringVector.getClass();
Method method = cls.getDeclaredMethod("method", params);
method.invoke(obj, stringVector);
assertTrue(true);
}catch(Exception e){
e.printStackTrace();
fail();
}
}
@Test
public void testInteger() {
try{
Class cls = getClassToTest();
Object obj = cls.newInstance();
Vector<Integer> stringVector = new Vector<Integer>();
Class[] params = new Class[1];
params[0] = stringVector.getClass();
Method method = cls.getDeclaredMethod("method", params);
method.invoke(obj, stringVector);
assertTrue(true);
}catch(Exception e){
e.printStackTrace();
fail();
}
}
}

View File

@ -0,0 +1,7 @@
import java.util.Vector;
class TypedVector{
public void method(Vector<String> v) {
}
}

View File

@ -0,0 +1,41 @@
package bytecode.types;
import static org.junit.Assert.*;
import java.lang.reflect.Method;
import java.util.Stack;
import java.util.Vector;
import org.junit.Test;
import bytecode.BytecodeTest;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.Section;
public class TypedVectorTest extends BytecodeTest{
@Override
protected void init() {
testName = "TypedVector";
rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/";
}
@Test
public void test() {
try{
Class cls = getClassToTest();
Object obj = cls.newInstance();
Vector<String> stringVector = new Vector<String>();
Class[] params = new Class[1];
params[0] = stringVector.getClass();
Method method = cls.getDeclaredMethod("method", params);
method.invoke(obj, stringVector);
assertTrue(true);
}catch(Exception e){
Logger.getLogger("SingleClassTester").error(e.toString(), Section.CODEGEN);
fail();
}
}
}

View File

@ -0,0 +1,5 @@
class LambdaTest{
op = (m) -> (f) -> {f.apply(this,m); return this;};
}

View File

@ -0,0 +1,23 @@
package plugindevelopment.TypeInsertTests;
import de.dhbwstuttgart.typeinference.Menge;
import org.junit.Test;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.LoggerConfiguration;
import de.dhbwstuttgart.logger.Section;
public class LambdaTest2_3 {
private static final String TEST_FILE = "LambdaTest2_3.jav";
@Test
public void run(){
Menge<String> mustContain = new Menge<String>();
//mustContain.add("S m");
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain,
new LoggerConfiguration().setOutput(Section.ASSUMPTIONS, System.out));
}
}