diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index a07d8263d..8e2a86d19 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -62,22 +62,13 @@ public class ClassGenerator extends ClassGen{ //return getNearestType((TypePlaceholder) t); return new TypePlaceholderType((TypePlaceholder) t); }else{ - return t.getBytecodeType(this); + return t.getBytecodeType(this, getTypeinferenceResults().getTypeReconstructions().firstElement()); } } public org.apache.commons.bcel6.generic.Type getNearestUsedType(TypePlaceholder toTPH){ return this.getNearestUsedType(toTPH, null); } - - public Type resolveTPH(TypePlaceholder typePlaceholder) { - return resolveTPH(typePlaceholder, null); - } - - public Type resolveTPH(TypePlaceholder typePlaceholder, Menge toOneOfTheseTypes) { - return tiResult.getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes); - } - public String createLambdaMethodName() { return "lambda$methode$"+(lambdaMethodeNr++); } @@ -135,7 +126,7 @@ public class ClassGenerator extends ClassGen{ //Signatur setzen: String typeParameters = this.generateParameterSignature(); - String superClassSignature = this.superClass.getBytecodeSignature(this); + String superClassSignature = this.superClass.getBytecodeSignature(this, null); String classSignature = typeParameters + superClassSignature; if(classSignature.length()>0){ 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(); //ret += tph.getBytecodeMethodSignature(this); //ret += ":"; - ret += tph.getClassSignature(this); + ret += tph.getClassSignature(this, getTypeinferenceResults().getTypeReconstructions().firstElement()); } ret += ">"; } diff --git a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java index 2c69189d4..a5e469318 100644 --- a/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java +++ b/src/de/dhbwstuttgart/bytecode/DHBWInstructionFactory.java @@ -26,6 +26,7 @@ import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Return; import de.dhbwstuttgart.syntaxtree.type.FunN; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; public class DHBWInstructionFactory extends InstructionFactory{ @@ -46,7 +47,7 @@ public class DHBWInstructionFactory extends InstructionFactory{ * @param lambdaMethod * @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 //this.cp.addMethodref(lambdaMethod); @@ -67,7 +68,7 @@ public class DHBWInstructionFactory extends InstructionFactory{ String lambdaTypeParameterList = "()"; 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 ConstantMethodHandle implMethod = new ConstantMethodHandle(implMethodKind,cg.getConstantPool().addMethodref(lambdaMethod)); //Das zweite Argument ist der MethodRef zur LambdaMethode diff --git a/src/de/dhbwstuttgart/bytecode/MethodGenerator.java b/src/de/dhbwstuttgart/bytecode/MethodGenerator.java index 3fdb79b01..fe6531a80 100644 --- a/src/de/dhbwstuttgart/bytecode/MethodGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/MethodGenerator.java @@ -14,6 +14,7 @@ import de.dhbwstuttgart.syntaxtree.ParameterList; import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Return; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; 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); } - 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; DHBWInstructionFactory factory = cg.getInstructionFactory(); - InstructionList blockInstructions = block.genByteCode(cg); + InstructionList blockInstructions = block.genByteCode(cg, rs); InstructionList il = this.getInstructionList(); 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: String paramTypesSig = "("; for(FormalParameter p : parameter){ - paramTypesSig += p.getType().getBytecodeSignature(cg); + paramTypesSig += p.getType().getBytecodeSignature(cg, rs); Logger.getLogger("MethodGenerator").error(paramTypesSig, Section.CODEGEN); } paramTypesSig += ")"; - String retTypeSig = retType.getBytecodeSignature(cg); + String retTypeSig = retType.getBytecodeSignature(cg, rs); method.addAttribute(factory.createSignatureAttribute(paramTypesSig+retTypeSig)); diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index d3a5ab108..006e35377 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -110,7 +110,7 @@ public class Class extends GTVDeclarationContext implements AClassOrInterface, I } InstructionList fieldInitializations = new InstructionList(); 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: for(Constructor c : constructors){ diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java index 7a6b443cb..65a855225 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -29,6 +29,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.SingleConstraint; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption; @@ -65,8 +66,8 @@ public class Constructor extends Method { DHBWConstantPoolGen _cp = cg.getConstantPool(); InstructionList il = new InstructionList(); //sollte nicht new sein sondern aus Block kommen Class parentClass = this.getParentClass(); - - MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg), this.parameterlist.getBytecodeTypeList(cg) , this.parameterlist.getParameterNameArray(), "", parentClass.name, il, _cp); + + MethodGenerator method = new MethodGenerator(Constants.ACC_PUBLIC, this.getType().getBytecodeType(cg, null), this.parameterlist.getBytecodeTypeList(cg,null) , this.parameterlist.getParameterNameArray(), "", parentClass.name, il, _cp); //FieldInitializations an Block anfügen 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) - cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block())); + cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block(), null)); } /** @@ -91,7 +92,7 @@ public class Constructor extends Method { il = toInsert; } @Override - public InstructionList genByteCode(ClassGenerator cg){ + public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs){ return il; } } diff --git a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java index d989a6912..7aba86b21 100644 --- a/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java +++ b/src/de/dhbwstuttgart/syntaxtree/FieldDeclaration.java @@ -22,6 +22,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.OderConstraint; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.SingleConstraint; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -170,19 +171,19 @@ public class FieldDeclaration extends Field{ * @param cg * @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: - FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg), this.getDescription(), cg.getConstantPool()); - field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg))); + FieldGen field = new FieldGen(0, this.getType().getBytecodeType(cg, rs), this.getDescription(), cg.getConstantPool()); + field.addAttribute(cg.getInstructionFactory().createSignatureAttribute(this.getType().getBytecodeSignature(cg, rs))); 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)); + il.append(new This(this).genByteCode(cg, rs)); + il.append(this.wert.genByteCode(cg, rs)); FieldInstruction putFieldInstruction = 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 ); return il; } diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index ddb325d7b..d3df4039b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -236,7 +236,7 @@ public class FormalParameter extends SyntaxTreeNode implements Typeable, TypeIns public String getDescription() { String ret = ""; if(this.getType() != null && !(this.getType() instanceof TypePlaceholder)){ - ret += this.getType().getBytecodeSignature(null); + ret += this.getType().getBytecodeSignature(null, null); } return ret+this.getIdentifier(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 27dc321f8..8977fdd84 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -6,6 +6,7 @@ package de.dhbwstuttgart.syntaxtree; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import java.util.LinkedList; import java.util.List; import org.apache.commons.bcel6.Constants; @@ -18,7 +19,9 @@ import org.apache.commons.bcel6.generic.InstructionList; import org.apache.commons.bcel6.generic.MethodGen; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.Menge.Equal; import de.dhbwstuttgart.logger.Logger; +import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.bytecode.DHBWConstantPoolGen; import de.dhbwstuttgart.bytecode.DHBWInstructionFactory; @@ -44,6 +47,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.TypeInsertable; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; @@ -107,6 +111,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable // ino.end // ino.attribute.parserlog.23518.declaration protected static Logger parserlog = Logger.getLogger("parser"); + + protected Menge createdMethods = new Menge<>(); // ino.end @@ -746,28 +752,43 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable } public void genByteCode(ClassGenerator cg) { - List typeReconstructionSetIndexList = cg.getTypeinferenceResults().getTypeReconstructionSetIndexList(this, cg); + List typeInterferenceResults = cg.getTypeinferenceResults().getTypeReconstructions(this, cg); - for(Integer t: typeReconstructionSetIndexList){ - cg.getTypeinferenceResults().setTypeReconstructionSetIndex(t); - + for(TypeinferenceResultSet t: typeInterferenceResults){ DHBWConstantPoolGen _cp = cg.getConstantPool(); InstructionList il = new InstructionList(); Class parentClass = this.getParentClass(); //Die Argumentliste generieren: - org.apache.commons.bcel6.generic.Type[] argumentTypes = org.apache.commons.bcel6.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.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(cg); + argumentTypes[i] = parameter.getType().getBytecodeType(cg, t); argumentNames[i] = parameter.getIdentifier(); i++; } + + if(!createdMethods.contains(argumentTypes, new ArgumentTypeEquals())){ + createdMethods.add(argumentTypes); + } } + + short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public + if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; + + Type returnType = this.getType(); + + //Methode generieren: + MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg, t), argumentTypes , argumentNames, this.get_Method_Name(), parentClass.name, il, _cp); + + //Methode generieren und anfügen: + cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block(), t)); + + /* short constants = Constants.ACC_PUBLIC; //Per Definition ist jede Methode public if(this.modifiers != null && this.modifiers.includesModifier(new Static())) constants += Constants.ACC_STATIC; @@ -778,11 +799,33 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable //Methode generieren und anfügen: cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block())); - + */ } } - - +} +class ArgumentTypeEquals implements Equal{ + + @Override + public boolean equal(org.apache.commons.bcel6.generic.Type[] a, org.apache.commons.bcel6.generic.Type[] b) { + if(a.length != b.length){ + Logger.getLogger("ArgumentTypeEquals").error("false(length)", Section.CODEGEN); + return false; + } + + for(int i = 0; i < a.length; i++){ + if(!a[i].equals(b[i])){ + String as = a[i].toString(); + String bs = b[i].toString(); + Logger.getLogger("ArgumentTypeEquals").error("false "+as+" != "+bs, Section.CODEGEN); + return false; + } + } + + Logger.getLogger("ArgumentTypeEquals").error("true", Section.CODEGEN); + + return true; + } + } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/ParameterList.java b/src/de/dhbwstuttgart/syntaxtree/ParameterList.java index e88ad0ef4..66c368e3a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/ParameterList.java +++ b/src/de/dhbwstuttgart/syntaxtree/ParameterList.java @@ -11,6 +11,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; // ino.end @@ -145,11 +146,11 @@ public class ParameterList extends SyntaxTreeNode implements Iterable", org.apache.commons.bcel6.generic.Type.VOID, - this.arglist.getBytecodeTypeList(_cg), Constants.INVOKESPECIAL)); + this.arglist.getBytecodeTypeList(_cg, rs), Constants.INVOKESPECIAL)); }else{ il.append(_cg.getInstructionFactory().createInvoke(this.getType().getDescription(), "", org.apache.commons.bcel6.generic.Type.VOID, diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java index 8b3563c6a..c7b6dd992 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java @@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.OderConstraint; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.Unify; @@ -136,7 +137,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public InstructionList genByteCode(ClassGenerator _cg) { + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { // TODO Bytecode throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Null.java b/src/de/dhbwstuttgart/syntaxtree/statement/Null.java index 7a9e2c47f..aa70e5d1c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Null.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Null.java @@ -22,6 +22,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; @@ -95,7 +96,7 @@ public class Null extends Literal } @Override - public InstructionList genByteCode(ClassGenerator cg) { + public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); InstructionList il = new InstructionList(); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java index 2aa6ef6ae..04cef0d5f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java @@ -20,6 +20,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; @@ -120,7 +121,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public InstructionList genByteCode(ClassGenerator _cg) { + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { // TODO Bytecode throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java index 1b3272568..9b80a94a2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java @@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.Unify; @@ -93,7 +94,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public InstructionList genByteCode(ClassGenerator _cg) { + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { // TODO Bytecode throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java index 2eab1c72f..036a5b552 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java @@ -30,6 +30,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.OderConstraint; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.UndConstraint; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; @@ -103,7 +104,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { public static int counterPostInc = 0; @Override - public InstructionList genByteCode(ClassGenerator _cg) { + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { InstructionFactory _factory = new InstructionFactory(_cg, _cg.getConstantPool()); InstructionList il = new InstructionList(); counterPostInc++; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java index 00afda787..d8c3eceac 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java @@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.Unify; @@ -92,7 +93,7 @@ public class PreDecExpr extends UnaryExpr } @Override - public InstructionList genByteCode(ClassGenerator _cg) { + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { // TODO Bytecode throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java index 4005523ed..16ff6864d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java @@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; import de.dhbwstuttgart.typeinference.unify.Unify; @@ -94,7 +95,7 @@ public JavaCodeResult printJavaCode(ResultSet resultSet) { } @Override - public InstructionList genByteCode(ClassGenerator _cg) { + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { // TODO Bytecode throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java index 7c0e70ce5..4dc0947cf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Receiver.java @@ -18,6 +18,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; 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(); if(receiverType instanceof TypePlaceholder){ - receiverType = cg.resolveTPH((TypePlaceholder)receiverType); + receiverType = rs.getTypeOfPlaceholder((TypePlaceholder)receiverType); } if(!(receiverType instanceof RefType)){ throw new TypeinferenceException("Typ des Receivers nicht eindeutig",this.get_Expr()); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java index 170345ef4..d39204c8c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java @@ -25,6 +25,7 @@ import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.SingleConstraint; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; @@ -134,12 +135,12 @@ public class Return extends Statement } @Override - public InstructionList genByteCode(ClassGenerator cg) { - InstructionList il = retexpr.genByteCode(cg); + public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { + InstructionList il = retexpr.genByteCode(cg, rs); 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 )); return il; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java index c8d4d7ba5..d6e2e9f8b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java @@ -26,6 +26,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.Typeable; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; 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); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java index 0323d6036..cab243651 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/StringLiteral.java @@ -28,6 +28,7 @@ import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; @@ -123,7 +124,7 @@ public class StringLiteral extends Literal } //public static int counterString = 0; @Override - public InstructionList genByteCode(ClassGenerator cg) { + public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { ConstantPoolGen cp = cg.getConstantPool(); InstructionFactory _factory = new InstructionFactory(cg, cp); InstructionList il = new InstructionList(); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java index 6b6d45c39..ef90282b2 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/SuperCall.java @@ -28,6 +28,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -92,7 +93,7 @@ public class SuperCall extends ThisCall } @Override - public InstructionList genByteCode(ClassGenerator cg) { + public InstructionList genByteCode(ClassGenerator cg, TypeinferenceResultSet rs) { InstructionFactory _factory = new InstructionFactory(cg, cg.getConstantPool()); InstructionList il = new InstructionList(); Type superClass = this.getParentClass().getSuperClass(); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/This.java b/src/de/dhbwstuttgart/syntaxtree/statement/This.java index ead9f40b7..dc9b142b6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/This.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/This.java @@ -28,6 +28,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void; import de.dhbwstuttgart.typeinference.ConstraintsSet; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.ConstructorAssumption; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -149,7 +150,7 @@ public class This extends Expr } @Override - public InstructionList genByteCode(ClassGenerator _cg) { + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { InstructionList il = new InstructionList(); il.append(InstructionFactory.createLoad( org.apache.commons.bcel6.generic.Type.OBJECT, 0)); return il; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java index 771ea7ad5..dd95b912d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java @@ -29,6 +29,7 @@ import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.SingleConstraint; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; import de.dhbwstuttgart.typeinference.unify.CSubstitutionSet; @@ -137,7 +138,7 @@ public class WhileStmt extends Statement } @Override - public InstructionList genByteCode(ClassGenerator _cg) { + public InstructionList genByteCode(ClassGenerator _cg, TypeinferenceResultSet rs) { // TODO Bytecode throw new NotImplementedException(); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java index 40ddb8954..3f7073acf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FreshWildcardType.java @@ -6,6 +6,7 @@ import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; public class FreshWildcardType extends ObjectType { @@ -172,7 +173,7 @@ public class FreshWildcardType extends ObjectType { } @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 return null; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/FunN.java b/src/de/dhbwstuttgart/syntaxtree/type/FunN.java index e3eff8bd8..efe96c263 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/FunN.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/FunN.java @@ -3,6 +3,7 @@ package de.dhbwstuttgart.syntaxtree.type; import java.util.Iterator; import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Method; @@ -116,13 +117,13 @@ public class FunN extends RefType { return 0; } - public String getBytecodeInvokeDynamicSignature(ClassGenerator cg) { + public String getBytecodeInvokeDynamicSignature(ClassGenerator cg, TypeinferenceResultSet rs) { String ret = "("; for(Type t : T){ - ret+=t.getBytecodeType(cg).getSignature(); + ret+=t.getBytecodeType(cg, rs).getSignature(); } ret +=")"; - ret+= R.getBytecodeType(cg).getSignature(); + ret+= R.getBytecodeType(cg, rs).getSignature(); return ret; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java index 2c83b0c98..0df35e3cf 100644 --- a/src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericClassType.java @@ -17,7 +17,7 @@ public class GenericClassType extends RefType{ } @Override - public String getBytecodeSignature(ClassGenerator cg) { + public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) { return "L"+getTypeName()+";"; } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java index 9a4af3d1b..d4e4d52a4 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java @@ -13,6 +13,7 @@ import de.dhbwstuttgart.typeinference.Pair; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.SingleConstraint; import de.dhbwstuttgart.typeinference.TypeInsertable; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -232,7 +233,7 @@ public class GenericTypeVar extends ObjectType } @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 return null; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index f09e0ad62..ba03d5834 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -822,8 +822,9 @@ public class RefType extends ObjectType implements IMatchable } } - public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { - org.apache.commons.bcel6.generic.ObjectType ret = new org.apache.commons.bcel6.generic.ObjectType(getCombinedType(cg)); + @Override + 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()){ //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); @@ -833,11 +834,11 @@ public class RefType extends ObjectType implements IMatchable } @Override - public String getBytecodeSignature(ClassGenerator cg) { - String combinedType = getCombinedType(cg); + public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) { + String combinedType = getCombinedType(cg, rs); if(!combinedType.equals(getName().toString())){ 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()); } @@ -845,7 +846,7 @@ public class RefType extends ObjectType implements IMatchable return ret; } - public String getCombinedType(ClassGenerator cg){ + public String getCombinedType(ClassGenerator cg, TypeinferenceResultSet rs){ //Bsp.: Ljava/util/Vector; StringBuilder sb = new StringBuilder(); @@ -854,11 +855,11 @@ public class RefType extends ObjectType implements IMatchable sb.append("%%"); for(Type type: parameter){ if(type instanceof RefType){ - sb.append(((RefType) type).getCombinedType(cg).replace(".", "%")); + sb.append(((RefType) type).getCombinedType(cg, rs).replace(".", "%")); }else if(type instanceof TypePlaceholder){ - sb.append(((TypePlaceholder) type).getBytecodeType(cg).toString().replace(".", "%")); + sb.append(((TypePlaceholder) type).getBytecodeType(cg, rs).toString().replace(".", "%")); }else{ - sb.append(type.getBytecodeType(cg).toString().replace(".", "%")); + sb.append(type.getBytecodeType(cg, rs).toString().replace(".", "%")); } sb.append("%"); diff --git a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java index a9de59145..df10d9908 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/SuperWildcardType.java @@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; @@ -163,8 +164,8 @@ public class SuperWildcardType extends WildcardType implements ITypeContainer, I */ @Override - public String getBytecodeSignature(ClassGenerator cg) { - return "-" + this.innerType.getBytecodeSignature(cg); + public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) { + return "-" + this.innerType.getBytecodeSignature(cg, rs); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Type.java b/src/de/dhbwstuttgart/syntaxtree/type/Type.java index 5c2e4d86a..5959f52f3 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Type.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Type.java @@ -12,6 +12,7 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -309,7 +310,7 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset 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. @@ -317,16 +318,16 @@ public abstract class Type extends SyntaxTreeNode implements IItemWithOffset * @param cg * @return */ - public String getBytecodeSignature(ClassGenerator cg) { - return this.getBytecodeType(cg).getSignature(); + public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) { + return this.getBytecodeType(cg, rs).getSignature(); } /** * @param cg * @return Die Signatur wie sie in Klassensignaturen verwendet wird */ - public String getClassSignature(ClassGenerator cg){ - return this.getBytecodeSignature(cg); + public String getClassSignature(ClassGenerator cg, TypeinferenceResultSet rs){ + return this.getBytecodeSignature(cg, rs); } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java index 4b48e9c54..33d4babf0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java @@ -17,6 +17,7 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; import de.dhbwstuttgart.typeinference.TypeInsertable; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -436,26 +437,26 @@ public class TypePlaceholder extends ObjectType } @Override - public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { - Type resolvedType = cg.resolveTPH(this); + public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) { + Type resolvedType = rs.getTypeOfPlaceholder(this); if(resolvedType instanceof TypePlaceholder){ return DHBWInstructionFactory.createObjectType(); } - return resolvedType.getBytecodeType(cg); + return resolvedType.getBytecodeType(cg, rs); } @Override - public String getBytecodeSignature(ClassGenerator cg) { - Type resolvedType = cg.resolveTPH(this); + public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) { + Type resolvedType = rs.getTypeOfPlaceholder(this); if(resolvedType instanceof TypePlaceholder){ cg.addUsedTPH((TypePlaceholder)resolvedType); return new TypePlaceholderType((TypePlaceholder)resolvedType).getSignature(); } - return resolvedType.getBytecodeSignature(cg); + return resolvedType.getBytecodeSignature(cg, rs); } @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" String ret = this.get_Name();//this.getBytecodeSignature(cg); //ret = ret.substring(1, ret.length()-1) + ":"; //";" mit ":" ersetzen diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Void.java b/src/de/dhbwstuttgart/syntaxtree/type/Void.java index 2bd17d766..500c65a34 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Void.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Void.java @@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.core.IItemWithOffset; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; @@ -81,16 +82,17 @@ public class Void extends RefType } @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; } - public String getBytecodeSignature(ClassGenerator cg) { - return this.getBytecodeType(cg).getSignature(); + @Override + public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) { + return this.getBytecodeType(cg, rs).getSignature(); } - public String getBytecodeMethodSignature(ClassGenerator cg) { - return this.getBytecodeSignature(cg); + public String getBytecodeMethodSignature(ClassGenerator cg, TypeinferenceResultSet rs) { + return this.getBytecodeSignature(cg, rs); } } // ino.end diff --git a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java index feff1e557..262e1466f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/WildcardType.java @@ -5,6 +5,7 @@ import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.typeinference.JavaCodeResult; import de.dhbwstuttgart.typeinference.ResultSet; +import de.dhbwstuttgart.typeinference.TypeinferenceResultSet; import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions; import de.dhbwstuttgart.typeinference.exceptions.DebugException; import de.dhbwstuttgart.typeinference.exceptions.NotImplementedException; @@ -101,13 +102,13 @@ public class WildcardType extends Type{ } @Override - public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { - return this.innerType.getBytecodeType(cg); + public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, TypeinferenceResultSet rs) { + return this.innerType.getBytecodeType(cg, rs); } @Override - public String getBytecodeSignature(ClassGenerator cg) { - return this.innerType.getBytecodeSignature(cg); + public String getBytecodeSignature(ClassGenerator cg, TypeinferenceResultSet rs) { + return this.innerType.getBytecodeSignature(cg, rs); } diff --git a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java index 43a0f193b..b2486c2cd 100644 --- a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java +++ b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java @@ -1,104 +1,58 @@ package de.dhbwstuttgart.typeinference; -import java.util.LinkedList; -import java.util.List; - import de.dhbwstuttgart.bytecode.ClassGenerator; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.Section; -import de.dhbwstuttgart.syntaxtree.FormalParameter; import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType; import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType; -import de.dhbwstuttgart.syntaxtree.type.Type; -import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.Menge.Equal; public class TypeinferenceResults { private Menge typeReconstructions; - private Integer typeReconstructionSetIndex = 0; public TypeinferenceResults() { typeReconstructions = new Menge<>(); } public TypeinferenceResults(Menge typeReconstructions) { + //TODO: filter + + int limit = typeReconstructions.size(); + Logger.getLogger("TypeinferenceResults").error(new Integer(limit).toString(), Section.CODEGEN); + for(int i = 0; i < limit; i++){ + Logger.getLogger("TypeinferenceResults").error(new Integer(i).toString(), Section.CODEGEN); + + for(Pair p: typeReconstructions.get(i).getUnifiedConstraints()){ + boolean flag = false; + + Logger.getLogger("TypeinferenceResults").error(p.toString(), Section.CODEGEN); + + if( p.TA1 instanceof SuperWildcardType || + p.TA1 instanceof ExtendsWildcardType || + p.TA2 instanceof SuperWildcardType || + p.TA2 instanceof ExtendsWildcardType || + flag){ + + Logger.getLogger("TypeinferenceResults").error("remove", Section.CODEGEN); + + typeReconstructions.remove(i); + i--; + limit--; + flag = true; + } + } + } + + this.typeReconstructions = typeReconstructions; } - public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Menge toOneOfTheseTypes) { - return typeReconstructions.get(typeReconstructionSetIndex).getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes); - } - - public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder) { - return getTypeOfPlaceholder(typePlaceholder, null); - } - public Menge getTypeReconstructions() { return typeReconstructions; } - public void setTypeReconstructionSetIndex(Integer typeReconstructionSetIndex) { - this.typeReconstructionSetIndex = typeReconstructionSetIndex; + public Menge getTypeReconstructions(Method method, ClassGenerator cg) { + return typeReconstructions; } - - public List getTypeReconstructionSetIndexList(Method method, ClassGenerator cg) { - Menge parameters = method.parameterlist.formalparameter; - Menge typePlaceholders = new Menge<>(); - List result = new LinkedList<>(); - Menge 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{ - 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; - } - -} +} \ No newline at end of file diff --git a/test/bytecode/SingleClassTester.java b/test/bytecode/SingleClassTester.java index 1a02e4d39..5c4eface1 100644 --- a/test/bytecode/SingleClassTester.java +++ b/test/bytecode/SingleClassTester.java @@ -38,6 +38,8 @@ public class SingleClassTester { Menge bytecode = compiler.generateBytecode(sourceFiles, results); //System.out.println(bytecode); + + ByteCodeResult result = bytecode.firstElement(); JavaClass javaClass = result.getByteCode().getJavaClass(); diff --git a/test/bytecode/types/AutoOverloading.jav b/test/bytecode/types/AutoOverloading.jav index 193bbfe7b..314a7f48f 100644 --- a/test/bytecode/types/AutoOverloading.jav +++ b/test/bytecode/types/AutoOverloading.jav @@ -1,5 +1,3 @@ -import java.util.Vector; - class AutoOverloading{ method2(String p){ diff --git a/test/bytecode/types/AutoOverloadingVector.jav b/test/bytecode/types/AutoOverloadingVector.jav new file mode 100644 index 000000000..431abf650 --- /dev/null +++ b/test/bytecode/types/AutoOverloadingVector.jav @@ -0,0 +1,18 @@ +import java.util.Vector; + +class AutoOverloadingVector{ + method2(p){ + + } + + + method(Vector p){ + method2(p.firstElement()); + } + + + method(Vector p){ + method2(p.firstElement()); + } + +} \ No newline at end of file diff --git a/test/bytecode/types/AutoOverloadingVectorTest.java b/test/bytecode/types/AutoOverloadingVectorTest.java new file mode 100644 index 000000000..aa4264b7b --- /dev/null +++ b/test/bytecode/types/AutoOverloadingVectorTest.java @@ -0,0 +1,84 @@ +package bytecode.types; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class AutoOverloadingVectorTest extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "AutoOverloadingVector"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; + } + + @Test + public void testConstruct() throws Exception{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + assertTrue(true); + } + + @Test + public void testString() { + try{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + File file = new File(rootDirectory); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + Class string = classLoader.loadClass("java.lang.String"); + + Class[] params = new Class[1]; + params[0] = string; + + Method method = cls.getDeclaredMethod("method2", params); + method.invoke(obj, string.newInstance()); + assertTrue(true); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + @Test + public void testInteger() { + try{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + File file = new File(rootDirectory); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + Integer integer = new Integer(123); + + Class[] params = new Class[1]; + params[0] = integer.getClass(); + + Method method = cls.getDeclaredMethod("method2", params); + method.invoke(obj, integer); + assertTrue(true); + }catch(Exception e){ + throw new RuntimeException(e); + } + } +} diff --git a/test/bytecode/types/MethodWithTypedVector.jav b/test/bytecode/types/MethodWithTypedVector.jav index a74062eeb..35261e96f 100644 --- a/test/bytecode/types/MethodWithTypedVector.jav +++ b/test/bytecode/types/MethodWithTypedVector.jav @@ -4,4 +4,8 @@ class MethodWithTypedVector{ public void method(Vector v) { } + + public void method(Vector v) { + + } } \ No newline at end of file