predicates are not feasible to flip on and off. The entire splicing mechanism for...
[IRC.git] / Robust / src / Analysis / Disjoint / ExistPredSet.java
index 124cec68316d81a0f1c98956336283fc00fbf17e..c45535a9df99e286eca38f245fdb29999add7f50 100644 (file)
@@ -29,19 +29,23 @@ import java.io.*;
 
 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;
   }
 
@@ -50,18 +54,76 @@ public class ExistPredSet extends Canonical {
   }
 
 
-  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;
     }
@@ -72,7 +134,7 @@ public class ExistPredSet extends Canonical {
 
     ExistPredSet eps = (ExistPredSet) o;
 
-    return preds.equals( eps.preds );
+    return preds.equals(eps.preds);
   }
 
 
@@ -80,7 +142,23 @@ public class ExistPredSet extends Canonical {
     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();