Bytecode erweitert. BCEL6-SNAPSHOT eingebunden.

This commit is contained in:
JanUlrich 2015-09-02 17:11:32 +02:00
parent 64bed0c60d
commit ccd25ab865
85 changed files with 645 additions and 514 deletions

View File

@ -8,6 +8,7 @@
<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/guava-10.0.1.jar"/>
<classpathentry kind="lib" path="lib/bcel-6.0-SNAPSHOT.jar" sourcepath="lib/bcel-5.2-src.zip"/>
<classpathentry kind="lib" path="lib/commons-bcel6-6.0-SNAPSHOT.jar"/>
<classpathentry kind="lib" path="lib/bcel-6.0-SNAPSHOT.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@ -0,0 +1,11 @@
package bcelifier;
public class FieldDeclaration {
Integer field = methode();
Integer methode()
{
return field;
}
}

View File

@ -0,0 +1,68 @@
package bcelifier;
import org.apache.commons.bcel6.generic.*;
import org.apache.commons.bcel6.classfile.*;
import org.apache.commons.bcel6.*;
import java.io.*;
public class FieldDeclarationCreator implements Constants {
private InstructionFactory _factory;
private ConstantPoolGen _cp;
private ClassGen _cg;
public FieldDeclarationCreator() {
_cg = new ClassGen("bcelifier.FieldDeclaration", "java.lang.Object", "FieldDeclaration.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();
createMethod_1();
_cg.getJavaClass().dump(out);
}
private void createFields() {
FieldGen field;
field = new FieldGen(0, new ObjectType("java.lang.Integer"), "field", _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.FieldDeclaration", 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(_factory.createLoad(Type.OBJECT, 0));
il.append(_factory.createInvoke("bcelifier.FieldDeclaration", "methode", new ObjectType("java.lang.Integer"), Type.NO_ARGS, Constants.INVOKEVIRTUAL));
il.append(_factory.createFieldAccess("bcelifier.FieldDeclaration", "field", new ObjectType("java.lang.Integer"), Constants.PUTFIELD));
InstructionHandle ih_12 = il.append(_factory.createReturn(Type.VOID));
method.setMaxStack();
method.setMaxLocals();
_cg.addMethod(method.getMethod());
il.dispose();
}
private void createMethod_1() {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(0, new ObjectType("java.lang.Integer"), Type.NO_ARGS, new String[] { }, "methode", "bcelifier.FieldDeclaration", il, _cp);
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
il.append(_factory.createFieldAccess("bcelifier.FieldDeclaration", "field", new ObjectType("java.lang.Integer"), Constants.GETFIELD));
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.OBJECT));
method.setMaxStack();
method.setMaxLocals();
_cg.addMethod(method.getMethod());
il.dispose();
}
public static void main(String[] args) throws Exception {
bcelifier.FieldDeclarationCreator creator = new bcelifier.FieldDeclarationCreator();
creator.create(new FileOutputStream("bcelifier.FieldDeclaration.class"));
}
}

View File

@ -1,8 +1,8 @@
package bcelifier;
import org.apache.bcel.generic.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.*;
import org.apache.commons.bcel6.generic.*;
import org.apache.commons.bcel6.classfile.*;
import org.apache.commons.bcel6.*;
import java.io.*;
public class IntLiteralCreator implements Constants {

View File

@ -8,10 +8,10 @@ import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import org.apache.bcel.classfile.ClassFormatException;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.util.BCELifier;
import org.apache.commons.bcel6.classfile.ClassFormatException;
import org.apache.commons.bcel6.classfile.ClassParser;
import org.apache.commons.bcel6.classfile.JavaClass;
import org.apache.commons.bcel6.util.BCELifier;
public class JavaToBCEL {
@ -27,6 +27,8 @@ public class JavaToBCEL {
new BCELifier(new ClassParser(rootDirectory+"This.class").parse(), new FileOutputStream(new File(rootDirectory+"ThisCreator.java"))).start();
new BCELifier(new ClassParser(rootDirectory+"IntLiteral.class").parse(), new FileOutputStream(new File(rootDirectory+"IntLiteralCreator.java"))).start();
new BCELifier(new ClassParser(rootDirectory+"MethodCall.class").parse(), new FileOutputStream(new File(rootDirectory+"MethodCallCreator.java"))).start();
new BCELifier(new ClassParser(rootDirectory+"FieldDeclaration.class").parse(), new FileOutputStream(new File(rootDirectory+"FieldDeclarationCreator.java"))).start();
new BCELifier(new ClassParser(rootDirectory+"Null.class").parse(), new FileOutputStream(new File(rootDirectory+"NullCreator.java"))).start();
} catch (ClassFormatException | IOException e) {
e.printStackTrace();

View File

@ -1,8 +1,8 @@
package bcelifier;
import org.apache.bcel.generic.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.*;
import org.apache.commons.bcel6.generic.*;
import org.apache.commons.bcel6.classfile.*;
import org.apache.commons.bcel6.*;
import java.io.*;
public class Lambda1Creator implements Constants {

View File

@ -1,8 +1,8 @@
package bcelifier;
import org.apache.bcel.generic.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.*;
import org.apache.commons.bcel6.generic.*;
import org.apache.commons.bcel6.classfile.*;
import org.apache.commons.bcel6.*;
import java.io.*;
public class MethodCallCreator implements Constants {

7
BCEL/bcelifier/Null.java Normal file
View File

@ -0,0 +1,7 @@
package bcelifier;
public class Null {
Integer i = null;
}

View File

@ -0,0 +1,53 @@
package bcelifier;
import org.apache.commons.bcel6.generic.*;
import org.apache.commons.bcel6.classfile.*;
import org.apache.commons.bcel6.*;
import java.io.*;
public class NullCreator implements Constants {
private InstructionFactory _factory;
private ConstantPoolGen _cp;
private ClassGen _cg;
public NullCreator() {
_cg = new ClassGen("bcelifier.Null", "java.lang.Object", "Null.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.Integer"), "i", _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.Null", 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(InstructionConstants.ACONST_NULL);
il.append(_factory.createFieldAccess("bcelifier.Null", "i", new ObjectType("java.lang.Integer"), Constants.PUTFIELD));
InstructionHandle ih_9 = 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.NullCreator creator = new bcelifier.NullCreator();
creator.create(new FileOutputStream("bcelifier.Null.class"));
}
}

View File

@ -1,8 +1,8 @@
package bcelifier;
import org.apache.bcel.generic.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.*;
import org.apache.commons.bcel6.generic.*;
import org.apache.commons.bcel6.classfile.*;
import org.apache.commons.bcel6.*;
import java.io.*;
public class ThisCreator implements Constants {

Binary file not shown.

View File

@ -0,0 +1,30 @@
package de.dhbwstuttgart.bytecode;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
public class ClassGenerator extends ClassGen{
private DHBWInstructionFactory factory = new DHBWInstructionFactory(this, this.getConstantPool());
private TypeinferenceResultSet tiResult;
public ClassGenerator(String name, String get_Name, String string,
short accPublic, String[] strings, TypeinferenceResultSet resultSet) {
super(name,get_Name,string,accPublic,strings);
this.tiResult = resultSet;
}
public DHBWInstructionFactory getInstructionFactory() {
return factory ;
}
public Type resolveTPH(TypePlaceholder typePlaceholder) {
return tiResult.getTypeOfPlaceholder(typePlaceholder);
}
}

View File

@ -3,15 +3,17 @@ package de.dhbwstuttgart.bytecode;
import java.awt.List;
import java.util.ArrayList;
import org.apache.bcel.classfile.BootstrapMethod;
import org.apache.bcel.classfile.ConstantInvokeDynamic;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.INVOKEDYNAMIC;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.MethodGen;
import org.apache.bcel.generic.Type;
import org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.classfile.BootstrapMethod;
import org.apache.commons.bcel6.classfile.ConstantInvokeDynamic;
import org.apache.commons.bcel6.classfile.InnerClass;
import org.apache.commons.bcel6.classfile.Method;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
import org.apache.commons.bcel6.generic.INVOKEDYNAMIC;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.MethodGen;
import org.apache.commons.bcel6.generic.Type;
public class DHBWInstructionFactory extends InstructionFactory{
@ -26,11 +28,39 @@ public class DHBWInstructionFactory extends InstructionFactory{
public INVOKEDYNAMIC createInvokeDynamic( MethodGen lambdaMethod ) {
//Zuerst die Bootstrap-Methode erstellen: Diese müssen dann in ein BootstrapMethods-Attribut zusammengefasst und dem Classfile hinzugefügt werden
int lambdaMethodIndex = this.cp.addMethodref(lambdaMethod);
//this.cp.addMethodref(lambdaMethod);
ArrayList arguments = new ArrayList<Integer>();
ArrayList<Integer> arguments = new ArrayList<Integer>();
/*
* Die Argumente für die Bootstrap-Methode. Im Decompilierten Beispiel sind das:
* #19 ()V
* #20 invokespecial Lambda3.lambda$methode$0:()V
* #19 ()V
*
* #20 ist ein MethodHandle_info Structure
* TODO: Rausfinden, was es mit den Argumenten auf sich hat:
* -> Das sind Informationen die die Lambda Funktion zum Ausführen benötigt. (This-Referenz, Variablen, welche vom Lambda Ausdruck benutzt werden)
* Anmerkung: Bei der momentanen Implementierung der Lambda Ausdrücke wird nur this übergeben.
*/
BootstrapMethod bMethod = new BootstrapMethod(lambdaMethodIndex, arguments.size(), (int[])arguments.toArray());
int innerClassIndex = cp.addClass("java.lang.invoke.MethodHandles$Lookup");
int innerClassName = cp.addUtf8("Lookup");
int outerClassIndex = cp.addClass("java.lang.invoke.MethodHandles");
int accessFlags = Constants.ACC_FINAL + Constants.ACC_STATIC + Constants.ACC_PUBLIC;
InnerClass innerClassAttribute = new InnerClass(innerClassIndex, outerClassIndex, innerClassName,accessFlags);
//Diese InnereKlasse muss später im ClassFile vorkommen, da sie von der Bootstrap Methode benutzt wird.
//TODO: Dies kann man möglicherweise auslagern. Die ClassGen Klasse erweiter, welche sich dann die InnerenKlassen mertk, welche gebraucht werden
String bootstrapSignature = "(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;";
int lambdaMethodIndex = cp.addMethodref("java.lang.invoke.LambdaMetafactory", "metafactory", bootstrapSignature);
int[] argumentsArray = new int[arguments.size()];
for(int i = 0; i<arguments.size();i++){
argumentsArray[i] = arguments.get(i);
}
BootstrapMethod bMethod = new BootstrapMethod(lambdaMethodIndex, arguments.size(), argumentsArray);
final short opcode = 186;
int index;
@ -68,13 +98,14 @@ public class DHBWInstructionFactory extends InstructionFactory{
*/
int bootstrap_method_attr_index = bMethod.getBootstrapMethodRef();
//TODO: der Typ der Lambda Methode muss den Typ von this als erstes Argument enthalten, damit this innerhalb der Lambda Methode verwendet werden kann
int name_and_type_index = cp.addNameAndType(lambdaMethod.getName(), lambdaMethod.getType().getSignature());
ConstantInvokeDynamic cInvokeDynamic = new ConstantInvokeDynamic(bootstrap_method_attr_index, name_and_type_index);
index = cp.addConstant(cInvokeDynamic, cp);
return new INVOKEDYNAMIC(opcode, index);
return new INVOKEDYNAMIC(index);
}
}

View File

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

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();
public Menge<ByteCodeResult> generateBytecode(TypeinferenceResultSet rs);
}
// ino.end

View File

@ -8,17 +8,18 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionHandle;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.MethodGen;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
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.MethodGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.logger.Section;
import de.dhbwstuttgart.logger.SectionLogger;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.AClassOrInterface;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.parser.JavaClassName;
@ -44,9 +45,9 @@ import de.dhbwstuttgart.typeinference.typedeployment.TypeInsertPoint;
import de.dhbwstuttgart.typeinference.unify.FC_TTO;
import de.dhbwstuttgart.typeinference.unify.Unify;
import org.apache.bcel.generic.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.*;
import org.apache.commons.bcel6.generic.*;
import org.apache.commons.bcel6.classfile.*;
import org.apache.commons.bcel6.*;
import java.io.*;
@ -66,25 +67,47 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
protected UsedId pkgName;
protected Modifiers modifiers;
protected String name;
//For ByteCode Construction
private InstructionFactory _factory;
private ConstantPoolGen _cp;
private ClassGen _cg;
//Method created with BCEL to generate ByteCode
public ByteCodeResult genByteCode() {
/**
*
* @param resultSet - Fehlende Typen im Syntaxbaum werden nach diesem ResultSet aufgelöst
* @return
*/
public ByteCodeResult genByteCode(TypeinferenceResultSet resultSet) {
InstructionFactory _factory;
ConstantPoolGen _cp;
ClassGenerator _cg;
SectionLogger logger = Logger.getSectionLogger(this.getClass().getName(), Section.CODEGEN);
logger.debug("Test");
if(pkgName != null)throw new NotImplementedException();
_cg = new ClassGen(name, superClass.get_Name(), name + ".java", Constants.ACC_PUBLIC , new String[] { }); //letzter Parameter sind implementierte Interfaces
_cg = new ClassGenerator(name, superClass.get_Name(), name + ".java", Constants.ACC_PUBLIC , new String[] { }, resultSet); //letzter Parameter sind implementierte Interfaces
_cp = _cg.getConstantPool();
_factory = new InstructionFactory(_cg, _cp);
//Die Felder in Methoden Felder und Konstruktoren aufteilen:
Menge<FieldDeclaration> fieldDeclarations = new Menge<>();
Menge<Constructor> constructors = new Menge<>();
Menge<Method> methods = new Menge<>();
for(Field field : this.fielddecl){
field.genByteCode(_cg);
if(field instanceof Constructor)constructors.add((Constructor)field);
if(field instanceof Method && ! (field instanceof Constructor))methods.add((Method)field);
if(field instanceof FieldDeclaration)fieldDeclarations.add((FieldDeclaration)field);
//field.genByteCode(_cg);
}
//Zuerst die Methoden und Felder abarbeiten:
for(Method m : methods){
m.genByteCode(_cg);
}
InstructionList fieldInitializations = new InstructionList();
for(FieldDeclaration f : fieldDeclarations){
fieldInitializations.append(f.genByteCode(_cg));
}
//Die Konstruktoren müssen die Feld initialisierungswerte beinhalten:
for(Constructor c : constructors){
c.genByteCode(_cg, fieldInitializations);
}
ByteCodeResult code = new ByteCodeResult(_cg);
return code;

View File

@ -1,15 +1,16 @@
package de.dhbwstuttgart.syntaxtree;
import org.apache.bcel.Constants;
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.InstructionHandle;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.MethodGen;
import org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.classfile.ConstantPool;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
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.MethodGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
@ -55,18 +56,20 @@ public class Constructor extends Method {
return ret;
}
@Override
public void genByteCode(ClassGen cg) {
public void genByteCode(ClassGenerator cg, InstructionList fieldInitializations){
ConstantPoolGen _cp = cg.getConstantPool();
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
Class parentClass = this.getParentClass();
//TODO: Alles dynamisch gestalten
//init darf nur drin stehen, wenn Konstruktor;
this.method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), org.apache.bcel.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
this.method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg), org.apache.commons.bcel6.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
//Iteration <EFBFBD>ber Block starten
Block block = this.get_Block();
if(block.statements.firstElement() instanceof SuperCall){
block.statements.insertElementAt(new BytecodeInstructionBlock(fieldInitializations), 1);
}
InstructionList blockInstructions = block.genByteCode(cg);
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
@ -75,6 +78,26 @@ public class Constructor extends Method {
cg.addMethod(this.method.getMethod());
}
/**
* Mit dieser Hilfsklasse kann eine beliebige InstructionList in eine vorhandenen Block als Statement eingefügt werden.
* Wird für Bytecodegenerierung benötigt.
*/
private class BytecodeInstructionBlock extends Block{
InstructionList il;
BytecodeInstructionBlock(InstructionList toInsert){
il = toInsert;
}
@Override
public InstructionList genByteCode(ClassGenerator cg){
return il;
}
}
@Override
public void genByteCode(ClassGenerator cg) {
this.genByteCode(cg, new InstructionList());
}
// super statement muss drin sein
// stmt genByteCode + im block genByteCode implementieren & dann Hierarchie ausprobieren
// de.dhbw.systanxtree.stmts supercall

View File

@ -1,8 +1,9 @@
package de.dhbwstuttgart.syntaxtree;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
@ -173,10 +174,5 @@ public abstract class Field extends GTVDeclarationContext implements TypeInserta
return false;
}
/**
* F<EFBFBD>gt das das Feld zu ClassGen hinzu
* @param cg
*/
public abstract void genByteCode(ClassGen cg);
}

View File

@ -1,11 +1,18 @@
package de.dhbwstuttgart.syntaxtree;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.Constants;
import org.apache.commons.bcel6.generic.FieldGen;
import org.apache.commons.bcel6.generic.FieldInstruction;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.ObjectType;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.misc.DeclId;
import de.dhbwstuttgart.syntaxtree.statement.Expr;
import de.dhbwstuttgart.syntaxtree.statement.This;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.Type;
@ -157,10 +164,26 @@ public class FieldDeclaration extends Field{
if(this.getWert()!=null)this.getWert().wandleRefTypeAttributes2GenericAttributes(paralist, new Menge<GenericTypeVar>()); //FieldDeclaration hat keine Generischen Variablen, daher leere Liste übergeben
}
@Override
public void genByteCode(ClassGen cg) {
// TODO Auto-generated method stub
/**
* Das besondere bei genByteCode einer FieldDeclaration ist, dass ein InstructionList zurückgegeben wird.
* Dieser muss in jeden Konstruktor eingefügt werden um das Feld zu initialisieren.
* @param cg
* @return - Die InstructionList, welche das Feld initialisiert
*/
public InstructionList genByteCode(ClassGenerator cg) {
//Das Feld an die Klasse anfügen:
FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg), this.getDescription(), cg.getConstantPool());
cg.addField(field.getField());
//Die Felddekleration an den Konstruktor anhängen:
InstructionList il = new InstructionList();
il.append(new This(this).genByteCode(cg));
il.append(this.wert.genByteCode(cg));
FieldInstruction putFieldInstruction =
cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(),
this.getDescription(), this.getType().getBytecodeType(cg), Constants.PUTFIELD);
il.append(putFieldInstruction );
return il;
}
/*@Override

View File

@ -7,16 +7,17 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.Constants;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionHandle;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.MethodGen;
import org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
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.MethodGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -739,39 +740,38 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
return super.equals(obj);
}
@Override
public void genByteCode(ClassGen cg) {
public void genByteCode(ClassGenerator cg) {
ConstantPoolGen _cp = cg.getConstantPool();
InstructionFactory _factory = new InstructionFactory(cg, _cp);
InstructionList il = new InstructionList();
Class parentClass = this.getParentClass();
//Die Argumentliste generieren:
org.apache.bcel.generic.Type[] argumentTypes = org.apache.bcel.generic.Type.NO_ARGS;
org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.generic.Type.NO_ARGS;
String[] argumentNames = new String[]{};
if(this.parameterlist != null &&
this.parameterlist.size() > 0){
argumentTypes = new org.apache.bcel.generic.Type[this.parameterlist.size()];
argumentTypes = new org.apache.commons.bcel6.generic.Type[this.parameterlist.size()];
argumentNames = new String[this.parameterlist.size()];
int i = 0;
for(FormalParameter parameter : this.parameterlist){
argumentTypes[i] = parameter.getType().getBytecodeType();
argumentTypes[i] = parameter.getType().getBytecodeType(cg);
argumentNames[i] = parameter.getIdentifier();
i++;
}
}
//Methode generieren:
MethodGen method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
MethodGen method = new MethodGen(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
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)); }
if (block.get_Statement().size() == 0) { il.append(_factory.createReturn( org.apache.commons.bcel6.generic.Type.VOID)); }
else {
if (!(block.get_Statement().lastElement() instanceof Return)) { il.append(_factory.createReturn(org.apache.bcel.generic.Type.VOID)); }
if (!(block.get_Statement().lastElement() instanceof Return)) { il.append(_factory.createReturn( org.apache.commons.bcel6.generic.Type.VOID)); }
}
method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)

View File

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

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.syntaxtree;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.core.IItemWithOffset;

View File

@ -6,16 +6,17 @@ 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 org.apache.commons.bcel6.generic.ASTORE;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.DSTORE;
import org.apache.commons.bcel6.generic.FSTORE;
import org.apache.commons.bcel6.generic.ISTORE;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.LSTORE;
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;
@ -178,13 +179,15 @@ public class Assign extends Expr
public static int counterAssign = 0; //Zaehlvariable f<EFBFBD>r ISTORE
@Override
public InstructionList genByteCode(ClassGen cg, TypeAssumptions ass) {
public InstructionList genByteCode(ClassGenerator cg) {
// TODO Auto-generated method stub
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = expr2.genByteCode(cg, ass);//expr2 rechte expr
InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr
//TODO: ^^
counterAssign++; //macht STORE f<EFBFBD>r meherere Variable nutzbar (nicht nur ISTORE_1, ISTORE_2, etc.)
/*
String expr2Type = expr2.getType().get_Name().toString();
switch(expr2Type){
case "java.lang.Integer":
@ -207,6 +210,9 @@ public class Assign extends Expr
il.append(new LSTORE(counterAssign));
break;
}
*/
//Es wird momentan immer von RefType ausgegangen:
il.append(new ASTORE(counterAssign));
return il;
}

View File

@ -6,8 +6,8 @@ import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionList;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -6,15 +6,16 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.Constants;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.ConstantPoolGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionHandle;
import org.apache.bcel.generic.InstructionList;
import org.apache.bcel.generic.MethodGen;
import org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
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.MethodGen;
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;
@ -255,7 +256,7 @@ public class Block extends Statement
}
@Override
public InstructionList genByteCode(ClassGen cg) {
public InstructionList genByteCode(ClassGenerator cg) {
//ConstantPoolGen _cp = cg.getConstantPool();
InstructionList il = new InstructionList();

View File

@ -4,9 +4,9 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.BoolLiteral.8626.import
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -4,10 +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 org.apache.commons.bcel6.generic.BIPUSH;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -4,13 +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 org.apache.commons.bcel6.generic.BIPUSH;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.LDC;
import org.apache.commons.bcel6.generic.LDC2_W;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.EmptyStmt.8629.import
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -5,8 +5,8 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionList;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;

View File

@ -4,11 +4,11 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.IntLiteral.8635.import
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 org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.LDC;
import org.apache.commons.bcel6.generic.LDC2_W;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -4,7 +4,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -6,7 +6,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -6,7 +6,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -4,16 +4,17 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.IntLiteral.8635.import
import java.util.Hashtable;
import org.apache.bcel.Constants;
import org.apache.bcel.generic.BIPUSH;
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 org.apache.bcel.generic.ObjectType;
import org.apache.bcel.generic.PUSH;
import org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.generic.BIPUSH;
import org.apache.commons.bcel6.generic.ClassGen;
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.ObjectType;
import org.apache.commons.bcel6.generic.PUSH;
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;
@ -138,7 +139,7 @@ public class IntLiteral extends Literal
}
@Override
public InstructionList genByteCode(ClassGen cg) {
public InstructionList genByteCode(ClassGenerator cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
@ -146,7 +147,7 @@ public class IntLiteral extends Literal
* Der jetzige Compiler kann keine primitiven Typen. Ein int-Literal ist daher eine Instanz von java.lang.Integer
*/
il.append(new PUSH(cg.getConstantPool(), this.get_Int()));
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.bcel.generic.Type[] { org.apache.bcel.generic.Type.INT }, Constants.INVOKESTATIC));
il.append(_factory.createInvoke("java.lang.Integer", "valueOf", new ObjectType("java.lang.Integer"), new org.apache.commons.bcel6.generic.Type[] { org.apache.commons.bcel6.generic.Type.INT }, Constants.INVOKESTATIC));
return il;
}

View File

@ -2,16 +2,17 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import org.apache.bcel.classfile.BootstrapMethod;
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 org.apache.commons.bcel6.classfile.BootstrapMethod;
import org.apache.commons.bcel6.classfile.ConstantPool;
import org.apache.commons.bcel6.generic.BIPUSH;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.INVOKEDYNAMIC;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.SCStatementException;
@ -225,7 +226,7 @@ public class LambdaExpression extends Expr{
}
@Override
public InstructionList genByteCode(ClassGen cg) {
public InstructionList genByteCode(ClassGenerator cg) {
ConstantPoolGen cp = cg.getConstantPool();
InstructionList il = new InstructionList();

View File

@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -5,11 +5,12 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Enumeration;
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionList;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.myexception.JVMCodeException;
import de.dhbwstuttgart.myexception.SCExcept;
@ -428,7 +429,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
}
@Override
public InstructionList genByteCode(ClassGen _cg) {
public InstructionList genByteCode(ClassGenerator _cg) {
// TODO Auto-generated method stub
return new InstructionList();
}

View File

@ -4,10 +4,10 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.IntLiteral.8635.import
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 org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.LDC2_W;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -4,13 +4,14 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.MethodCall.8639.import
import java.util.Hashtable;
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 org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionHandle;
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.JVMCodeException;
import de.dhbwstuttgart.syntaxtree.Method;
@ -313,11 +314,11 @@ public class MethodCall extends Expr
*/
@Override
public InstructionList genByteCode(ClassGen _cg) {
public InstructionList genByteCode(ClassGenerator cg) {
InstructionList il = new InstructionList();
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
il.append(receiver.get_Expr().genByteCode(_cg));
il.append(receiver.get_Expr().genByteCode(cg));
//Herausfinden, ob eine Methode oder ein Interface aufgerufen wird:
Type receiverType = this.receiver.get_Expr().getType();
@ -329,19 +330,19 @@ public class MethodCall extends Expr
kind = Constants.INVOKEVIRTUAL;
}
org.apache.bcel.generic.Type[] argumentTypen = org.apache.bcel.generic.Type.NO_ARGS;
org.apache.commons.bcel6.generic.Type[] argumentTypen = org.apache.commons.bcel6.generic.Type.NO_ARGS;
if(this.getArgumentList() != null && this.getArgumentList().size()>0){
argumentTypen = new org.apache.bcel.generic.Type[this.getArgumentList().size()];
argumentTypen = new org.apache.commons.bcel6.generic.Type[this.getArgumentList().size()];
int i = 0;
for(Expr argument : this.arglist.expr){
argumentTypen[i] = argument.getType().getBytecodeType();
argumentTypen[i] = argument.getType().getBytecodeType(cg);
//Das Argument auf den Stack legen:
il.append(argument.genByteCode(_cg));
il.append(argument.genByteCode(cg));
i++;
}
}
org.apache.bcel.generic.Type returnType = this.getType().getBytecodeType();
org.apache.commons.bcel6.generic.Type returnType = this.getType().getBytecodeType(cg);
il.append(_factory.createInvoke(receiver.getReceiverClass().getName().toString(), this.get_Name(), returnType , argumentTypen, kind));
return il;
}

View File

@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -4,9 +4,9 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.NewArray.8641.import
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -152,7 +152,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
InstructionList il = new InstructionList();
il.append(expr.elementAt(0).genByteCode(cg));
il.append(_factory.createNewArray(org.apache.bcel.generic.Type.getType(getTypeName()), (short)1));
il.append(_factory.createNewArray( org.apache.commons.bcel6.generic.Type.getType(getTypeName()), (short)1));
return il;

View File

@ -6,7 +6,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -4,11 +4,13 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.Null.8644.import
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.bcel.generic.InstructionFactory;
import org.apache.bcel.generic.InstructionList;
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;
@ -93,11 +95,11 @@ public class Null extends Literal
}
@Override
public InstructionList genByteCode(ClassGen cg) {
public InstructionList genByteCode(ClassGenerator cg) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList();
il.append(_factory.ACONST_NULL);
il.append(InstructionConstants.ACONST_NULL);
return il;

View File

@ -4,7 +4,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.PositivExpr.8645.import
import java.util.Hashtable;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -5,11 +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 org.apache.commons.bcel6.generic.BIPUSH;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.IINC;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
@ -106,9 +106,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
InstructionList il = new InstructionList();
counterPostInc++;
il.append(new IINC(counterPostInc,1));
//Tests aufgrund fehlener TypInferenz-Funktionalität nicht 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
//Tests aufgrund fehlener TypInferenz-Funktionalit<EFBFBD>t nicht m<EFBFBD>glich
//Vermutlich muss der Counter noch angepasst werden, da nicht incrementierende Variablen nicht mitgez<EFBFBD>hlt werden, und zu falschen aufrufen f<EFBFBD>hren
//Gibt es einen Compiler-internen Variablenindex, der den Counter effektiver ersetzen k<EFBFBD>nnte
return il;
}

View File

@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -5,7 +5,7 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -4,12 +4,13 @@ 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 org.apache.commons.bcel6.generic.ConstantPoolGen;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.ClassGen;
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;
@ -133,12 +134,13 @@ public class Return extends Statement
}
@Override
public InstructionList genByteCode(ClassGen cg) {
public InstructionList genByteCode(ClassGenerator cg) {
InstructionList il = retexpr.genByteCode(cg);
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
il.append(_factory.createReturn(retexpr.getType().getBytecodeType()));
org.apache.commons.bcel6.generic.Type retType = this.getReturnType().getBytecodeType(cg);//retexpr.getType().getBytecodeType();
il.append(_factory.createReturn(retType ));
return il;
}

View File

@ -5,12 +5,13 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.Enumeration;
import java.util.Hashtable;
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.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
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.core.IItemWithOffset;
import de.dhbwstuttgart.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -129,7 +130,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
}
public abstract InstructionList genByteCode(ClassGen _cg);
public abstract InstructionList genByteCode(ClassGenerator _cg);
}

View File

@ -6,18 +6,20 @@ 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 org.apache.commons.bcel6.classfile.ConstantPool;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.ConstantPoolGen;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionList;
import org.apache.commons.bcel6.generic.LDC;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
@ -121,7 +123,7 @@ public class StringLiteral extends Literal
}
//public static int counterString = 0;
@Override
public InstructionList genByteCode(ClassGen cg) {
public InstructionList genByteCode(ClassGenerator cg) {
ConstantPoolGen cp = cg.getConstantPool();
InstructionFactory _factory = new InstructionFactory(cg, cp);
InstructionList il = new InstructionList();

View File

@ -4,13 +4,14 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.This.8654.import
import java.util.Hashtable;
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 org.apache.commons.bcel6.Constants;
import org.apache.commons.bcel6.generic.ClassGen;
import org.apache.commons.bcel6.generic.InstructionFactory;
import org.apache.commons.bcel6.generic.InstructionHandle;
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;
@ -91,14 +92,14 @@ public class SuperCall extends ThisCall
}
@Override
public InstructionList genByteCode(ClassGen cg) {
public InstructionList genByteCode(ClassGenerator 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));
InstructionHandle ih_0 = il.append(_factory.createLoad( org.apache.commons.bcel6.generic.Type.OBJECT, 0));
il.append(_factory.createInvoke(superClass.getName().toString(), "<init>", org.apache.commons.bcel6.generic.Type.VOID, org.apache.commons.bcel6.generic.Type.NO_ARGS, Constants.INVOKESPECIAL));
InstructionHandle ih_4 = il.append(_factory.createReturn( org.apache.commons.bcel6.generic.Type.VOID));
return il;
}

View File

@ -4,14 +4,15 @@ package de.dhbwstuttgart.syntaxtree.statement;
// ino.module.This.8654.import
import java.util.Hashtable;
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 org.apache.bcel.generic.MethodGen;
import org.apache.bcel.generic.ObjectType;
import org.apache.commons.bcel6.generic.ClassGen;
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.MethodGen;
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.myexception.CTypeReconstructionException;
import de.dhbwstuttgart.myexception.JVMCodeException;
@ -148,9 +149,9 @@ public class This extends Expr
}
@Override
public InstructionList genByteCode(ClassGen _cg) {
public InstructionList genByteCode(ClassGenerator _cg) {
InstructionList il = new InstructionList();
InstructionHandle ih_0 = il.append(InstructionFactory.createLoad(org.apache.bcel.generic.Type.OBJECT, 0));
il.append(InstructionFactory.createLoad( org.apache.commons.bcel6.generic.Type.OBJECT, 0));
return il;
}

View File

@ -6,7 +6,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;

View File

@ -9,6 +9,7 @@ import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.Logger;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.myexception.SCException;
import de.dhbwstuttgart.parser.JavaClassName;
@ -812,8 +813,8 @@ public class RefType extends ObjectType implements IMatchable
}
}
public org.apache.bcel.generic.Type getBytecodeType() {
return new org.apache.bcel.generic.ObjectType(this.getTypeName());
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
return new org.apache.commons.bcel6.generic.ObjectType(this.getTypeName());
}
}

View File

@ -3,8 +3,9 @@ package de.dhbwstuttgart.syntaxtree.type;
// ino.end
// ino.module.Type.8677.import
import java.util.ArrayList;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
@ -304,7 +305,7 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
return this;
}
public abstract org.apache.bcel.generic.Type getBytecodeType();
public abstract org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg);
}
// ino.end

View File

@ -5,9 +5,10 @@ package de.dhbwstuttgart.syntaxtree.type;
// ino.module.TypePlaceholder.8678.import
import java.util.Hashtable;
import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.logger.*;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.MyCompiler;
import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
@ -15,6 +16,8 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable;
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.typeinference.typedeployment.TypeInsertSet;
// ino.class.TypePlaceholder.26780.description type=javadoc
@ -425,6 +428,14 @@ public class TypePlaceholder extends ObjectType
}
return ret;
}
@Override
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
//throw new TypeinferenceException("Zuerst alle Typen einsetzen vor dem Kompiliervorgang",this);
Type resolvedType = cg.resolveTPH(this);
if(resolvedType instanceof TypePlaceholder)throw new DebugException("Kann TypePlaceholder nicht auflösen");
return resolvedType.getBytecodeType(cg);
}
}
// ino.end

View File

@ -1,6 +1,7 @@
// ino.module.Void.8679.package
package de.dhbwstuttgart.syntaxtree.type;
import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
@ -80,8 +81,8 @@ public class Void extends RefType
}
@Override
public org.apache.bcel.generic.Type getBytecodeType() {
return org.apache.bcel.generic.Type.VOID;
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) {
return org.apache.commons.bcel6.generic.Type.VOID;
}
}

View File

@ -1,6 +1,6 @@
package de.dhbwstuttgart.typeinference;
import org.apache.bcel.generic.ClassGen;
import org.apache.commons.bcel6.generic.ClassGen;
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;

View File

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

View File

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

View File

@ -1,45 +0,0 @@
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

@ -0,0 +1,8 @@
class FieldDeclaration{
Integer integer = 20;
FieldDeclaration field = methode();
FieldDeclaration methode(){
return this;
}
}

View File

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

View File

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

View File

@ -1,45 +0,0 @@
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

@ -28,18 +28,7 @@ public class LambdaExpr {
@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();
}
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

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

View File

@ -1,45 +0,0 @@
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

@ -28,18 +28,7 @@ public class MethodEmpty {
@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();
}
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -28,18 +28,7 @@ public class MethodEmptyRetType {
@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();
}
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -1,45 +0,0 @@
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

@ -28,18 +28,7 @@ public class PostIncrement {
@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();
}
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -19,8 +19,7 @@ public class SingleClassTester {
MyCompilerAPI compiler = MyCompiler.getAPI(logConfig);
try {
compiler.parse(new File(inputFile));
compiler.typeReconstruction();
Menge<ByteCodeResult> bytecode = compiler.generateBytecode();
Menge<ByteCodeResult> bytecode = compiler.generateBytecode(compiler.typeReconstruction().firstElement());
System.out.println(bytecode);
bytecode.firstElement().getByteCode().getJavaClass().dump(new File(outputFile));
} catch (IOException | yyException e) {

View File

@ -28,18 +28,7 @@ public class StringLitTest {
@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();
}
SingleClassTester.compileToBytecode(rootDirectory+testFile, rootDirectory+outputFile);
}
}

View File

@ -7,5 +7,6 @@ public static void main(String[] args){
new Assign();
System.out.println(new Return().method());
new MethodCall().method();
System.out.println(new FieldDeclaration().field);
}
}

View File

@ -0,0 +1,3 @@
LambdaTest5:
* Zeit ohne Unify-Filterung: 729601
* Zeit mit Unify-Filterung: 95235

View File

@ -0,0 +1,13 @@
class Klasse1 {
void methode(){
var;
var = this;
var = new Klasse2();
}
}
class Klasse2 extends Klasse1{
}

View File

@ -0,0 +1,19 @@
package plugindevelopment.TypeInsertTests;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.typeinference.Menge;
import org.junit.Test;
public class UnifyPaper {
private static final String TEST_FILE = "UnifyPaper.jav";
@Test
public void run(){
Menge<String> mustContain = new Menge<String>();
//mustContain.add("TestIfStmt var");
MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain);
ArrayList l = new ArrayList();
}
}

View File

@ -0,0 +1,13 @@
import java.util.Vector;
class Klasse1 {
void methode(){
var;
var = new Vector<Klasse2>();
var = new Vector<Klasse1>();
}
}
class Klasse2 extends Klasse1{
}

View File

@ -0,0 +1,19 @@
package plugindevelopment.TypeInsertTests;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.typeinference.Menge;
import org.junit.Test;
public class UnifyPaper2 {
private static final String TEST_FILE = "UnifyPaper2.jav";
@Test
public void run(){
Menge<String> mustContain = new Menge<String>();
//mustContain.add("TestIfStmt var");
MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain);
ArrayList l = new ArrayList();
}
}