import IR.Tree.SubBlockNode;
import IR.Tree.TertiaryNode;
import IR.Tree.TreeNode;
+import Util.Pair;
public class FlowDownCheck {
toanalyze.remove(cd);
if (!cd.isInterface()) {
+
+ ClassDescriptor superDesc = cd.getSuperDesc();
+ if (superDesc != null && (!superDesc.isInterface())
+ && (!superDesc.getSymbol().equals("Object"))) {
+ checkOrderingInheritance(superDesc, cd);
+ }
+
checkDeclarationInClass(cd);
for (Iterator method_it = cd.getMethods(); method_it.hasNext();) {
MethodDescriptor md = (MethodDescriptor) method_it.next();
}
+ private void checkOrderingInheritance(ClassDescriptor superCd, ClassDescriptor cd) {
+ // here, we're going to check that sub class keeps same relative orderings
+ // in respect to super class
+
+ SSJavaLattice<String> superLattice = ssjava.getClassLattice(superCd);
+ SSJavaLattice<String> subLattice = ssjava.getClassLattice(cd);
+
+ Set<Pair<String, String>> superPairSet = superLattice.getOrderingPairSet();
+ Set<Pair<String, String>> subPairSet = subLattice.getOrderingPairSet();
+
+ for (Iterator iterator = superPairSet.iterator(); iterator.hasNext();) {
+ Pair<String, String> pair = (Pair<String, String>) iterator.next();
+
+ if (!subPairSet.contains(pair)) {
+ throw new Error("Subclass '" + cd + "' does not have the relative ordering '"
+ + pair.getSecond() + " < " + pair.getFirst() + "' that is defined by its superclass '"
+ + superCd + "'.");
+ }
+ }
+
+ }
+
public Hashtable getMap() {
return d2loc;
}
}
-
private CompositeLocation checkLocationFromArrayAccessNode(MethodDescriptor md,
SymbolTable nametable, ArrayAccessNode aan) {
// addTypeLocation(on.getRight().getType(), rightLoc);
}
-// System.out.println("checking op node=" + on.printNode(0));
-// System.out.println("left loc=" + leftLoc + " from " + on.getLeft().getClass());
-// System.out.println("right loc=" + rightLoc + " from " + on.getRight().getClass());
+ // System.out.println("checking op node=" + on.printNode(0));
+ // System.out.println("left loc=" + leftLoc + " from " +
+ // on.getLeft().getClass());
+ // System.out.println("right loc=" + rightLoc + " from " +
+ // on.getRight().getClass());
Operation op = on.getOp();
}
srcLocation = new CompositeLocation();
srcLocation = checkLocationFromExpressionNode(md, nametable, an.getSrc(), srcLocation);
-// System.out.println(" an= " + an.printNode(0) + " an.getSrc()=" + an.getSrc().getClass()
-// + " at " + cd.getSourceFileName() + "::" + an.getNumLine());
-// System.out.println("srcLocation=" + srcLocation);
-// System.out.println("dstLocation=" + destLocation);
+ // System.out.println(" an= " + an.printNode(0) + " an.getSrc()=" +
+ // an.getSrc().getClass()
+ // + " at " + cd.getSourceFileName() + "::" + an.getNumLine());
+ // System.out.println("srcLocation=" + srcLocation);
+ // System.out.println("dstLocation=" + destLocation);
if (!CompositeLattice.isGreaterThan(srcLocation, destLocation)) {
throw new Error("The value flow from " + srcLocation + " to " + destLocation
+ " does not respect location hierarchy on the assignment " + an.printNode(0) + " at "
return lowerSet;
}
+ public Set<Pair<T, T>> getOrderingPairSet() {
+ // return the set of pairs in the lattice
+
+ Set<Pair<T, T>> set = new HashSet<Pair<T, T>>();
+
+ Set<T> visited = new HashSet<T>();
+ Set<T> needtovisit = new HashSet<T>();
+ needtovisit.add(top);
+
+ while (!needtovisit.isEmpty()) {
+ T key = needtovisit.iterator().next();
+ Set<T> lowerSet = table.get(key);
+ if(lowerSet!=null){
+ for (Iterator iterator = lowerSet.iterator(); iterator.hasNext();) {
+ T lowerItem = (T) iterator.next();
+ set.add(new Pair(key, lowerItem));
+ if (!visited.contains(key)) {
+ needtovisit.add(lowerItem);
+ }
+ }
+ }
+ visited.add(key);
+ needtovisit.remove(key);
+ }
+ return set;
+ }
+
}