public class ExistPredSet extends Canonical {
+ protected static boolean DISABLE_PREDICATES = false;
+
protected Set<ExistPred> preds;
-
+ public static boolean debug = false;
+
+
public static ExistPredSet factory() {
ExistPredSet out = new ExistPredSet();
- out = (ExistPredSet) Canonical.makeCanonical( out );
+ out = (ExistPredSet) Canonical.makeCanonical(out);
return out;
}
- public static ExistPredSet factory( ExistPred pred ) {
+ public static ExistPredSet factory(ExistPred pred) {
ExistPredSet out = new ExistPredSet();
- out.preds.add( pred );
- out = (ExistPredSet) Canonical.makeCanonical( out );
+ out.preds.add(pred);
+ out = (ExistPredSet) Canonical.makeCanonical(out);
return out;
}
}
- public boolean isSatisfiedBy( ReachGraph rg ) {
+ public Iterator<ExistPred> iterator() {
+ return preds.iterator();
+ }
+
+
+ // only consider the subest of the caller elements that
+ // are reachable by callee when testing predicates
+ public ExistPredSet isSatisfiedBy(ReachGraph rg,
+ Set<Integer> calleeReachableNodes,
+ Set<RefSrcNode> callerSrcMatches
+ ) {
+ // jjenista 1/17/2012
+ //
+ // this does not work to disable predicates, in fact the whole
+ // interprocedural context mapping system is built on predicates
+ // because edges and nodes that get renamed in the callee context
+ // have to be spliced back into the caller context, and the
+ // elements that cross the boundry are fused by matching
+ // predicates of callee elements to caller elements.
+ //
+ //if( DISABLE_PREDICATES ) {
+ // return ReachGraph.predsTrue;
+ //}
+
+ ExistPredSet predsOut = null;
+
Iterator<ExistPred> predItr = preds.iterator();
while( predItr.hasNext() ) {
- if( predItr.next().isSatisfiedBy( rg ) ) {
- return true;
+ ExistPredSet predsFromSatisfier =
+ predItr.next().isSatisfiedBy(rg,
+ calleeReachableNodes,
+ callerSrcMatches);
+
+ if( predsFromSatisfier != null ) {
+ if( predsOut == null ) {
+ predsOut = predsFromSatisfier;
+ } else {
+ predsOut = Canonical.join(predsOut,
+ predsFromSatisfier);
+ }
}
}
- return false;
+
+ return predsOut;
+ }
+
+
+ // this method returns the source node of any
+ // edge predicates in the set for the given graph
+ public Set<RefSrcNode> getEdgeSources( ReachGraph rg ) {
+ Set<RefSrcNode> out = new HashSet<RefSrcNode>();
+
+ for( ExistPred pred: preds ) {
+ RefSrcNode rsn = pred.getEdgeSource( rg );
+ if( rsn != null ) {
+ out.add( rsn );
+ }
+ }
+
+ return out;
+ }
+
+
+
+ public boolean isEmpty() {
+ return preds.isEmpty();
}
- public boolean equals( Object o ) {
+ public boolean equalsSpecific(Object o) {
if( o == null ) {
return false;
}
ExistPredSet eps = (ExistPredSet) o;
- return preds.equals( eps.preds );
+ return preds.equals(eps.preds);
}
return preds.hashCode();
}
-
+
+ public String toStringEscNewline() {
+ String s = "P[";
+
+ Iterator<ExistPred> predItr = preds.iterator();
+ while( predItr.hasNext() ) {
+ ExistPred pred = predItr.next();
+ s += pred.toString();
+ if( predItr.hasNext() ) {
+ s += " ||\\n";
+ }
+ }
+ s += "]";
+ return s;
+ }
+
+
public String toString() {
String s = "P[";
Iterator<ExistPred> predItr = preds.iterator();