diff --git a/src/de/dhbwstuttgart/syntaxtree/Method.java b/src/de/dhbwstuttgart/syntaxtree/Method.java index 659a522d..0130daef 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.List; import org.apache.commons.bcel6.Constants; import org.apache.commons.bcel6.classfile.Signature; @@ -745,9 +746,10 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable } public void genByteCode(ClassGenerator cg) { - //for(int t = 0; t < cg.getTypeinferenceResults().getTypeReconstructions().size(); t++){ + List typeReconstructionSetIndexList = cg.getTypeinferenceResults().getTypeReconstructionSetIndexList(this); + + for(Integer t: typeReconstructionSetIndexList){ DHBWConstantPoolGen _cp = cg.getConstantPool(); - DHBWInstructionFactory _factory = new DHBWInstructionFactory(cg, _cp); InstructionList il = new InstructionList(); Class parentClass = this.getParentClass(); @@ -760,7 +762,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable int i = 0; for(FormalParameter parameter : this.parameterlist){ if(parameter.getType() instanceof TypePlaceholder){ - argumentTypes[i] = ((TypePlaceholder) parameter.getType()).getBytecodeType(cg, 0); + argumentTypes[i] = ((TypePlaceholder) parameter.getType()).getBytecodeType(cg, t); }else{ argumentTypes[i] = parameter.getType().getBytecodeType(cg); } @@ -776,7 +778,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable //Methode generieren und anfügen: cg.addMethod(method.createMethod(cg, getParameterList(), getType(), get_Block())); - //} + } } diff --git a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java index e132e27e..79915d9b 100644 --- a/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java +++ b/src/de/dhbwstuttgart/typeinference/TypeinferenceResults.java @@ -1,7 +1,13 @@ package de.dhbwstuttgart.typeinference; +import java.util.LinkedList; +import java.util.List; + +import de.dhbwstuttgart.syntaxtree.FormalParameter; +import de.dhbwstuttgart.syntaxtree.Method; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.typeinference.Menge.Equal; public class TypeinferenceResults { @@ -19,7 +25,58 @@ public class TypeinferenceResults { return typeReconstructions.get(typeinferenceResultSetIndex).getTypeOfPlaceholder(typePlaceholder, toOneOfTheseTypes); } + public Type getTypeOfPlaceholder(TypePlaceholder typePlaceholder, Integer typeinferenceResultSetIndex) { + return getTypeOfPlaceholder(typePlaceholder, typeinferenceResultSetIndex, null); + } + public Menge getTypeReconstructions() { return typeReconstructions; } + + public List getTypeReconstructionSetIndexList(Method method) { + 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++){ + Type[] reconstructionTypes = new Type[typePlaceholders.size()]; + + for(int t = 0; t < typePlaceholders.size(); t++){ + reconstructionTypes[t] = getTypeOfPlaceholder(typePlaceholders.get(t), i); + } + + if(!types.contains(reconstructionTypes, new TypeArrayEqual())){ + types.add(reconstructionTypes); + result.add(i); + } + } + + return result; + } +} + +class TypeArrayEqual implements Equal{ + + @Override + public boolean equal(Type[] a, Type[] b) { + if(a.length != b.length){ + return false; + } + + for(int i = 0; i < a.length; i++){ + if(!a[i].equals(b[i])){ + return false; + } + } + + return true; + } + }