changes.
[IRC.git] / Robust / src / Analysis / SSJava / FlowGraph.java
index e81fe7d073b93b29fe094b4f6313b353ec9d724f..e2783bf60ca44f66ec9506deff8756c9ab3f3e1c 100644 (file)
@@ -95,18 +95,13 @@ public class FlowGraph {
     return mapParamDescToIdx;
   }
 
-  public FlowNode createIntermediateNode(MethodDescriptor md) {
-
+  public FlowNode createIntermediateNode() {
     NTuple<Descriptor> tuple = new NTuple<Descriptor>();
     Descriptor interDesc = new InterDescriptor(LocationInference.INTERLOC + interseed);
     tuple.add(interDesc);
     interseed++;
 
-    NTuple<Location> locTuple = new NTuple<Location>();
-    Location interLoc = new Location(md, interDesc);
-    locTuple.add(interLoc);
-
-    FlowNode newNode = new FlowNode(locTuple);
+    FlowNode newNode = new FlowNode(tuple);
     newNode.setIntermediate(true);
 
     mapDescTupleToInferNode.put(tuple, newNode);
@@ -140,6 +135,18 @@ public class FlowGraph {
     return mapIdxToFlowNode.get(idx);
   }
 
+  public Set<FlowEdge> getEdgeSet() {
+    Set<FlowEdge> edgeSet = new HashSet<FlowEdge>();
+
+    Set<FlowNode> nodeSet = getNodeSet();
+    for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
+      FlowNode flowNode = (FlowNode) iterator.next();
+      edgeSet.addAll(getOutEdgeSet(flowNode));
+    }
+
+    return edgeSet;
+  }
+
   public Set<FlowNode> getNodeSet() {
     Set<FlowNode> set = new HashSet<FlowNode>();
     set.addAll(mapDescTupleToInferNode.values());
@@ -279,10 +286,8 @@ public class FlowGraph {
 
   public FlowNode createNewFlowNode(NTuple<Descriptor> tuple) {
 
-    NTuple<Location> locTuple = translateToLocationTuple(tuple);
     if (!mapDescTupleToInferNode.containsKey(tuple)) {
-
-      FlowNode node = new FlowNode(locTuple);
+      FlowNode node = new FlowNode(tuple);
       mapDescTupleToInferNode.put(tuple, node);
       // nodeSet.add(node);
 
@@ -361,6 +366,20 @@ public class FlowGraph {
     return set;
   }
 
+  public Set<FlowNode> getReachableSetFrom(NTuple<Descriptor> prefix) {
+    Set<FlowNode> reachableSet = new HashSet<FlowNode>();
+
+    Set<FlowNode> nodeSet = getNodeSet();
+    for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
+      FlowNode flowNode = (FlowNode) iterator.next();
+      if (flowNode.getCurrentDescTuple().startsWith(prefix)) {
+        recurReachableSetFrom(flowNode, reachableSet);
+      }
+    }
+
+    return reachableSet;
+  }
+
   // private void getReachFlowNodeSetFrom(FlowNode fn, Set<FlowNode> visited) {
   //
   // for (Iterator iterator = fn.getOutEdgeSet().iterator();
@@ -380,6 +399,20 @@ public class FlowGraph {
   //
   // }
 
+  private void recurReachableSetFrom(FlowNode curNode, Set<FlowNode> reachableSet) {
+
+    Set<FlowEdge> edgeSet = getOutEdgeSet(curNode);
+    for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
+      FlowEdge edge = (FlowEdge) iterator.next();
+      FlowNode dstNode = getFlowNode(edge.getEndTuple());
+      if (!reachableSet.contains(dstNode)) {
+        reachableSet.add(dstNode);
+        recurReachableSetFrom(dstNode, reachableSet);
+      }
+    }
+
+  }
+
   public Set<NTuple<Location>> getReachableFlowTupleSet(Set<NTuple<Location>> visited, FlowNode fn) {
 
     Set<FlowEdge> outEdgeSet = getOutEdgeSet(fn);
@@ -387,7 +420,7 @@ public class FlowGraph {
     for (Iterator iterator = outEdgeSet.iterator(); iterator.hasNext();) {
       FlowEdge edge = (FlowEdge) iterator.next();
 
-      if (fn.getLocTuple().equals(edge.getInitTuple())) {
+      if (fn.getDescTuple().equals(edge.getInitTuple())) {
         FlowNode dstNode = getFlowNode(edge.getEndTuple());
         NTuple<Location> dstTuple = getLocationTuple(dstNode);
 
@@ -405,51 +438,6 @@ public class FlowGraph {
     return getLocationTuple(getFlowNode(descTuple));
   }
 
-  public NTuple<Location> translateToLocationTuple(NTuple<Descriptor> descTuple) {
-
-    NTuple<Location> locTuple = new NTuple<Location>();
-    ClassDescriptor cd = null;
-
-    Descriptor localDesc = descTuple.get(0);
-
-    if (localDesc instanceof InterDescriptor) {
-      Location interLoc = new Location(md, localDesc);
-      locTuple.add(interLoc);
-    } else if (localDesc.getSymbol().equals(LocationInference.TOPLOC)) {
-      Location topLoc = new Location(md, Location.TOP);
-      topLoc.setLocDescriptor(LocationInference.TOPDESC);
-      locTuple.add(topLoc);
-    } else if (localDesc.getSymbol().equals(LocationInference.GLOBALLOC)) {
-      Location globalLoc = new Location(md, LocationInference.GLOBALLOC);
-      globalLoc.setLocDescriptor(LocationInference.GLOBALDESC);
-      locTuple.add(globalLoc);
-    } else {
-      // normal case
-      for (int i = 0; i < descTuple.size(); i++) {
-        Descriptor curDesc = descTuple.get(i);
-        Location loc;
-        if (i == 0) {
-          loc = new Location(md, curDesc.getSymbol());
-          loc.setLocDescriptor(curDesc);
-          cd = ((VarDescriptor) curDesc).getType().getClassDesc();
-        } else {
-          loc = new Location(cd, curDesc.getSymbol());
-          loc.setLocDescriptor(curDesc);
-
-          if (curDesc instanceof FieldDescriptor) {
-            cd = ((FieldDescriptor) curDesc).getType().getClassDesc();
-          } else {
-            cd = ((LocationDescriptor) curDesc).getEnclosingClassDesc();
-          }
-
-        }
-        locTuple.add(loc);
-      }
-    }
-
-    return locTuple;
-  }
-
   public NTuple<Location> getLocationTuple(FlowNode fn) {
 
     if (!mapFlowNodeToLocTuple.containsKey(fn)) {
@@ -623,8 +611,8 @@ public class FlowGraph {
       FlowNode u = flowEdge.getSrc();
       FlowNode v = flowEdge.getDst();
 
-      if (u.getLocTuple().equals(flowEdge.getInitTuple())
-          && v.getLocTuple().equals(flowEdge.getEndTuple())) {
+      if (u.getDescTuple().equals(flowEdge.getInitTuple())
+          && v.getDescTuple().equals(flowEdge.getEndTuple())) {
         // only draw an edge of the actual value flow
 
         if (!addedEdgeSet.contains(flowEdge)) {
@@ -675,7 +663,7 @@ public class FlowGraph {
     while (iter.hasNext()) {
       FlowNode node = iter.next();
 
-      if (node.getLocTuple().size() == 1) {
+      if (node.getDescTuple().size() == 1) {
         // here, we just care about the local variable
         if (node.getFieldNodeSet().size() > 0) {
           drawSubgraph(node, bw, addedEdgeSet);