1 package Analysis.Disjoint;
8 ///////////////////////////////////////////
10 // This class is an immutable Canonical, so
12 // 0) construct them with a factory pattern
13 // to ensure only canonical versions escape
15 // 1) any operation that modifies a Canonical
16 // is a static method in the Canonical class
18 // 2) operations that just read this object
19 // should be defined here
21 // 3) every Canonical subclass hashCode should
22 // throw an error if the hash ever changes
24 ///////////////////////////////////////////
26 // a reach state is a set of reach tuples
27 // such that any heap region ID in a tuple
28 // appears at most once in the state
30 public class ReachState extends Canonical {
32 protected HashSet<ReachTuple> reachTuples;
34 // existance predicates must be true in a caller
35 // context for this state to transfer from this
36 // callee to that context
37 protected ExistPredSet preds;
40 public static ReachState factory() {
41 ReachState out = new ReachState();
42 out = (ReachState) Canonical.makeCanonical(out);
46 public static ReachState factory(ReachTuple rt) {
48 assert rt.isCanonical();
49 ReachState out = new ReachState();
50 out.reachTuples.add(rt);
51 out = (ReachState) Canonical.makeCanonical(out);
55 public static ReachState factory(HashSet<ReachTuple> reachTuples,
58 assert reachTuples != null;
60 assert preds.isCanonical();
61 ReachState out = new ReachState();
62 out.reachTuples.addAll(reachTuples);
64 out = (ReachState) Canonical.makeCanonical(out);
68 protected ReachState() {
69 reachTuples = new HashSet<ReachTuple>();
70 preds = ExistPredSet.factory();
74 public Iterator iterator() {
75 return reachTuples.iterator();
78 public boolean isEmpty() {
79 return reachTuples.isEmpty();
82 public boolean isSubset(ReachState rsIn) {
84 return rsIn.reachTuples.containsAll(this.reachTuples);
87 public boolean containsTuple(ReachTuple rt) {
89 return reachTuples.contains(rt);
92 // this should be a hash table so we can do this by key
93 public ReachTuple containsHrnID(Integer hrnID,
94 boolean isOutOfContext) {
97 Iterator<ReachTuple> rtItr = reachTuples.iterator();
98 while( rtItr.hasNext() ) {
99 ReachTuple rt = rtItr.next();
100 if( hrnID.equals(rt.getHrnID() ) &&
101 isOutOfContext == rt.isOutOfContext()
110 public ExistPredSet getPreds() {
115 public boolean equalsSpecific(Object o) {
120 if( !(o instanceof ReachState) ) {
124 ReachState rs = (ReachState) o;
126 reachTuples.equals(rs.reachTuples) &&
127 preds.equals(rs.preds);
131 public int hashCodeSpecific() {
133 reachTuples.hashCode() ^
138 public boolean equalsIgnorePreds(Object o) {
143 if( !(o instanceof ReachState) ) {
147 ReachState rs = (ReachState) o;
149 reachTuples.equals(rs.reachTuples);
154 public String toString() {
155 return reachTuples.toString();
156 //return reachTuples+":"+preds;
159 public String toStringPreds() {
160 return reachTuples+":"+preds;