a bunch of fixes.
[IRC.git] / Robust / src / Analysis / SSJava / SSJavaLattice.java
index cbbae46c8ffb2ae6a59c547a615a10bbd6fcb8ff..be1a342ec9ff6d2630cf5cc7d0b8908829c48559 100644 (file)
@@ -1,16 +1,15 @@
 package Analysis.SSJava;
 
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Set;
 
 import Util.Lattice;
 
 public class SSJavaLattice<T> extends Lattice<T> {
 
-  public static final String TOP = "_top_";
-  public static final String BOTTOM = "_bottom_";
-
   Set<T> sharedLocSet;
+  public static int seed = 0;
 
   public SSJavaLattice(T top, T bottom) {
     super(top, bottom);
@@ -36,4 +35,32 @@ public class SSJavaLattice<T> extends Lattice<T> {
     return put(higher, lower);
   }
 
+  public void insertNewLocationAtOneLevelHigher(T lowerLoc, T newLoc) {
+    // first identifying which location is connected to the input loc
+    Set<T> keySet = getKeySet();
+    Set<T> oneLevelHigherLocSet = new HashSet<T>();
+
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      T locKey = (T) iterator.next();
+      Set<T> conntectedSet = get(locKey);
+      for (Iterator iterator2 = conntectedSet.iterator(); iterator2.hasNext();) {
+        T connectedLoc = (T) iterator2.next();
+        if (connectedLoc.equals(lowerLoc)) {
+          oneLevelHigherLocSet.add(locKey);
+        }
+      }
+    }
+
+    put(newLoc);
+    addRelationHigherToLower(newLoc, lowerLoc);
+
+    for (Iterator iterator = oneLevelHigherLocSet.iterator(); iterator.hasNext();) {
+      T higherLoc = (T) iterator.next();
+      // remove an existing edge between the higher loc and the input loc
+      get(higherLoc).remove(lowerLoc);
+      // add a new edge from the higher loc to the new location
+      put(higherLoc, newLoc);
+    }
+
+  }
 }