TypeinferenceResultSet von ClassGenerator getrennt

This commit is contained in:
Enrico Schrödter 2015-11-27 16:10:35 +01:00
parent 8ae7bda535
commit dd478961e2
57 changed files with 195 additions and 219 deletions

View File

@ -62,22 +62,13 @@ public class ClassGenerator extends ClassGen{
//return getNearestType((TypePlaceholder) t); //return getNearestType((TypePlaceholder) t);
return new TypePlaceholderType((TypePlaceholder) t); return new TypePlaceholderType((TypePlaceholder) t);
}else{ }else{
return t.getBytecodeType(this); return t.getBytecodeType(this, getTypeinferenceResults().getTypeReconstructions().firstElement());
} }
} }
public org.apache.commons.bcel6.generic.Type getNearestUsedType(TypePlaceholder toTPH){ public org.apache.commons.bcel6.generic.Type getNearestUsedType(TypePlaceholder toTPH){
return this.getNearestUsedType(toTPH, null); return this.getNearestUsedType(toTPH, null);
} }
public Type resolveTPH(TypePlaceholder typePlaceholder) {
return resolveTPH(typePlaceholder, null);
}
public Type resolveTPH(TypePlaceholder typePlaceholder, Menge<TypePlaceholder> toOneOfTheseTypes) {
return tiResult.getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes);
}
public String createLambdaMethodName() { public String createLambdaMethodName() {
return "lambda$methode$"+(lambdaMethodeNr++); return "lambda$methode$"+(lambdaMethodeNr++);
} }
@ -135,7 +126,7 @@ public class ClassGenerator extends ClassGen{
//Signatur setzen: //Signatur setzen:
String typeParameters = this.generateParameterSignature(); String typeParameters = this.generateParameterSignature();
String superClassSignature = this.superClass.getBytecodeSignature(this); String superClassSignature = this.superClass.getBytecodeSignature(this, getTypeinferenceResults().getTypeReconstructions().firstElement());
String classSignature = typeParameters + superClassSignature; String classSignature = typeParameters + superClassSignature;
if(classSignature.length()>0){ if(classSignature.length()>0){
this.addAttribute(new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(classSignature),cp.getConstantPool())); this.addAttribute(new Signature(cp.addUtf8("Signature"),2,cp.addUtf8(classSignature),cp.getConstantPool()));
@ -153,7 +144,7 @@ public class ClassGenerator extends ClassGen{
TypePlaceholder tph = it.next(); TypePlaceholder tph = it.next();
//ret += tph.getBytecodeMethodSignature(this); //ret += tph.getBytecodeMethodSignature(this);
//ret += ":"; //ret += ":";
ret += tph.getClassSignature(this); ret += tph.getClassSignature(this, getTypeinferenceResults().getTypeReconstructions().firstElement());
} }
ret += ">"; ret += ">";
} }

View File

@ -26,6 +26,7 @@ import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.Return; import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.type.FunN; import de.dhbwstuttgart.syntaxtree.type.FunN;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
public class DHBWInstructionFactory extends InstructionFactory{ public class DHBWInstructionFactory extends InstructionFactory{
@ -46,7 +47,7 @@ public class DHBWInstructionFactory extends InstructionFactory{
* @param lambdaMethod * @param lambdaMethod
* @return * @return
*/ */
public INVOKEDYNAMIC createInvokeDynamic( String interfaceMethodName, String invokeDynamicMethodType, FunN interfaceMethodType, MethodGen lambdaMethod ) { public INVOKEDYNAMIC createInvokeDynamic( String interfaceMethodName, String invokeDynamicMethodType, FunN interfaceMethodType, MethodGen lambdaMethod, TypeinferenceResultSet rs) {
//Zuerst die Bootstrap-Methode erstellen: Diese müssen dann in ein BootstrapMethods-Attribut zusammengefasst und dem Classfile hinzugefügt werden //Zuerst die Bootstrap-Methode erstellen: Diese müssen dann in ein BootstrapMethods-Attribut zusammengefasst und dem Classfile hinzugefügt werden
//this.cp.addMethodref(lambdaMethod); //this.cp.addMethodref(lambdaMethod);
@ -67,7 +68,7 @@ public class DHBWInstructionFactory extends InstructionFactory{
String lambdaTypeParameterList = "()"; String lambdaTypeParameterList = "()";
ConstantMethodType lambdaMethodType1 = new ConstantMethodType(this.cp.addUtf8(interfaceMethodType.getBytecodeInvokeDynamicSignatureUpperBound(cg))); //TODO: Hier den Grund finden, warum Object stehen muss. ConstantMethodType lambdaMethodType1 = new ConstantMethodType(this.cp.addUtf8(interfaceMethodType.getBytecodeInvokeDynamicSignatureUpperBound(cg))); //TODO: Hier den Grund finden, warum Object stehen muss.
ConstantMethodType lambdaMethodType = new ConstantMethodType(this.cp.addUtf8(interfaceMethodType.getBytecodeInvokeDynamicSignature(cg))); ConstantMethodType lambdaMethodType = new ConstantMethodType(this.cp.addUtf8(interfaceMethodType.getBytecodeInvokeDynamicSignature(cg, rs)));
int implMethodKind = 7; // 7 = InvokeSpecial @see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.5 int implMethodKind = 7; // 7 = InvokeSpecial @see https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-5.html#jvms-5.4.3.5
ConstantMethodHandle implMethod = new ConstantMethodHandle(implMethodKind,cg.getConstantPool().addMethodref(lambdaMethod)); //Das zweite Argument ist der MethodRef zur LambdaMethode ConstantMethodHandle implMethod = new ConstantMethodHandle(implMethodKind,cg.getConstantPool().addMethodref(lambdaMethod)); //Das zweite Argument ist der MethodRef zur LambdaMethode

View File

@ -14,6 +14,7 @@ import de.dhbwstuttgart.syntaxtree.ParameterList;
import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.Return; import de.dhbwstuttgart.syntaxtree.statement.Return;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
public class MethodGenerator extends MethodGen{ public class MethodGenerator extends MethodGen{
@ -22,11 +23,11 @@ public class MethodGenerator extends MethodGen{
super(access_flags, return_type, arg_types, arg_names, method_name, class_name, il, cp); super(access_flags, return_type, arg_types, arg_names, method_name, class_name, il, cp);
} }
public Method createMethod(ClassGenerator cg, ParameterList parameter, de.dhbwstuttgart.syntaxtree.type.Type retType, Block block){ public Method createMethod(ClassGenerator cg, ParameterList parameter, de.dhbwstuttgart.syntaxtree.type.Type retType, Block block, TypeinferenceResultSet rs){
MethodGen method = this; MethodGen method = this;
DHBWInstructionFactory factory = cg.getInstructionFactory(); DHBWInstructionFactory factory = cg.getInstructionFactory();
InstructionList blockInstructions = block.genByteCode(cg); InstructionList blockInstructions = block.genByteCode(cg, rs);
InstructionList il = this.getInstructionList(); InstructionList il = this.getInstructionList();
il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen il.append(blockInstructions);//Die vom Block generierten Instructions an die InstructionList der Methode anfügen
@ -42,12 +43,12 @@ public class MethodGenerator extends MethodGen{
//Die korrekte Signatur für die Methode anhängen. Hier sind dann auch die Parameter von RefTypes enthalten: //Die korrekte Signatur für die Methode anhängen. Hier sind dann auch die Parameter von RefTypes enthalten:
String paramTypesSig = "("; String paramTypesSig = "(";
for(FormalParameter p : parameter){ for(FormalParameter p : parameter){
paramTypesSig += p.getType().getBytecodeSignature(cg); paramTypesSig += p.getType().getBytecodeSignature(cg, rs);
Logger.getLogger("MethodGenerator").error(paramTypesSig, Section.CODEGEN); Logger.getLogger("MethodGenerator").error(paramTypesSig, Section.CODEGEN);
} }
paramTypesSig += ")"; paramTypesSig += ")";
String retTypeSig = retType.getBytecodeSignature(cg); String retTypeSig = retType.getBytecodeSignature(cg, rs);
method.addAttribute(factory.createSignatureAttribute(paramTypesSig+retTypeSig)); method.addAttribute(factory.createSignatureAttribute(paramTypesSig+retTypeSig));

View File

@ -110,7 +110,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I
} }
InstructionList fieldInitializations = new InstructionList(); InstructionList fieldInitializations = new InstructionList();
for(FieldDeclaration f : fieldDeclarations){ for(FieldDeclaration f : fieldDeclarations){
fieldInitializations.append(f.genByteCode(_cg)); fieldInitializations.append(f.genByteCode(_cg, typeinferenceResults.getTypeReconstructions().firstElement()));
} }
//Die Konstruktoren müssen die Feld initialisierungswerte beinhalten: //Die Konstruktoren müssen die Feld initialisierungswerte beinhalten:
for(Constructor c : constructors){ for(Constructor c : constructors){

View File

@ -29,6 +29,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption; import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption; import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
@ -66,7 +67,7 @@ public class Constructor extends Method {
InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen
Class parentClass = this.getParentClass(); Class parentClass = this.getParentClass();
MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg), org.apache.commons.bcel6.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp); MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, cg.getTypeinferenceResults().getTypeReconstructions().firstElement()), org.apache.commons.bcel6.generic.Type.NO_ARGS , new String[] { }, "<init>", parentClass.name, il, _cp);
//FieldInitializations an Block anfügen //FieldInitializations an Block anfügen
Block block = this.get_Block(); Block block = this.get_Block();
@ -78,7 +79,7 @@ public class Constructor extends Method {
//method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden) //method.setMaxStack(); //Die Stack Größe automatisch berechnen lassen (erst nach dem alle Instructions angehängt wurden)
cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block())); cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block(), cg.getTypeinferenceResults().getTypeReconstructions().firstElement()));
} }
/** /**
@ -91,7 +92,7 @@ public class Constructor extends Method {
il = toInsert; il = toInsert;
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator cg){ public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs){
return il; return il;
} }
} }

View File

@ -22,6 +22,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint; import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption; import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -170,19 +171,19 @@ public class FieldDeclaration extends Field{
* @param cg * @param cg
* @return - Die InstructionList, welche das Feld initialisiert * @return - Die InstructionList, welche das Feld initialisiert
*/ */
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
//Das Feld an die Klasse anfügen: //Das Feld an die Klasse anfügen:
FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg), this.getDescription(), cg.getConstantPool()); FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(), cg.getConstantPool());
field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg))); field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg, rs)));
cg.addField(field.getField()); cg.addField(field.getField());
//Die Felddekleration an den Konstruktor anhängen: //Die Felddekleration an den Konstruktor anhängen:
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
il.append(new This(this).genByteCode(cg)); il.append(new This(this).genByteCode(cg, rs));
il.append(this.wert.genByteCode(cg)); il.append(this.wert.genByteCode(cg, rs));
FieldInstruction putFieldInstruction = FieldInstruction putFieldInstruction =
cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(), cg.getInstructionFactory().createFieldAccess(this.getParentClass().getName().toString(),
this.getDescription(), this.getType().getBytecodeType(cg), Constants.PUTFIELD); this.getDescription(), this.getType().getBytecodeType(cg, rs), Constants.PUTFIELD);
il.append(putFieldInstruction ); il.append(putFieldInstruction );
return il; return il;
} }

View File

@ -236,7 +236,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns
public String getDescription() { public String getDescription() {
String ret = ""; String ret = "";
if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){ if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){
ret += this.getType().getBytecodeSignature(null); ret += this.getType().getBytecodeSignature(null, null);
} }
return ret+this.getIdentifier(); return ret+this.getIdentifier();
} }

View File

@ -44,6 +44,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption; import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -746,11 +747,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
} }
public void genByteCode(ClassGenerator cg) { public void genByteCode(ClassGenerator cg) {
List<Integer> typeReconstructionSetIndexList = cg.getTypeinferenceResults().getTypeReconstructionSetIndexList(this, cg); List<TypeinferenceResultSet> typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg);
for(Integer t: typeReconstructionSetIndexList){ for(TypeinferenceResultSet t: typeInterferenceResults){
cg.getTypeinferenceResults().setTypeReconstructionSetIndex(t);
DHBWConstantPoolGen _cp = cg.getConstantPool(); DHBWConstantPoolGen _cp = cg.getConstantPool();
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
Class parentClass = this.getParentClass(); Class parentClass = this.getParentClass();
@ -763,7 +762,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
argumentNames = new String[this.parameterlist.size()]; argumentNames = new String[this.parameterlist.size()];
int i = 0; int i = 0;
for(FormalParameter parameter : this.parameterlist){ for(FormalParameter parameter : this.parameterlist){
argumentTypes[i] = parameter.getType().getBytecodeType(cg); argumentTypes[i] = parameter.getType().getBytecodeType(cg, t);
argumentNames[i] = parameter.getIdentifier(); argumentNames[i] = parameter.getIdentifier();
i++; i++;
} }
@ -774,10 +773,10 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
Type returnType = this.getType(); Type returnType = this.getType();
//Methode generieren: //Methode generieren:
MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp); MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp);
//Methode generieren und anfügen: //Methode generieren und anfügen:
cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block())); cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t));
} }
} }
} }

View File

@ -11,6 +11,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
// ino.end // ino.end
@ -145,11 +146,11 @@ public class ParameterList extends SyntaxTreeNode implements Iterable<FormalPara
return this.formalparameter.size(); return this.formalparameter.size();
} }
public org.apache.commons.bcel6.generic.Type[] getBytecodeTypeList(ClassGenerator cg){ public org.apache.commons.bcel6.generic.Type[] getBytecodeTypeList(ClassGenerator cg, TypeinferenceResultSet rs){
org.apache.commons.bcel6.generic.Type[] ret = new org.apache.commons.bcel6.generic.Type[formalparameter.size()]; org.apache.commons.bcel6.generic.Type[] ret = new org.apache.commons.bcel6.generic.Type[formalparameter.size()];
int i = 0; int i = 0;
for(FormalParameter f : formalparameter){ for(FormalParameter f : formalparameter){
ret[i] = f.getType().getBytecodeType(cg); ret[i] = f.getType().getBytecodeType(cg, rs);
i++; i++;
} }
return ret; return ret;

View File

@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.FormalParameter;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
public class ArgumentList extends SyntaxTreeNode public class ArgumentList extends SyntaxTreeNode
{ {
@ -81,19 +82,19 @@ public class ArgumentList extends SyntaxTreeNode
return expr; return expr;
} }
public InstructionList generateBytecode(ClassGenerator cg){ public InstructionList generateBytecode(ClassGenerator cg, TypeinferenceResultSet rs){
InstructionList ret = new InstructionList(); InstructionList ret = new InstructionList();
for(Expr e : expr){ for(Expr e : expr){
ret.append(e.genByteCode(cg)); ret.append(e.genByteCode(cg, rs));
} }
return ret; return ret;
} }
public org.apache.commons.bcel6.generic.Type[] getBytecodeTypeList(ClassGenerator cg){ public org.apache.commons.bcel6.generic.Type[] getBytecodeTypeList(ClassGenerator cg, TypeinferenceResultSet rs){
org.apache.commons.bcel6.generic.Type[] ret = new org.apache.commons.bcel6.generic.Type[expr.size()]; org.apache.commons.bcel6.generic.Type[] ret = new org.apache.commons.bcel6.generic.Type[expr.size()];
int i = 0; int i = 0;
for(Expr e : expr){ for(Expr e : expr){
ret[i] = e.getType().getBytecodeType(cg); ret[i] = e.getType().getBytecodeType(cg, rs);
i++; i++;
} }
return ret; return ret;

View File

@ -34,6 +34,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.Unify; import de.dhbwstuttgart.typeinference.unify.Unify;
@ -179,10 +180,10 @@ public class Assign extends Expr
public static int counterAssign = 0; //Zaehlvariable f<EFBFBD>r ISTORE public static int counterAssign = 0; //Zaehlvariable f<EFBFBD>r ISTORE
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = expr2.genByteCode(cg);//expr2 rechte expr InstructionList il = expr2.genByteCode(cg, rs);//expr2 rechte expr

View File

@ -39,6 +39,7 @@ import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint; import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -227,9 +228,9 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
InstructionList linkeSeite = this.expr1.genByteCode(_cg); InstructionList linkeSeite = this.expr1.genByteCode(_cg, rs);
InstructionList rechteSeite = this.expr2.genByteCode(_cg); InstructionList rechteSeite = this.expr2.genByteCode(_cg, rs);
if(this.getReturnType().getName().equals(new JavaClassName("String"))){ if(this.getReturnType().getName().equals(new JavaClassName("String"))){
throw new TypeinferenceException("Zeichenketten zusammenfügen ist noch nicht unterstützt",this); throw new TypeinferenceException("Zeichenketten zusammenfügen ist noch nicht unterstützt",this);
} }

View File

@ -33,6 +33,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -256,12 +257,12 @@ public class Block extends Statement
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
//ConstantPoolGen _cp = cg.getConstantPool(); //ConstantPoolGen _cp = cg.getConstantPool();
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
for(Statement stmt : this.get_Statement()){ for(Statement stmt : this.get_Statement()){
il.append(stmt.genByteCode(cg)); il.append(stmt.genByteCode(cg, rs));
} }
//il.dispose(); //il.dispose();

View File

@ -22,6 +22,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -130,7 +131,7 @@ public class BoolLiteral extends Literal
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();

View File

@ -23,6 +23,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -123,7 +124,7 @@ public class CastExpr extends UnaryExpr
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -22,6 +22,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -125,7 +126,7 @@ public class CharLiteral extends Literal
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
il.append(new BIPUSH((byte) get_Char())); il.append(new BIPUSH((byte) get_Char()));

View File

@ -25,6 +25,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -145,7 +146,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
}*/ }*/
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
ConstantPoolGen cp = _cg.getConstantPool(); ConstantPoolGen cp = _cg.getConstantPool();
//InstructionFactory _factory = new InstructionFactory(cg, cp); //InstructionFactory _factory = new InstructionFactory(cg, cp);
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();

View File

@ -19,6 +19,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -89,7 +90,7 @@ public class EmptyStmt extends Statement
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -23,6 +23,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -133,7 +134,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
ConstantPoolGen cp = _cg.getConstantPool(); ConstantPoolGen cp = _cg.getConstantPool();
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();

View File

@ -34,6 +34,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.Unify; import de.dhbwstuttgart.typeinference.unify.Unify;
@ -133,7 +134,7 @@ public class ForStmt extends Statement
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
/* /*
0: iconst_0 0: iconst_0
1: istore_1 1: istore_1
@ -147,16 +148,16 @@ public class ForStmt extends Statement
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
il.append(head_Initializer.genByteCode(_cg)); il.append(head_Initializer.genByteCode(_cg, rs));
InstructionHandle ih = il.append(head_Condition.genByteCode(_cg)); InstructionHandle ih = il.append(head_Condition.genByteCode(_cg, rs));
BranchInstruction branch = new IF_ICMPGE(null); BranchInstruction branch = new IF_ICMPGE(null);
il.append(branch); il.append(branch);
il.append(body_Loop_block.genByteCode(_cg)); il.append(body_Loop_block.genByteCode(_cg, rs));
il.append(head_Loop_expr.genByteCode(_cg)); il.append(head_Loop_expr.genByteCode(_cg, rs));
il.append(new GOTO(ih)); il.append(new GOTO(ih));

View File

@ -45,6 +45,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.MUB; import de.dhbwstuttgart.typeinference.unify.MUB;
@ -178,21 +179,21 @@ public class IfStmt extends Statement
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
InstructionFactory _factory = _cg.getInstructionFactory(); InstructionFactory _factory = _cg.getInstructionFactory();
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
IfInstruction ifInstruction = new IFEQ(null); IfInstruction ifInstruction = new IFEQ(null);
il.append(expr.genByteCode(_cg)); il.append(expr.genByteCode(_cg, rs));
//Anmerkung: expr ist vom Typ java.lang.Boolean (per Definition) //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(_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(ifInstruction);
il.append(then_block.genByteCode(_cg)); il.append(then_block.genByteCode(_cg, rs));
if(else_block != null && !(else_block instanceof EmptyStmt)){ if(else_block != null && !(else_block instanceof EmptyStmt)){
GotoInstruction gotoInstruction = new GOTO(null); GotoInstruction gotoInstruction = new GOTO(null);
il.append(gotoInstruction); il.append(gotoInstruction);
ifInstruction.setTarget(il.append(else_block.genByteCode(_cg))); ifInstruction.setTarget(il.append(else_block.genByteCode(_cg, rs)));
gotoInstruction.setTarget(il.append(new NOP())); gotoInstruction.setTarget(il.append(new NOP()));
}else{ }else{
ifInstruction.setTarget(il.append(new NOP())); ifInstruction.setTarget(il.append(new NOP()));

View File

@ -220,7 +220,7 @@ public class InstVar extends Expr
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -23,6 +23,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -119,7 +120,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -26,6 +26,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -139,7 +140,7 @@ public class IntLiteral extends Literal
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();

View File

@ -43,6 +43,7 @@ import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.Typeable; import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption; import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -238,12 +239,12 @@ public class LambdaExpression extends Expr{
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
ConstantPoolGen cp = cg.getConstantPool(); ConstantPoolGen cp = cg.getConstantPool();
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
org.apache.commons.bcel6.generic.Type[] paramTypes = params.getBytecodeTypeList(cg); org.apache.commons.bcel6.generic.Type[] paramTypes = params.getBytecodeTypeList(cg, rs);
org.apache.commons.bcel6.generic.Type retType = method_body.getType().getBytecodeType(cg); org.apache.commons.bcel6.generic.Type retType = method_body.getType().getBytecodeType(cg, rs);
MethodGenerator lambdaMethod = new MethodGenerator(0, retType, MethodGenerator lambdaMethod = new MethodGenerator(0, retType,
paramTypes, params.getParameterNameArray(), cg.createLambdaMethodName(), paramTypes, params.getParameterNameArray(), cg.createLambdaMethodName(),
@ -255,18 +256,18 @@ public class LambdaExpression extends Expr{
String interfaceMethodName = "apply"; //Das ist ein Hack, funktioniert momentan, da nur FunN Interfaces für LambdaAusdrücke funktionieren String interfaceMethodName = "apply"; //Das ist ein Hack, funktioniert momentan, da nur FunN Interfaces für LambdaAusdrücke funktionieren
il.append(InstructionFactory.createLoad( org.apache.commons.bcel6.generic.Type.OBJECT, 0)); il.append(InstructionFactory.createLoad( org.apache.commons.bcel6.generic.Type.OBJECT, 0));
il.append(cg.getInstructionFactory().createInvokeDynamic(interfaceMethodName,this.getLambdaSignature(cg),lambdaType,lambdaMethod)); il.append(cg.getInstructionFactory().createInvokeDynamic(interfaceMethodName,this.getLambdaSignature(cg, rs),lambdaType,lambdaMethod, rs));
cg.addMethod(lambdaMethod.createMethod(cg, params, method_body.getType(), method_body)); cg.addMethod(lambdaMethod.createMethod(cg, params, method_body.getType(), method_body, rs));
return il; return il;
} }
private String getLambdaSignature(ClassGenerator cg){ private String getLambdaSignature(ClassGenerator cg, TypeinferenceResultSet rs){
String typeSignature = "("; String typeSignature = "(";
typeSignature+=this.getParentClass().getType().getBytecodeType(cg).getSignature(); typeSignature+=this.getParentClass().getType().getBytecodeType(cg, rs).getSignature();
typeSignature += ")"; typeSignature += ")";
typeSignature += this.lambdaType.getBytecodeType(cg).getSignature(); typeSignature += this.lambdaType.getBytecodeType(cg, rs).getSignature();
return typeSignature; return typeSignature;
} }
} }

View File

@ -29,6 +29,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption; import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -148,14 +149,14 @@ public class LocalOrFieldVar extends Expr
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
if(this.isFieldAccess){ 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().createFieldAccess(this.getParentClass().getName().toString(), this.get_Name(), this.getType().getBytecodeType(cg, rs), Constants.GETFIELD));
} }
Type type = this.getType(); Type type = this.getType();
org.apache.commons.bcel6.generic.Type byteCodeType = type.getBytecodeType(cg); org.apache.commons.bcel6.generic.Type byteCodeType = type.getBytecodeType(cg, rs);
String name = this.get_Name(); String name = this.get_Name();

View File

@ -29,6 +29,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.LocalVarAssumption; import de.dhbwstuttgart.typeinference.assumptions.LocalVarAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.DebugException;
@ -429,7 +430,7 @@ public class LocalVarDecl extends Statement implements TypeInsertable
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return new InstructionList(); return new InstructionList();
} }

View File

@ -22,6 +22,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -129,7 +130,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
ConstantPoolGen cp = _cg.getConstantPool(); ConstantPoolGen cp = _cg.getConstantPool();
//InstructionFactory _factory = new InstructionFactory(cg, cp); //InstructionFactory _factory = new InstructionFactory(cg, cp);
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();

View File

@ -25,6 +25,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint; import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint; import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
@ -321,15 +322,15 @@ public class MethodCall extends Expr
*/ */
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
InstructionList il = new InstructionList(); 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, rs));
//Herausfinden, ob eine Methode oder ein Interface aufgerufen wird: //Herausfinden, ob eine Methode oder ein Interface aufgerufen wird:
Type receiverType = this.receiver.get_Expr().getType(); Type receiverType = this.receiver.get_Expr().getType();
de.dhbwstuttgart.syntaxtree.Class receiverClass = this.receiver.getReceiverClass(cg); de.dhbwstuttgart.syntaxtree.Class receiverClass = this.receiver.getReceiverClass(cg, rs);
short kind = 0; short kind = 0;
if(receiverClass.isInterface()){ if(receiverClass.isInterface()){
kind = Constants.INVOKEINTERFACE; kind = Constants.INVOKEINTERFACE;
@ -342,15 +343,15 @@ public class MethodCall extends Expr
argumentTypen = new org.apache.commons.bcel6.generic.Type[this.getArgumentList().size()]; argumentTypen = new org.apache.commons.bcel6.generic.Type[this.getArgumentList().size()];
int i = 0; int i = 0;
for(Expr argument : this.arglist.expr){ for(Expr argument : this.arglist.expr){
argumentTypen[i] = argument.getType().getBytecodeType(cg); argumentTypen[i] = argument.getType().getBytecodeType(cg, rs);
//Das Argument auf den Stack legen: //Das Argument auf den Stack legen:
il.append(argument.genByteCode(cg)); il.append(argument.genByteCode(cg, rs));
i++; i++;
} }
} }
org.apache.commons.bcel6.generic.Type returnType = this.getType().getBytecodeType(cg); org.apache.commons.bcel6.generic.Type returnType = this.getType().getBytecodeType(cg, rs);
il.append(_factory.createInvoke(receiver.getReceiverClass(cg).getName().toString(), this.get_Name(), returnType , argumentTypen, kind)); il.append(_factory.createInvoke(receiver.getReceiverClass(cg, rs).getName().toString(), this.get_Name(), returnType , argumentTypen, kind));
return il; return il;
} }

View File

@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify; import de.dhbwstuttgart.typeinference.unify.Unify;
@ -112,7 +113,7 @@ public class NegativeExpr extends UnaryExpr
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -20,6 +20,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -147,11 +148,11 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
il.append(expr.elementAt(0).genByteCode(_cg)); il.append(expr.elementAt(0).genByteCode(_cg, rs));
il.append(_factory.createNewArray( org.apache.commons.bcel6.generic.Type.getType(getTypeName()), (short)1)); il.append(_factory.createNewArray( org.apache.commons.bcel6.generic.Type.getType(getTypeName()), (short)1));

View File

@ -35,6 +35,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint; import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption; import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -193,17 +194,17 @@ public class NewClass extends Expr
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
il.append(_cg.getInstructionFactory().createNew(get_Name())); il.append(_cg.getInstructionFactory().createNew(get_Name()));
il.append(InstructionConstants.DUP); il.append(InstructionConstants.DUP);
if(arglist!=null){ if(arglist!=null){
il.append(arglist.generateBytecode(_cg)); il.append(arglist.generateBytecode(_cg, rs));
il.append(_cg.getInstructionFactory().createInvoke(this.get_Name(), "<init>", il.append(_cg.getInstructionFactory().createInvoke(this.get_Name(), "<init>",
org.apache.commons.bcel6.generic.Type.VOID, org.apache.commons.bcel6.generic.Type.VOID,
this.arglist.getBytecodeTypeList(_cg), Constants.INVOKESPECIAL)); this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL));
}else{ }else{
il.append(_cg.getInstructionFactory().createInvoke(this.get_Name(), "<init>", il.append(_cg.getInstructionFactory().createInvoke(this.get_Name(), "<init>",
org.apache.commons.bcel6.generic.Type.VOID, org.apache.commons.bcel6.generic.Type.VOID,

View File

@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint; import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify; import de.dhbwstuttgart.typeinference.unify.Unify;
@ -136,7 +137,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -22,6 +22,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -95,7 +96,7 @@ public class Null extends Literal
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();

View File

@ -20,6 +20,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -120,7 +121,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify; import de.dhbwstuttgart.typeinference.unify.Unify;
@ -93,7 +94,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -30,6 +30,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint; import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.UndConstraint; import de.dhbwstuttgart.typeinference.UndConstraint;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -103,7 +104,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
public static int counterPostInc = 0; public static int counterPostInc = 0;
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool());
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
counterPostInc++; counterPostInc++;

View File

@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify; import de.dhbwstuttgart.typeinference.unify.Unify;
@ -92,7 +93,7 @@ public class PreDecExpr extends UnaryExpr
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
import de.dhbwstuttgart.typeinference.unify.Unify; import de.dhbwstuttgart.typeinference.unify.Unify;
@ -94,7 +95,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) {
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -18,6 +18,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -101,10 +102,10 @@ public class Receiver
} }
*/ */
public Class getReceiverClass(ClassGenerator cg){ public Class getReceiverClass(ClassGenerator cg, TypeinferenceResultSet rs){
de.dhbwstuttgart.syntaxtree.type.Type receiverType = this.get_Expr().getType(); de.dhbwstuttgart.syntaxtree.type.Type receiverType = this.get_Expr().getType();
if(receiverType instanceof TypePlaceholder){ if(receiverType instanceof TypePlaceholder){
receiverType = cg.resolveTPH((TypePlaceholder)receiverType); receiverType = rs.getTypeOfPlaceholder((TypePlaceholder)receiverType);
} }
if(!(receiverType instanceof RefType)){ if(!(receiverType instanceof RefType)){
throw new TypeinferenceException("Typ des Receivers nicht eindeutig",this.get_Expr()); throw new TypeinferenceException("Typ des Receivers nicht eindeutig",this.get_Expr());

View File

@ -25,6 +25,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -134,12 +135,12 @@ public class Return extends Statement
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
InstructionList il = retexpr.genByteCode(cg); InstructionList il = retexpr.genByteCode(cg, rs);
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
org.apache.commons.bcel6.generic.Type retType = this.getReturnType().getBytecodeType(cg);//retexpr.getType().getBytecodeType(); org.apache.commons.bcel6.generic.Type retType = this.getReturnType().getBytecodeType(cg, rs);//retexpr.getType().getBytecodeType();
il.append(_factory.createReturn(retType )); il.append(_factory.createReturn(retType ));
return il; return il;

View File

@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.Typeable; import de.dhbwstuttgart.typeinference.Typeable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -130,7 +131,7 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse
} }
public abstract InstructionList genByteCode(ClassGenerator _cg); public abstract InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs);
} }

View File

@ -28,6 +28,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
@ -123,7 +124,7 @@ public class StringLiteral extends Literal
} }
//public static int counterString = 0; //public static int counterString = 0;
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
ConstantPoolGen cp = cg.getConstantPool(); ConstantPoolGen cp = cg.getConstantPool();
InstructionFactory _factory = new InstructionFactory(cg, cp); InstructionFactory _factory = new InstructionFactory(cg, cp);
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();

View File

@ -28,6 +28,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption; import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -92,7 +93,7 @@ public class SuperCall extends ThisCall
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator cg) { public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) {
InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool());
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
Type superClass = this.getParentClass().getSuperClass(); Type superClass = this.getParentClass().getSuperClass();

View File

@ -28,6 +28,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption; import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -149,7 +150,7 @@ public class This extends Expr
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
InstructionList il = new InstructionList(); InstructionList il = new InstructionList();
il.append(InstructionFactory.createLoad( org.apache.commons.bcel6.generic.Type.OBJECT, 0)); il.append(InstructionFactory.createLoad( org.apache.commons.bcel6.generic.Type.OBJECT, 0));
return il; return il;

View File

@ -29,6 +29,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet;
@ -137,7 +138,7 @@ public class WhileStmt extends Statement
} }
@Override @Override
public InstructionList genByteCode(ClassGenerator _cg) { public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -6,6 +6,7 @@ import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
public class FreshWildcardType extends ObjectType { public class FreshWildcardType extends ObjectType {
@ -172,7 +173,7 @@ public class FreshWildcardType extends ObjectType {
} }
@Override @Override
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
// TODO: Bytecode // TODO: Bytecode
return null; return null;
} }

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree.type;
import java.util.Iterator; import java.util.Iterator;
import de.dhbwstuttgart.typeinference.Menge; import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.parser.JavaClassName;
import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.Method;
@ -116,13 +117,13 @@ public class FunN extends RefType {
return 0; return 0;
} }
public String getBytecodeInvokeDynamicSignature(ClassGenerator cg) { public String getBytecodeInvokeDynamicSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
String ret = "("; String ret = "(";
for(Type t : T){ for(Type t : T){
ret+=t.getBytecodeType(cg).getSignature(); ret+=t.getBytecodeType(cg, rs).getSignature();
} }
ret +=")"; ret +=")";
ret+= R.getBytecodeType(cg).getSignature(); ret+= R.getBytecodeType(cg, rs).getSignature();
return ret; return ret;
} }

View File

@ -17,7 +17,7 @@ public class GenericClassType extends RefType{
} }
@Override @Override
public String getBytecodeSignature(ClassGenerator cg) { public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
return "L"+getTypeName()+";"; return "L"+getTypeName()+";";
} }
} }

View File

@ -13,6 +13,7 @@ import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -232,7 +233,7 @@ public class GenericTypeVar extends ObjectType
} }
@Override @Override
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
// TODO Bytecode // TODO Bytecode
return null; return null;
} }

View File

@ -822,8 +822,9 @@ public class RefType extends ObjectType implements IMatchable
} }
} }
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { @Override
org.apache.commons.bcel6.generic.ObjectType ret = new org.apache.commons.bcel6.generic.ObjectType(getCombinedType(cg)); public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
org.apache.commons.bcel6.generic.ObjectType ret = new org.apache.commons.bcel6.generic.ObjectType(getCombinedType(cg, rs));
if(this.IsArray()){ if(this.IsArray()){
//Hier wird einfachhalber von einer Dimension ausgegangen. Arrays sind im Bytecode nur für main-Methode relevant //Hier wird einfachhalber von einer Dimension ausgegangen. Arrays sind im Bytecode nur für main-Methode relevant
return new org.apache.commons.bcel6.generic.ArrayType(ret, 1); return new org.apache.commons.bcel6.generic.ArrayType(ret, 1);
@ -833,11 +834,11 @@ public class RefType extends ObjectType implements IMatchable
} }
@Override @Override
public String getBytecodeSignature(ClassGenerator cg) { public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
String combinedType = getCombinedType(cg); String combinedType = getCombinedType(cg, rs);
if(!combinedType.equals(getName().toString())){ if(!combinedType.equals(getName().toString())){
getSuperWildcardTypes(); getSuperWildcardTypes();
Class generatedClass = ASTFactory.createClass(getCombinedType(cg), getGenericClassType(), null, null, new SourceFile()); Class generatedClass = ASTFactory.createClass(getCombinedType(cg, rs), getGenericClassType(), null, null, new SourceFile());
cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResults()).getByteCode()); cg.addExtraClass(generatedClass.genByteCode(new TypeinferenceResults()).getByteCode());
} }
@ -845,7 +846,7 @@ public class RefType extends ObjectType implements IMatchable
return ret; return ret;
} }
public String getCombinedType(ClassGenerator cg){ public String getCombinedType(ClassGenerator cg, TypeinferenceResultSet rs){
//Bsp.: Ljava/util/Vector<Ljava/lang/String;>; //Bsp.: Ljava/util/Vector<Ljava/lang/String;>;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -854,11 +855,11 @@ public class RefType extends ObjectType implements IMatchable
sb.append("%%"); sb.append("%%");
for(Type type: parameter){ for(Type type: parameter){
if(type instanceof RefType){ if(type instanceof RefType){
sb.append(((RefType) type).getCombinedType(cg).replace(".", "%")); sb.append(((RefType) type).getCombinedType(cg, rs).replace(".", "%"));
}else if(type instanceof TypePlaceholder){ }else if(type instanceof TypePlaceholder){
sb.append(((TypePlaceholder) type).getBytecodeType(cg).toString().replace(".", "%")); sb.append(((TypePlaceholder) type).getBytecodeType(cg, rs).toString().replace(".", "%"));
}else{ }else{
sb.append(type.getBytecodeType(cg).toString().replace(".", "%")); sb.append(type.getBytecodeType(cg, rs).toString().replace(".", "%"));
} }
sb.append("%"); sb.append("%");

View File

@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.DebugException;
@ -163,8 +164,8 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I
*/ */
@Override @Override
public String getBytecodeSignature(ClassGenerator cg) { public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
return "-" + this.innerType.getBytecodeSignature(cg); return "-" + this.innerType.getBytecodeSignature(cg, rs);
} }

View File

@ -12,6 +12,7 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.misc.UsedId;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -309,7 +310,7 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
return this; return this;
} }
public abstract org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg); public abstract org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs);
/** /**
* Erzeugt einen String, welcher den Typ genauer angibt. * Erzeugt einen String, welcher den Typ genauer angibt.
@ -317,16 +318,16 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset
* @param cg * @param cg
* @return * @return
*/ */
public String getBytecodeSignature(ClassGenerator cg) { public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
return this.getBytecodeType(cg).getSignature(); return this.getBytecodeType(cg, rs).getSignature();
} }
/** /**
* @param cg * @param cg
* @return Die Signatur wie sie in Klassensignaturen verwendet wird * @return Die Signatur wie sie in Klassensignaturen verwendet wird
*/ */
public String getClassSignature(ClassGenerator cg){ public String getClassSignature(ClassGenerator cg, TypeinferenceResultSet rs){
return this.getBytecodeSignature(cg); return this.getBytecodeSignature(cg, rs);
} }
} }
// ino.end // ino.end

View File

@ -17,6 +17,7 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeInsertable; import de.dhbwstuttgart.typeinference.TypeInsertable;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -436,26 +437,26 @@ public class TypePlaceholder extends ObjectType
} }
@Override @Override
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
Type resolvedType = cg.resolveTPH(this); Type resolvedType = rs.getTypeOfPlaceholder(this);
if(resolvedType instanceof TypePlaceholder){ if(resolvedType instanceof TypePlaceholder){
return DHBWInstructionFactory.createObjectType(); return DHBWInstructionFactory.createObjectType();
} }
return resolvedType.getBytecodeType(cg); return resolvedType.getBytecodeType(cg, rs);
} }
@Override @Override
public String getBytecodeSignature(ClassGenerator cg) { public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
Type resolvedType = cg.resolveTPH(this); Type resolvedType = rs.getTypeOfPlaceholder(this);
if(resolvedType instanceof TypePlaceholder){ if(resolvedType instanceof TypePlaceholder){
cg.addUsedTPH((TypePlaceholder)resolvedType); cg.addUsedTPH((TypePlaceholder)resolvedType);
return new TypePlaceholderType((TypePlaceholder)resolvedType).getSignature(); return new TypePlaceholderType((TypePlaceholder)resolvedType).getSignature();
} }
return resolvedType.getBytecodeSignature(cg); return resolvedType.getBytecodeSignature(cg, rs);
} }
@Override @Override
public String getClassSignature(ClassGenerator cg) { public String getClassSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
//Die Signaturen in der Klasse bauen sich für Generische Variabeln (also TPHs) folgendermaßen auf: "GVAR:SuperClass" //Die Signaturen in der Klasse bauen sich für Generische Variabeln (also TPHs) folgendermaßen auf: "GVAR:SuperClass"
String ret = this.get_Name();//this.getBytecodeSignature(cg); String ret = this.get_Name();//this.getBytecodeSignature(cg);
//ret = ret.substring(1, ret.length()-1) + ":"; //";" mit ":" ersetzen //ret = ret.substring(1, ret.length()-1) + ":"; //";" mit ":" ersetzen

View File

@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.core.IItemWithOffset;
import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.Method;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException;
@ -81,16 +82,17 @@ public class Void extends RefType
} }
@Override @Override
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
return org.apache.commons.bcel6.generic.Type.VOID; return org.apache.commons.bcel6.generic.Type.VOID;
} }
public String getBytecodeSignature(ClassGenerator cg) { @Override
return this.getBytecodeType(cg).getSignature(); public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
return this.getBytecodeType(cg, rs).getSignature();
} }
public String getBytecodeMethodSignature(ClassGenerator cg) { public String getBytecodeMethodSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
return this.getBytecodeSignature(cg); return this.getBytecodeSignature(cg, rs);
} }
} }
// ino.end // ino.end

View File

@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.DebugException;
import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException;
@ -101,13 +102,13 @@ public class WildcardType extends Type{
} }
@Override @Override
public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) {
return this.innerType.getBytecodeType(cg); return this.innerType.getBytecodeType(cg, rs);
} }
@Override @Override
public String getBytecodeSignature(ClassGenerator cg) { public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) {
return this.innerType.getBytecodeSignature(cg); return this.innerType.getBytecodeSignature(cg, rs);
} }

View File

@ -17,88 +17,23 @@ import de.dhbwstuttgart.typeinference.Menge.Equal;
public class TypeinferenceResults { public class TypeinferenceResults {
private Menge<TypeinferenceResultSet> typeReconstructions; private Menge<TypeinferenceResultSet> typeReconstructions;
private Integer typeReconstructionSetIndex = 0;
public TypeinferenceResults() { public TypeinferenceResults() {
typeReconstructions = new Menge<>(); typeReconstructions = new Menge<>();
} }
public TypeinferenceResults(Menge<TypeinferenceResultSet> typeReconstructions) { public TypeinferenceResults(Menge<TypeinferenceResultSet> typeReconstructions) {
//TODO: filter
this.typeReconstructions = typeReconstructions; this.typeReconstructions = typeReconstructions;
} }
public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Menge<TypePlaceholder> toOneOfTheseTypes) {
return typeReconstructions.get(typeReconstructionSetIndex).getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes);
}
public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder) {
return getTypeOfPlaceholder(typePlaceholder, null);
}
public Menge<TypeinferenceResultSet> getTypeReconstructions() { public Menge<TypeinferenceResultSet> getTypeReconstructions() {
return typeReconstructions; return typeReconstructions;
} }
public void setTypeReconstructionSetIndex(Integer typeReconstructionSetIndex) { public Menge<TypeinferenceResultSet> getTypeReconstructions(Method method, ClassGenerator cg) {
this.typeReconstructionSetIndex = typeReconstructionSetIndex; return typeReconstructions;
} }
}
public List<Integer> getTypeReconstructionSetIndexList(Method method, ClassGenerator cg) {
Menge<FormalParameter> parameters = method.parameterlist.formalparameter;
Menge<TypePlaceholder> typePlaceholders = new Menge<>();
List<Integer> result = new LinkedList<>();
Menge<Type[]> types = new Menge<>();
for(FormalParameter parameter: parameters){
if(parameter.getType() instanceof TypePlaceholder){
typePlaceholders.add((TypePlaceholder) parameter.getType());
}
}
for(int i = 0; i < typeReconstructions.size(); i++){
setTypeReconstructionSetIndex(i);
Type[] reconstructionTypes = new Type[typePlaceholders.size()];
for(int t = 0; t < typePlaceholders.size(); t++){
reconstructionTypes[t] = getTypeOfPlaceholder(typePlaceholders.get(t));
}
if(!types.contains(reconstructionTypes, new TypeArrayEqual(cg))){
types.add(reconstructionTypes);
result.add(i);
}
}
return result;
}
}
class TypeArrayEqual implements Equal<Type[]>{
private ClassGenerator cg;
public TypeArrayEqual(ClassGenerator cg) {
this.cg = cg;
}
@Override
public boolean equal(Type[] a, Type[] b) {
if(a.length != b.length){
return false;
}
for(int i = 0; i < a.length; i++){
Logger.getLogger("TypeArrayEqual").error(a[i].toString(), Section.CODEGEN);
Logger.getLogger("TypeArrayEqual").error(b[i].toString(), Section.CODEGEN);
if(!a[i].getBytecodeType(cg).equals(b[i].getBytecodeType(cg))){
Logger.getLogger("TypeArrayEqual").error(a[i].toString(), Section.CODEGEN);
Logger.getLogger("TypeArrayEqual").error(b[i].toString(), Section.CODEGEN);
return false;
}
}
return true;
}
}