forked from JavaTX/JavaCompilerCore
Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2
This commit is contained in:
commit
6b33fdc5fb
@ -109,7 +109,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
}
|
||||
}else {
|
||||
// System.out.println("Cons has NOT Gens");
|
||||
// System.out.println("Cons has NO Gens");
|
||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import java.util.LinkedList;
|
||||
import org.objectweb.asm.Type;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.TPHExtractor;
|
||||
import de.dhbwstuttgart.bytecode.constraint.EqualConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||
@ -42,7 +43,7 @@ public class Simplify {
|
||||
if(revCon != null) {
|
||||
revCon.setRel(Relation.EQUAL);
|
||||
// the reverse constraint is removed because
|
||||
// otherwise there is twice the same constraint
|
||||
// otherwise there is the same constraint twice
|
||||
// (e.g. A<B and B<A => A=B and B=A)
|
||||
consToRemove.add(revCon);
|
||||
c.setRel(Relation.EQUAL);
|
||||
@ -199,6 +200,7 @@ public class Simplify {
|
||||
// if yes => check if the super type in the method, if not
|
||||
// then ignore it.
|
||||
HashMap<String, String> subAndSuper = new HashMap<>();
|
||||
ArrayList<TPHConstraint> eqCons = new ArrayList<>();
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(subAndSuper.containsKey(c.getLeft())) {
|
||||
LinkedList<String> all = new LinkedList<>();
|
||||
@ -216,9 +218,28 @@ public class Simplify {
|
||||
if(!containTPH(methodTphs, all.getLast()))
|
||||
continue;
|
||||
}
|
||||
if(subAndSuper.containsKey(c.getLeft())) {
|
||||
System.out.println(c.getLeft());
|
||||
String r = c.getRight();
|
||||
String r2 = subAndSuper.get(c.getLeft());
|
||||
EqualConstraint eq = new EqualConstraint(r2, r, Relation.EQUAL);
|
||||
eqCons.add(eq);
|
||||
substituteInMap(subAndSuper,eqCons,allCons,r,r2);
|
||||
}
|
||||
subAndSuper.put(c.getLeft(), c.getRight());
|
||||
}
|
||||
|
||||
System.out.println("SAME LEFT SIDE: ");
|
||||
subAndSuper.forEach((c,hs)->{
|
||||
if(c!=null) {
|
||||
System.out.print(c+ " -> " + hs);
|
||||
|
||||
}
|
||||
|
||||
|
||||
System.out.println();
|
||||
});
|
||||
System.out.println("----------------");
|
||||
int numOfVisitedPairs = 0;
|
||||
for(String sub : subAndSuper.keySet()) {
|
||||
if(isTPHInConstraint(result,sub))
|
||||
@ -280,17 +301,23 @@ public class Simplify {
|
||||
}
|
||||
|
||||
if(!containTPH(methodTphs, superTphRes)) {
|
||||
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), null);
|
||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons,superTphRes);
|
||||
|
||||
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), equals);
|
||||
} else {
|
||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), null);
|
||||
if(!isTPHInConstraint(result, superTphRes))
|
||||
result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), null);
|
||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons,subTphRes);
|
||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
||||
if(!isTPHInConstraint(result, superTphRes) && !isTphInEqualSet(result,superTphRes)) {
|
||||
HashSet<String> equals2 = getEqualsTphsFromEqualCons(eqCons,superTphRes);
|
||||
result.put(new ExtendsConstraint(superTphRes, Type.getInternalName(Object.class), Relation.EXTENDS), equals2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(String tph : methodTphs) {
|
||||
if(!isTPHInConstraint(result, tph)) {
|
||||
result.put(new ExtendsConstraint(tph, Type.getInternalName(Object.class), Relation.EXTENDS), null);
|
||||
if(!isTPHInConstraint(result, tph) && !isTphInEqualSet(result,tph)) {
|
||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons,tph);
|
||||
result.put(new ExtendsConstraint(tph, Type.getInternalName(Object.class), Relation.EXTENDS), equals);
|
||||
}
|
||||
}
|
||||
|
||||
@ -314,6 +341,43 @@ public class Simplify {
|
||||
return result;
|
||||
}
|
||||
|
||||
private static boolean isTphInEqualSet(HashMap<TPHConstraint, HashSet<String>> result, String tph) {
|
||||
for(HashSet<String> hs: result.values()) {
|
||||
if(hs.contains(tph))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static HashSet<String> getEqualsTphsFromEqualCons(ArrayList<TPHConstraint> eqCons, String tph) {
|
||||
HashSet<String> ee = new HashSet<>();
|
||||
for(TPHConstraint c : eqCons) {
|
||||
if(c.getLeft().equals(tph))
|
||||
ee.add(c.getRight());
|
||||
if(c.getRight().equals(tph))
|
||||
ee.add(c.getLeft());
|
||||
}
|
||||
return ee;
|
||||
}
|
||||
|
||||
private static void substituteInMap(HashMap<String, String> subAndSuper, ArrayList<TPHConstraint> allCons,ArrayList<TPHConstraint> eqCons, String toSubs,
|
||||
String tph) {
|
||||
substituteTPH(allCons, toSubs, tph);
|
||||
if(subAndSuper.containsKey(toSubs) && subAndSuper.containsKey(tph)) {
|
||||
toSubs = subAndSuper.remove(toSubs);
|
||||
EqualConstraint eq = new EqualConstraint(subAndSuper.get(tph), toSubs, Relation.EQUAL);
|
||||
eqCons.add(eq);
|
||||
substituteInMap(subAndSuper, allCons,eqCons,toSubs, subAndSuper.get(tph));
|
||||
} else if(subAndSuper.containsKey(toSubs) && !subAndSuper.containsKey(tph)) {
|
||||
String val = subAndSuper.remove(toSubs);
|
||||
subAndSuper.put(tph, val);
|
||||
} else {
|
||||
for(String k : subAndSuper.keySet()) {
|
||||
subAndSuper.replace(k, toSubs, tph);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static TPHConstraint getConstraint(String oldRight, String right, ArrayList<TPHConstraint> allCons) {
|
||||
for(TPHConstraint c : allCons) {
|
||||
if(c.getLeft().equals(oldRight) && c.getRight().equals(right))
|
||||
|
@ -70,9 +70,11 @@ public class SameLeftSide {
|
||||
TPHConstraint d = new ExtendsConstraint("D", Type.getInternalName(Object.class), Relation.EXTENDS);
|
||||
TPHConstraint a = new ExtendsConstraint("A", "D", Relation.EXTENDS);
|
||||
TPHConstraint b = new ExtendsConstraint("B", "D", Relation.EXTENDS);
|
||||
result.put(d, null);
|
||||
result.put(a, null);
|
||||
result.put(b, null);
|
||||
result.put(d, new HashSet<>());
|
||||
result.put(a, new HashSet<>());
|
||||
HashSet<String> hs = new HashSet<>();
|
||||
|
||||
result.put(b, hs);
|
||||
|
||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName, tphExtractor);
|
||||
boolean areEquals = SimpleCycle.areMapsEqual(result, sim);
|
||||
@ -86,8 +88,10 @@ public class SameLeftSide {
|
||||
TPHConstraint e = new ExtendsConstraint("E", Type.getInternalName(Object.class), Relation.EXTENDS);
|
||||
TPHConstraint c = new ExtendsConstraint("C", "E", Relation.EXTENDS);
|
||||
|
||||
result.put(e, null);
|
||||
result.put(c, null);
|
||||
result.put(e, new HashSet<>());
|
||||
HashSet<String> hs = new HashSet<>();
|
||||
hs.add("B");
|
||||
result.put(c, hs);
|
||||
|
||||
HashMap<TPHConstraint, HashSet<String>> sim = Simplify.simplifyConstraints(methName2, tphExtractor);
|
||||
boolean areEquals = SimpleCycle.areMapsEqual(result, sim);
|
||||
|
Loading…
Reference in New Issue
Block a user