a bunch of fixes.
[IRC.git] / Robust / src / Analysis / SSJava / SSJavaLattice.java
1 package Analysis.SSJava;
2
3 import java.util.HashSet;
4 import java.util.Iterator;
5 import java.util.Set;
6
7 import Util.Lattice;
8
9 public class SSJavaLattice<T> extends Lattice<T> {
10
11   Set<T> sharedLocSet;
12   public static int seed = 0;
13
14   public SSJavaLattice(T top, T bottom) {
15     super(top, bottom);
16     sharedLocSet = new HashSet<T>();
17   }
18
19   public Set<T> getSharedLocSet() {
20     return sharedLocSet;
21   }
22
23   public void addSharedLoc(T loc) {
24     sharedLocSet.add(loc);
25   }
26
27   public boolean isSharedLoc(T loc) {
28     return sharedLocSet.contains(loc);
29   }
30
31   public boolean addRelationHigherToLower(T higher, T lower) {
32
33     System.out.println("add a relation: " + lower + "<" + higher);
34
35     return put(higher, lower);
36   }
37
38   public void insertNewLocationAtOneLevelHigher(T lowerLoc, T newLoc) {
39     // first identifying which location is connected to the input loc
40     Set<T> keySet = getKeySet();
41     Set<T> oneLevelHigherLocSet = new HashSet<T>();
42
43     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
44       T locKey = (T) iterator.next();
45       Set<T> conntectedSet = get(locKey);
46       for (Iterator iterator2 = conntectedSet.iterator(); iterator2.hasNext();) {
47         T connectedLoc = (T) iterator2.next();
48         if (connectedLoc.equals(lowerLoc)) {
49           oneLevelHigherLocSet.add(locKey);
50         }
51       }
52     }
53
54     put(newLoc);
55     addRelationHigherToLower(newLoc, lowerLoc);
56
57     for (Iterator iterator = oneLevelHigherLocSet.iterator(); iterator.hasNext();) {
58       T higherLoc = (T) iterator.next();
59       // remove an existing edge between the higher loc and the input loc
60       get(higherLoc).remove(lowerLoc);
61       // add a new edge from the higher loc to the new location
62       put(higherLoc, newLoc);
63     }
64
65   }
66 }