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... rts) {
47 ReachState out = new ReachState();
48 for( ReachTuple rt : rts ) {
50 assert rt.isCanonical();
51 out.reachTuples.add(rt);
53 out = (ReachState) Canonical.makeCanonical(out);
57 public static ReachState factory(HashSet<ReachTuple> reachTuples,
60 assert reachTuples != null;
62 assert preds.isCanonical();
63 ReachState out = new ReachState();
64 out.reachTuples.addAll(reachTuples);
66 out = (ReachState) Canonical.makeCanonical(out);
70 protected ReachState() {
71 reachTuples = new HashSet<ReachTuple>();
72 preds = ExistPredSet.factory();
76 public Iterator<ReachTuple> iterator() {
77 return reachTuples.iterator();
80 public boolean isEmpty() {
81 return reachTuples.isEmpty();
84 public boolean isSubset(ReachState rsIn) {
86 return rsIn.reachTuples.containsAll(this.reachTuples);
89 public boolean containsTuple(ReachTuple rt) {
91 return reachTuples.contains(rt);
94 // this should be a hash table so we can do this by key
95 public ReachTuple containsHrnID(Integer hrnID,
96 boolean isOutOfContext) {
99 Iterator<ReachTuple> rtItr = reachTuples.iterator();
100 while( rtItr.hasNext() ) {
101 ReachTuple rt = rtItr.next();
102 if( hrnID.equals(rt.getHrnID() ) &&
103 isOutOfContext == rt.isOutOfContext()
112 public ExistPredSet getPreds() {
117 public boolean equalsSpecific(Object o) {
122 if( !(o instanceof ReachState) ) {
126 ReachState rs = (ReachState) o;
128 reachTuples.equals(rs.reachTuples) &&
129 preds.equals(rs.preds);
133 public int hashCodeSpecific() {
135 reachTuples.hashCode() ^
140 public int hashCodeNoPreds() {
141 return reachTuples.hashCode();
145 public boolean equalsIgnorePreds(Object o) {
150 if( !(o instanceof ReachState) ) {
154 ReachState rs = (ReachState) o;
156 reachTuples.equals(rs.reachTuples);
161 public String toString() {
162 return reachTuples.toString();
163 //return reachTuples+":"+preds;
166 public String toStringPreds() {
167 return reachTuples+":"+preds;
170 public String toString( boolean hidePreds ) {
174 return toStringPreds();