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 // set of location having write effects
17 public HashSet<Location> writeLocSet;
19 public SharedStatus() {
20 mapLocation2Status = new Hashtable<Location, Pair<Set<Descriptor>, Boolean>>();
21 writeLocSet = new HashSet<Location>();
24 private Pair<Set<Descriptor>, Boolean> getStatus(Location loc) {
25 Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
27 pair = new Pair<Set<Descriptor>, Boolean>(new HashSet<Descriptor>(), new Boolean(false));
28 mapLocation2Status.put(loc, pair);
33 public void addVar(Location loc, Descriptor d) {
34 getStatus(loc).getFirst().add(d);
37 public void setWriteEffect(Location loc) {
41 public void removeVar(Location loc, Descriptor d) {
43 Set<Descriptor> dSet = getStatus(loc).getFirst();
48 public String toString() {
49 return mapLocation2Status.toString();
52 public Set<Location> getLocationSet() {
53 return mapLocation2Status.keySet();
56 public void merge(SharedStatus inState) {
57 Set<Location> keySet = inState.getLocationSet();
58 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
59 Location inLoc = (Location) iterator.next();
61 Pair<Set<Descriptor>, Boolean> inPair = inState.getStatus(inLoc);
62 Pair<Set<Descriptor>, Boolean> currPair = mapLocation2Status.get(inLoc);
64 if (currPair == null) {
66 new Pair<Set<Descriptor>, Boolean>(new HashSet<Descriptor>(), new Boolean(false));
67 mapLocation2Status.put(inLoc, currPair);
69 mergeSet(currPair.getFirst(), inPair.getFirst());
72 writeLocSet.addAll(inState.getWriteLocSet());
75 public boolean haveWriteEffect(Location loc) {
76 return writeLocSet.contains(loc);
79 public Set<Location> getWriteLocSet() {
83 public void mergeSet(Set<Descriptor> curr, Set<Descriptor> in) {
85 // Varset has a special initial value which covers all possible
87 // For the first time of intersection, we can take all previous set
94 public int hashCode() {
95 return mapLocation2Status.hashCode();
98 public Hashtable<Location, Pair<Set<Descriptor>, Boolean>> getMap() {
99 return mapLocation2Status;
102 public boolean equals(Object o) {
103 if (!(o instanceof SharedStatus)) {
106 SharedStatus in = (SharedStatus) o;
107 return in.getMap().equals(mapLocation2Status);
110 public Set<Descriptor> getVarSet(Location loc) {
111 return mapLocation2Status.get(loc).getFirst();
114 public void updateFlag(Location loc, boolean b) {
115 Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
116 if (pair.getSecond() != b) {
117 mapLocation2Status.put(loc,
118 new Pair<Set<Descriptor>, Boolean>(pair.getFirst(), Boolean.valueOf(b)));
122 public void updateFlag(boolean b) {
123 Set<Location> locKeySet = mapLocation2Status.keySet();
124 for (Iterator iterator = locKeySet.iterator(); iterator.hasNext();) {
125 Location loc = (Location) iterator.next();
126 Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
127 mapLocation2Status.put(loc,
128 new Pair<Set<Descriptor>, Boolean>(pair.getFirst(), Boolean.valueOf(b)));
133 public boolean getFlag(Location loc) {
134 return mapLocation2Status.get(loc).getSecond().booleanValue();
137 public SharedStatus clone() {
138 SharedStatus newState = new SharedStatus();
139 newState.mapLocation2Status =
140 (Hashtable<Location, Pair<Set<Descriptor>, Boolean>>) mapLocation2Status.clone();
141 newState.writeLocSet=(HashSet<Location>) writeLocSet.clone();