Mehrere Lösungen in einer Classfile
This commit is contained in:
parent
8b0005ecee
commit
e4374c06fd
@ -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<Integer> 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()));
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<TypeinferenceResultSet> getTypeReconstructions() {
|
||||
return typeReconstructions;
|
||||
}
|
||||
|
||||
public List<Integer> getTypeReconstructionSetIndexList(Method method) {
|
||||
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++){
|
||||
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<Type[]>{
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user