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,
64 Set<RefSrcNode> callerSrcMatches
66 ExistPredSet predsOut = null;
68 Iterator<ExistPred> predItr = preds.iterator();
69 while( predItr.hasNext() ) {
70 ExistPredSet predsFromSatisfier =
71 predItr.next().isSatisfiedBy(rg,
75 if( predsFromSatisfier != null ) {
76 if( predsOut == null ) {
77 predsOut = predsFromSatisfier;
79 predsOut = Canonical.join(predsOut,
89 // this method returns the source node of any
90 // edge predicates in the set for the given graph
91 public Set<RefSrcNode> getEdgeSources( ReachGraph rg ) {
92 Set<RefSrcNode> out = new HashSet<RefSrcNode>();
94 for( ExistPred pred: preds ) {
95 RefSrcNode rsn = pred.getEdgeSource( rg );
106 public boolean isEmpty() {
107 return preds.isEmpty();
111 public boolean equalsSpecific(Object o) {
116 if( !(o instanceof ExistPredSet) ) {
120 ExistPredSet eps = (ExistPredSet) o;
122 return preds.equals(eps.preds);
126 public int hashCodeSpecific() {
127 return preds.hashCode();
131 public String toStringEscNewline() {
134 Iterator<ExistPred> predItr = preds.iterator();
135 while( predItr.hasNext() ) {
136 ExistPred pred = predItr.next();
137 s += pred.toString();
138 if( predItr.hasNext() ) {
147 public String toString() {
149 Iterator<ExistPred> predItr = preds.iterator();
150 while( predItr.hasNext() ) {
151 ExistPred pred = predItr.next();
152 s += pred.toString();
153 if( predItr.hasNext() ) {