Transivitaet Berechnung bei TPHs korrigiert

This commit is contained in:
Fayez Abu Alia 2018-07-26 14:37:11 +02:00
parent adf675e595
commit 5029cca0f1

View File

@ -287,6 +287,8 @@ public class BytecodeGen implements ASTVisitor {
ArrayList<GenericInsertPair> simplifiedPairs = new ArrayList<>(); ArrayList<GenericInsertPair> simplifiedPairs = new ArrayList<>();
ArrayList<HashMap<Integer, TypePlaceholder>> beforeSimplify = new ArrayList<>();
MethodAndTPH method; MethodAndTPH method;
ArrayList<TypePlaceholder> methodTphs = new ArrayList<>(); ArrayList<TypePlaceholder> methodTphs = new ArrayList<>();
ArrayList<GenericInsertPair> methodPairs = new ArrayList<>(); ArrayList<GenericInsertPair> methodPairs = new ArrayList<>();
@ -360,6 +362,13 @@ public class BytecodeGen implements ASTVisitor {
superTphRes = tphsInRel.get(tphsInRel.size()-i); superTphRes = tphsInRel.get(tphsInRel.size()-i);
i++; i++;
} }
if((methodTphs.contains(superTphRes) || !tphExtractor.allTPHS.containsKey(superTphRes))
&& !subTphRes.equals(superTphRes)) {
beforeSimplify.add(tphsInRel);
}
// teste noch den Fall X < Y und Y nicht in TPHS der Methode // teste noch den Fall X < Y und Y nicht in TPHS der Methode
// Dann hat man nach der While-Schleife X < Y // Dann hat man nach der While-Schleife X < Y
// Y muss durch Object ersetzt. // Y muss durch Object ersetzt.
@ -371,9 +380,44 @@ public class BytecodeGen implements ASTVisitor {
simplifiedPairs.add(sPair); simplifiedPairs.add(sPair);
} }
} }
beforeSimplify.forEach(e->{
System.out.println("=> ");
e.forEach((v,k) -> {
System.out.print(v + "->" + k + ", ");
});
System.out.println();
System.out.println("----------------------");
});
if(beforeSimplify.size()>1) {
int i = 0;
while(i<beforeSimplify.size()) {
TypePlaceholder sub = beforeSimplify.get(i).get(0);
for(HashMap<Integer, TypePlaceholder> e: beforeSimplify) {
if(!e.equals(beforeSimplify.get(i)) && e.containsValue(sub)) {
GenericInsertPair sPair = new GenericInsertPair(e.get(0), sub);
System.out.println("To remove = " + e.get(0)+ " " +e.get(e.size()-1));
removePair(simplifiedPairs,e.get(0), e.get(e.size()-1));
simplifiedPairs.add(sPair);
}
}
i++;
}
}
return simplifiedPairs; return simplifiedPairs;
} }
private void removePair(ArrayList<GenericInsertPair> simplifiedPairs, TypePlaceholder typePlaceholder, TypePlaceholder typePlaceholder2) {
for(GenericInsertPair p : simplifiedPairs) {
if(p.TA1.equals(typePlaceholder) && p.TA2.equals(typePlaceholder2)) {
simplifiedPairs.remove(p);
return;
}
}
}
@Override @Override
public void visit(ParameterList formalParameters) { public void visit(ParameterList formalParameters) {
paramsAndLocals = new HashMap<>(); paramsAndLocals = new HashMap<>();