add one more checking, class inheritance: If a class B has a super class A, all relat...
authoryeom <yeom>
Tue, 31 May 2011 23:48:40 +0000 (23:48 +0000)
committeryeom <yeom>
Tue, 31 May 2011 23:48:40 +0000 (23:48 +0000)
Robust/src/Analysis/SSJava/FlowDownCheck.java
Robust/src/Util/Lattice.java

index 82e3dc11daf77c32d5e08034023039d3a39da24d..980a3266b7d1165e88780ca179eeabb80a9210d0 100644 (file)
@@ -41,6 +41,7 @@ import IR.Tree.ReturnNode;
 import IR.Tree.SubBlockNode;
 import IR.Tree.TertiaryNode;
 import IR.Tree.TreeNode;
+import Util.Pair;
 
 public class FlowDownCheck {
 
@@ -97,6 +98,13 @@ 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();
@@ -133,6 +141,28 @@ public class FlowDownCheck {
 
   }
 
+  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;
   }
@@ -644,7 +674,6 @@ public class FlowDownCheck {
 
   }
 
   private CompositeLocation checkLocationFromArrayAccessNode(MethodDescriptor md,
       SymbolTable nametable, ArrayAccessNode aan) {
 
@@ -712,9 +741,11 @@ public class FlowDownCheck {
       // 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();
 
@@ -877,10 +908,11 @@ public class FlowDownCheck {
       }
       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 "
index cb8da73fd19687cde10da4571d40b556fa89cbf0..e22103c5d5b9bc9d23fb757333dac1f4807acf18 100644 (file)
@@ -220,4 +220,31 @@ public class Lattice<T> {
     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;
+  }
+
 }