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 set of existence predicates that are
27 // OR'ed terms, if any predicate is true
28 // then the set evaluates to true
30 public class ExistPredSet extends Canonical {
32 protected Set<ExistPred> preds;
35 public static ExistPredSet factory() {
36 ExistPredSet out = new ExistPredSet();
37 out = (ExistPredSet) Canonical.makeCanonical( out );
41 public static ExistPredSet factory( ExistPred pred ) {
42 ExistPredSet out = new ExistPredSet();
43 out.preds.add( pred );
44 out = (ExistPredSet) Canonical.makeCanonical( out );
48 protected ExistPredSet() {
49 preds = new HashSet<ExistPred>();
53 public Iterator<ExistPred> iterator() {
54 return preds.iterator();
58 // only consider the subest of the caller elements that
59 // are reachable by callee when testing predicates
60 public ExistPredSet isSatisfiedBy( ReachGraph rg,
61 Set<Integer> calleeReachableNodes
63 ExistPredSet predsOut = null;
65 Iterator<ExistPred> predItr = preds.iterator();
66 while( predItr.hasNext() ) {
67 ExistPredSet predsFromSatisfier =
68 predItr.next().isSatisfiedBy( rg,
69 calleeReachableNodes );
71 if( predsFromSatisfier != null ) {
72 if( predsOut == null ) {
73 predsOut = predsFromSatisfier;
75 predsOut = Canonical.join( predsOut,
85 public boolean equals( Object o ) {
90 if( !(o instanceof ExistPredSet) ) {
94 ExistPredSet eps = (ExistPredSet) o;
96 return preds.equals( eps.preds );
100 public int hashCodeSpecific() {
101 return preds.hashCode();
105 public String toString() {
107 Iterator<ExistPred> predItr = preds.iterator();
108 while( predItr.hasNext() ) {
109 ExistPred pred = predItr.next();
110 s += pred.toString();
111 if( predItr.hasNext() ) {