changes.
[IRC.git] / Robust / src / Analysis / SSJava / FlowGraph.java
index d4051fb508c497381b92ac8b3ae2db7c49a391a3..39d706144144bcbe0d35333d6d4b30794498305b 100644 (file)
@@ -34,6 +34,9 @@ public class FlowGraph {
 
   // maps a paramter descriptor to its index
   Map<Descriptor, Integer> mapParamDescToIdx;
+
+  Map<Integer, FlowNode> mapIdxToFlowNode;
+
   boolean debug = true;
 
   public FlowGraph(MethodDescriptor md, Map<Descriptor, Integer> mapParamDescToIdx) {
@@ -46,6 +49,7 @@ public class FlowGraph {
     this.mapParamDescToIdx = new HashMap<Descriptor, Integer>();
     this.mapParamDescToIdx.putAll(mapParamDescToIdx);
     this.returnNodeSet = new HashSet<FlowNode>();
+    this.mapIdxToFlowNode = new HashMap<Integer, FlowNode>();
 
     if (!md.isStatic()) {
       // create a node for 'this' varialbe
@@ -58,6 +62,25 @@ public class FlowGraph {
       thisVarNode = thisNode;
     }
 
+    setupMapIdxToDesc();
+
+  }
+
+  private void setupMapIdxToDesc() {
+
+    Set<Descriptor> descSet = mapParamDescToIdx.keySet();
+    for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
+      Descriptor paramDesc = (Descriptor) iterator.next();
+      int idx = mapParamDescToIdx.get(paramDesc);
+      NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
+      descTuple.add(paramDesc);
+      mapIdxToFlowNode.put(idx, getFlowNode(descTuple));
+    }
+
+  }
+
+  public FlowNode getParamFlowNode(int idx) {
+    return mapIdxToFlowNode.get(idx);
   }
 
   public Set<FlowNode> getNodeSet() {
@@ -89,6 +112,19 @@ public class FlowGraph {
     // System.out.println("add a new neighbor " + neighbor + " to " + node);
   }
 
+  public boolean isParamDesc(Descriptor desc) {
+
+    if (mapParamDescToIdx.containsKey(desc)) {
+      int idx = mapParamDescToIdx.get(desc);
+      if (!md.isStatic() && idx == 0) {
+        return false;
+      }
+      return true;
+    }
+
+    return false;
+  }
+
   public boolean hasEdge(NTuple<Descriptor> fromDescTuple, NTuple<Descriptor> toDescTuple) {
 
     FlowNode fromNode = mapDescTupleToInferNode.get(fromDescTuple);
@@ -160,7 +196,6 @@ public class FlowGraph {
   public FlowNode createNewFlowNode(NTuple<Descriptor> tuple) {
 
     if (!mapDescTupleToInferNode.containsKey(tuple)) {
-
       FlowNode node = new FlowNode(tuple, isParameter(tuple));
       mapDescTupleToInferNode.put(tuple, node);
       nodeSet.add(node);
@@ -180,7 +215,7 @@ public class FlowGraph {
 
   }
 
-  public void setReturnFlowNode(NTuple<Descriptor> tuple) {
+  public void addReturnFlowNode(NTuple<Descriptor> tuple) {
 
     if (!mapDescTupleToInferNode.containsKey(tuple)) {
       createNewFlowNode(tuple);
@@ -252,10 +287,12 @@ public class FlowGraph {
       Descriptor localDesc = fn.getDescTuple().get(0);
       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 topLoc = new Location(md, LocationInference.GLOBALLOC);
-        locTuple.add(topLoc);
+        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++) {