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;
35 public static ReachState factory() {
36 ReachState out = new ReachState();
37 out = (ReachState) Canonical.makeCanonical( out );
41 public static ReachState factory( ReachTuple rt ) {
43 assert rt.isCanonical();
44 ReachState out = new ReachState();
45 out.reachTuples.add( rt );
46 out = (ReachState) Canonical.makeCanonical( out );
50 protected ReachState() {
51 reachTuples = new HashSet<ReachTuple>();
55 public Iterator iterator() {
56 return reachTuples.iterator();
59 public boolean isEmpty() {
60 return reachTuples.isEmpty();
63 public boolean isSubset( ReachState rsIn ) {
65 return rsIn.reachTuples.containsAll( this.reachTuples );
68 public boolean containsTuple( ReachTuple rt ) {
70 return reachTuples.contains( rt );
73 // this should be a hash table so we can do this by key
74 public ReachTuple containsHrnID( Integer hrnID,
75 boolean isOutOfContext ) {
78 Iterator<ReachTuple> rtItr = reachTuples.iterator();
79 while( rtItr.hasNext() ) {
80 ReachTuple rt = rtItr.next();
81 if( hrnID.equals( rt.getHrnID() ) &&
82 isOutOfContext == rt.isOutOfContext()
93 public boolean equals( Object o ) {
98 if( !(o instanceof ReachState) ) {
102 ReachState rs = (ReachState) o;
103 return reachTuples.equals( rs.reachTuples );
107 public int hashCodeSpecific() {
108 return reachTuples.hashCode();
112 public String toString() {
113 return reachTuples.toString();