1 package Analysis.SSJava;
3 import java.util.HashSet;
4 import java.util.Hashtable;
5 import java.util.Iterator;
11 public class SharedStatus {
13 // maps location to its current writing var set and flag
14 Hashtable<Location, Pair<Set<Descriptor>, Boolean>> mapLocation2Status;
16 public SharedStatus() {
17 mapLocation2Status = new Hashtable<Location, Pair<Set<Descriptor>, Boolean>>();
20 private Pair<Set<Descriptor>, Boolean> getStatus(Location loc) {
21 Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
23 pair = new Pair<Set<Descriptor>, Boolean>(new HashSet<Descriptor>(), new Boolean(false));
24 mapLocation2Status.put(loc, pair);
29 public void addVar(Location loc, Descriptor d) {
30 getStatus(loc).getFirst().add(d);
33 public void removeVar(Location loc, Descriptor d) {
34 getStatus(loc).getFirst().remove(d);
37 public String toString() {
38 return mapLocation2Status.toString();
41 public Set<Location> getLocationSet() {
42 return mapLocation2Status.keySet();
45 public void merge(SharedStatus inState) {
46 Set<Location> keySet = inState.getLocationSet();
47 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
48 Location inLoc = (Location) iterator.next();
50 Pair<Set<Descriptor>, Boolean> inPair = inState.getStatus(inLoc);
51 Pair<Set<Descriptor>, Boolean> currPair = mapLocation2Status.get(inLoc);
53 if (currPair == null) {
55 new Pair<Set<Descriptor>, Boolean>(new HashSet<Descriptor>(), new Boolean(false));
56 mapLocation2Status.put(inLoc, currPair);
58 mergeSet(currPair.getFirst(), inPair.getFirst());
62 public void mergeSet(Set<Descriptor> curr, Set<Descriptor> in) {
64 // Varset has a special initial value which covers all possible
66 // For the first time of intersection, we can take all previous set
73 public int hashCode() {
74 return mapLocation2Status.hashCode();
77 public Hashtable<Location, Pair<Set<Descriptor>, Boolean>> getMap() {
78 return mapLocation2Status;
81 public boolean equals(Object o) {
82 if (!(o instanceof SharedStatus)) {
85 SharedStatus in = (SharedStatus) o;
86 return in.getMap().equals(mapLocation2Status);
89 public Set<Descriptor> getVarSet(Location loc) {
90 return mapLocation2Status.get(loc).getFirst();
93 public void updateFlag(Location loc, boolean b) {
94 Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
95 if (pair.getSecond() != b) {
96 mapLocation2Status.put(loc,
97 new Pair<Set<Descriptor>, Boolean>(pair.getFirst(), Boolean.valueOf(b)));
101 public void updateFlag(boolean b) {
102 Set<Location> locKeySet = mapLocation2Status.keySet();
103 for (Iterator iterator = locKeySet.iterator(); iterator.hasNext();) {
104 Location loc = (Location) iterator.next();
105 Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
106 mapLocation2Status.put(loc,
107 new Pair<Set<Descriptor>, Boolean>(pair.getFirst(), Boolean.valueOf(b)));
112 public boolean getFlag(Location loc) {
113 return mapLocation2Status.get(loc).getSecond().booleanValue();
116 public SharedStatus clone() {
117 SharedStatus newState = new SharedStatus();
118 newState.mapLocation2Status =
119 (Hashtable<Location, Pair<Set<Descriptor>, Boolean>>) mapLocation2Status.clone();