all fixed...
[IRC.git] / Robust / src / Analysis / SSJava / SSJavaLattice.java
index 847cfecbb68e8707130cbb363a28d3d1bb4a8d1d..406b72eca8c2671f0f1e326d4c72039819976848 100644 (file)
@@ -320,10 +320,14 @@ public class SSJavaLattice<T> extends Lattice<T> {
   }
 
   public void insertNewLocationBetween(T higher, Set<T> lowerSet, T newLoc) {
-    System.out.println("---insert new location=" + newLoc + "   between=" + higher + "<->"
-        + lowerSet);
+    // System.out.println("---insert new location=" + newLoc + "   between=" + higher + "<->"
+    // + lowerSet);
     Set<T> connectedSet = get(higher);
-    connectedSet.removeAll(lowerSet);
+    if (connectedSet == null) {
+      connectedSet = new HashSet<T>();
+    } else {
+      connectedSet.removeAll(lowerSet);
+    }
     connectedSet.add(newLoc);
 
     for (Iterator iterator = lowerSet.iterator(); iterator.hasNext();) {
@@ -340,4 +344,39 @@ public class SSJavaLattice<T> extends Lattice<T> {
     return clone;
   }
 
+  public int countPaths() {
+    T bottom = getBottomItem();
+
+    Map<T, Set<T>> map = getIncomingElementMap();
+    Map<T, Integer> countMap = new HashMap<T, Integer>();
+
+    Set<T> visited = new HashSet<T>();
+    visited.add(bottom);
+
+    countMap.put(bottom, new Integer(1));
+    recur_countPaths(bottom, map, countMap, visited);
+    if (countMap.containsKey(getTopItem())) {
+      return countMap.get(getTopItem());
+    }
+    return 0;
+  }
+
+  private void recur_countPaths(T cur, Map<T, Set<T>> map, Map<T, Integer> countMap, Set<T> visited) {
+    int curCount = countMap.get(cur).intValue();
+    Set<T> inSet = map.get(cur);
+
+    for (Iterator iterator = inSet.iterator(); iterator.hasNext();) {
+      T in = (T) iterator.next();
+      int inCount = 0;
+      if (countMap.containsKey(in)) {
+        inCount = countMap.get(in).intValue();
+      }
+      inCount += curCount;
+      countMap.put(in, inCount);
+      if (visited.containsAll(get(in))) {
+        visited.add(in);
+        recur_countPaths(in, map, countMap, visited);
+      }
+    }
+  }
 }