diff --git a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java index dee9be8ed..a07d8263d 100644 --- a/src/de/dhbwstuttgart/bytecode/ClassGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/ClassGenerator.java @@ -68,17 +68,14 @@ public class ClassGenerator extends ClassGen{ public org.apache.commons.bcel6.generic.Type getNearestUsedType(TypePlaceholder toTPH){ return this.getNearestUsedType(toTPH, null); } + public Type resolveTPH(TypePlaceholder typePlaceholder) { - return resolveTPH(typePlaceholder, 0, null); + return resolveTPH(typePlaceholder, null); } - public Type resolveTPH(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex) { - return resolveTPH(typePlaceholder, typeinferenceResultSetIndex, null); - } - - public Type resolveTPH(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex, Menge toOneOfTheseTypes) { - return tiResult.getTypeOfPlaceholder(typePlaceholder, typeinferenceResultSetIndex, toOneOfTheseTypes); + public Type resolveTPH(TypePlaceholder typePlaceholder, Menge toOneOfTheseTypes) { + return tiResult.getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes); } public String createLambdaMethodName() { diff --git a/src/de/dhbwstuttgart/bytecode/MethodGenerator.java b/src/de/dhbwstuttgart/bytecode/MethodGenerator.java index ddfcb27c3..3fdb79b01 100644 --- a/src/de/dhbwstuttgart/bytecode/MethodGenerator.java +++ b/src/de/dhbwstuttgart/bytecode/MethodGenerator.java @@ -22,7 +22,7 @@ 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, Integer typeReconstructionSetIndex){ + public Method createMethod(ClassGenerator cg, ParameterList parameter, de.dhbwstuttgart.syntaxtree.type.Type retType, Block block){ MethodGen method = this; DHBWInstructionFactory factory = cg.getInstructionFactory(); @@ -42,21 +42,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){ - if(p.getType() instanceof TypePlaceholder){ - paramTypesSig += ((TypePlaceholder) p.getType()).getBytecodeSignature(cg, typeReconstructionSetIndex); - }else{ - paramTypesSig += p.getType().getBytecodeSignature(cg); - } + paramTypesSig += p.getType().getBytecodeSignature(cg); Logger.getLogger("MethodGenerator").error(paramTypesSig, Section.CODEGEN); } paramTypesSig += ")"; - String retTypeSig = ""; - if(retType instanceof TypePlaceholder){ - retTypeSig = ((TypePlaceholder) retType).getBytecodeSignature(cg, typeReconstructionSetIndex); - }else{ - retTypeSig = retType.getBytecodeSignature(cg); - } + String retTypeSig = retType.getBytecodeSignature(cg); method.addAttribute(factory.createSignatureAttribute(paramTypesSig+retTypeSig)); diff --git a/src/de/dhbwstuttgart/syntaxtree/Constructor.java b/src/de/dhbwstuttgart/syntaxtree/Constructor.java index cce7a56ee..251124cde 100644 --- a/src/de/dhbwstuttgart/syntaxtree/Constructor.java +++ b/src/de/dhbwstuttgart/syntaxtree/Constructor.java @@ -78,7 +78,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(), 0)); + cg.addMethod(method.createMethod(cg, getParameterList(), this.getType(), get_Block())); } /** diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index e803dcf5d..8cd9ce2bd 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Method.java +++ b/src/de/dhbwstuttgart/syntaxtree/Method.java @@ -746,9 +746,11 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable } public void genByteCode(ClassGenerator cg) { - List typeReconstructionSetIndexList = cg.getTypeinferenceResults().getTypeReconstructionSetIndexList(this, cg); + List typeReconstructionSetIndexList = cg.getTypeinferenceResults().getTypeReconstructionSetIndexList(this, cg); for(Integer t: typeReconstructionSetIndexList){ + cg.getTypeinferenceResults().setTypeReconstructionSetIndex(t); + DHBWConstantPoolGen _cp = cg.getConstantPool(); InstructionList il = new InstructionList(); Class parentClass = this.getParentClass(); @@ -761,11 +763,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable argumentNames = new String[this.parameterlist.size()]; int i = 0; for(FormalParameter parameter : this.parameterlist){ - if(parameter.getType() instanceof TypePlaceholder){ - argumentTypes[i] = ((TypePlaceholder) parameter.getType()).getBytecodeType(cg, t); - }else{ - argumentTypes[i] = parameter.getType().getBytecodeType(cg); - } + argumentTypes[i] = parameter.getType().getBytecodeType(cg); argumentNames[i] = parameter.getIdentifier(); i++; } @@ -773,18 +771,13 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable 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; - if(this.getType() instanceof TypePlaceholder){ - returnType = cg.resolveTPH((TypePlaceholder) this.getType(), t); - }else{ - returnType = this.getType(); - } + Type returnType = this.getType(); //Methode generieren: MethodGenerator method = new MethodGenerator(constants, returnType.getBytecodeType(cg), 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)); + cg.addMethod(method.createMethod(cg, getParameterList(), returnType, get_Block())); } } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java index 00fe6aa7c..4b48e9c54 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/TypePlaceholder.java @@ -437,15 +437,7 @@ public class TypePlaceholder extends ObjectType @Override public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg) { - Type resolvedType = cg.resolveTPH(this, 0); - if(resolvedType instanceof TypePlaceholder){ - return DHBWInstructionFactory.createObjectType(); - } - return resolvedType.getBytecodeType(cg); - } - - public org.apache.commons.bcel6.generic.Type getBytecodeType(ClassGenerator cg, Integer typeReconstructionSetIndex) { - Type resolvedType = cg.resolveTPH(this, typeReconstructionSetIndex); + Type resolvedType = cg.resolveTPH(this); if(resolvedType instanceof TypePlaceholder){ return DHBWInstructionFactory.createObjectType(); } @@ -454,11 +446,7 @@ public class TypePlaceholder extends ObjectType @Override public String getBytecodeSignature(ClassGenerator cg) { - return getBytecodeSignature(cg, 0); - } - - public String getBytecodeSignature(ClassGenerator cg, Integer typeReconstructionSetIndex) { - Type resolvedType = cg.resolveTPH(this, typeReconstructionSetIndex); + Type resolvedType = cg.resolveTPH(this); if(resolvedType instanceof TypePlaceholder){ cg.addUsedTPH((TypePlaceholder)resolvedType); return new TypePlaceholderType((TypePlaceholder)resolvedType).getSignature(); diff --git a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java index 3424ad374..43a0f193b 100644 --- a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java +++ b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java @@ -17,6 +17,7 @@ import de.dhbwstuttgart.typeinference.Menge.Equal; public class TypeinferenceResults { private Menge typeReconstructions; + private Integer typeReconstructionSetIndex = 0; public TypeinferenceResults() { typeReconstructions = new Menge<>(); @@ -26,18 +27,22 @@ public class TypeinferenceResults { this.typeReconstructions = typeReconstructions; } - public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex, Menge toOneOfTheseTypes) { - return typeReconstructions.get(typeinferenceResultSetIndex).getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes); + public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Menge toOneOfTheseTypes) { + return typeReconstructions.get(typeReconstructionSetIndex).getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes); } - - public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex) { - return getTypeOfPlaceholder(typePlaceholder, typeinferenceResultSetIndex, null); + + public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder) { + return getTypeOfPlaceholder(typePlaceholder, null); } public Menge getTypeReconstructions() { return typeReconstructions; } + public void setTypeReconstructionSetIndex(Integer typeReconstructionSetIndex) { + this.typeReconstructionSetIndex = typeReconstructionSetIndex; + } + public List getTypeReconstructionSetIndexList(Method method, ClassGenerator cg) { Menge parameters = method.parameterlist.formalparameter; Menge typePlaceholders = new Menge<>(); @@ -51,10 +56,12 @@ public class TypeinferenceResults { } 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), i); + reconstructionTypes[t] = getTypeOfPlaceholder(typePlaceholders.get(t)); } if(!types.contains(reconstructionTypes, new TypeArrayEqual(cg))){ @@ -70,15 +77,10 @@ public class TypeinferenceResults { class TypeArrayEqual implements Equal{ private ClassGenerator cg; - - public TypeArrayEqual(ClassGenerator cg) { - super(); this.cg = cg; } - - - + @Override public boolean equal(Type[] a, Type[] b) { if(a.length != b.length){ @@ -86,6 +88,9 @@ class TypeArrayEqual implements Equal{ } 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); diff --git a/test/bytecode/types/AutoOverloadingTest.java b/test/bytecode/types/AutoOverloadingTest.java index 8aea83fdc..ddc8da0ad 100644 --- a/test/bytecode/types/AutoOverloadingTest.java +++ b/test/bytecode/types/AutoOverloadingTest.java @@ -69,13 +69,13 @@ public class AutoOverloadingTest extends SourceFileBytecodeTest{ URL url = file.toURL(); URL[] urls = new URL[]{url}; - Class integer = classLoader.loadClass("java.lang.Integer"); + Integer integer = new Integer(123); Class[] params = new Class[1]; - params[0] = integer; + params[0] = integer.getClass(); Method method = cls.getDeclaredMethod("method", params); - method.invoke(obj, integer.newInstance()); + method.invoke(obj, integer); assertTrue(true); }catch(Exception e){ throw new RuntimeException(e);