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;
34 public static boolean debug = false;
37 public static ExistPredSet factory() {
38 ExistPredSet out = new ExistPredSet();
39 out = (ExistPredSet) Canonical.makeCanonical(out);
43 public static ExistPredSet factory(ExistPred pred) {
44 ExistPredSet out = new ExistPredSet();
46 out = (ExistPredSet) Canonical.makeCanonical(out);
50 protected ExistPredSet() {
51 preds = new HashSet<ExistPred>();
55 public Iterator<ExistPred> iterator() {
56 return preds.iterator();
60 // only consider the subest of the caller elements that
61 // are reachable by callee when testing predicates
62 public ExistPredSet isSatisfiedBy(ReachGraph rg,
63 Set<Integer> calleeReachableNodes
65 ExistPredSet predsOut = null;
67 Iterator<ExistPred> predItr = preds.iterator();
68 while( predItr.hasNext() ) {
69 ExistPredSet predsFromSatisfier =
70 predItr.next().isSatisfiedBy(rg,
71 calleeReachableNodes);
73 if( predsFromSatisfier != null ) {
74 if( predsOut == null ) {
75 predsOut = predsFromSatisfier;
77 predsOut = Canonical.join(predsOut,
87 public boolean isEmpty() {
88 return preds.isEmpty();
92 public boolean equalsSpecific(Object o) {
97 if( !(o instanceof ExistPredSet) ) {
101 ExistPredSet eps = (ExistPredSet) o;
103 return preds.equals(eps.preds);
107 public int hashCodeSpecific() {
108 return preds.hashCode();
112 public String toStringEscNewline() {
115 Iterator<ExistPred> predItr = preds.iterator();
116 while( predItr.hasNext() ) {
117 ExistPred pred = predItr.next();
118 s += pred.toString();
119 if( predItr.hasNext() ) {
128 public String toString() {
130 Iterator<ExistPred> predItr = preds.iterator();
131 while( predItr.hasNext() ) {
132 ExistPred pred = predItr.next();
133 s += pred.toString();
134 if( predItr.hasNext() ) {