bug fixes on the flow graph.
authoryeom <yeom>
Fri, 10 Aug 2012 23:54:56 +0000 (23:54 +0000)
committeryeom <yeom>
Fri, 10 Aug 2012 23:54:56 +0000 (23:54 +0000)
Robust/src/Analysis/SSJava/FlowGraph.java
Robust/src/Analysis/SSJava/LocationInference.java
Robust/src/Analysis/SSJava/NodeTupleSet.java
Robust/src/Analysis/SSJava/SSJavaLattice.java

index de7cf348057c97fc2bdb0a315d1a20c7930e275b..9018489c4b588108f9409bbc2a105f5baa5a5693 100644 (file)
@@ -160,7 +160,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);
index d28772bb818b1eefdf14f4237788cdda80aeb438..1294cf85604dc57a6de25f6de0671198f722db13 100644 (file)
@@ -478,28 +478,36 @@ public class LocationInference {
               VarDescriptor varDesc = (VarDescriptor) srcNodeTuple.get(0);
               classDesc = varDesc.getType().getClassDesc();
             }
-
             extractRelationFromFieldFlows(classDesc, srcNode, dstNode, 1);
 
-          } else if (srcNodeTuple.size() == 1 || dstNodeTuple.size() == 1) {
-            // for the method lattice, we need to look at the first element of
-            // NTuple<Descriptor>
-            // in this case, take a look at connected nodes at the local level
-            addRelationToLattice(md, methodLattice, methodInfo, srcNode, dstNode);
           } else {
-
-            if (!srcNode.getDescTuple().get(0).equals(dstNode.getDescTuple().get(0))) {
-              // in this case, take a look at connected nodes at the local level
-              addRelationToLattice(md, methodLattice, methodInfo, srcNode, dstNode);
-            } else {
-              Descriptor srcDesc = srcNode.getDescTuple().get(0);
-              Descriptor dstDesc = dstNode.getDescTuple().get(0);
-              recursivelyAddCompositeRelation(md, fg, methodInfo, srcNode, dstNode, srcDesc,
-                  dstDesc);
-              // recursiveAddRelationToLattice(1, md, srcNode, dstNode);
-            }
+            // value flow between local var - local var or local var - field
+            addRelationToLattice(md, methodLattice, methodInfo, srcNode, dstNode);
           }
 
+          // else if (srcNodeTuple.size() == 1 || dstNodeTuple.size() == 1) {
+          // // for the method lattice, we need to look at the first element of
+          // // NTuple<Descriptor>
+          // // in this case, take a look at connected nodes at the local level
+          // addRelationToLattice(md, methodLattice, methodInfo, srcNode,
+          // dstNode);
+          // } else {
+          // if
+          // (!srcNode.getDescTuple().get(0).equals(dstNode.getDescTuple().get(0)))
+          // {
+          // // in this case, take a look at connected nodes at the local level
+          // addRelationToLattice(md, methodLattice, methodInfo, srcNode,
+          // dstNode);
+          // } else {
+          // Descriptor srcDesc = srcNode.getDescTuple().get(0);
+          // Descriptor dstDesc = dstNode.getDescTuple().get(0);
+          // recursivelyAddCompositeRelation(md, fg, methodInfo, srcNode,
+          // dstNode, srcDesc,
+          // dstDesc);
+          // // recursiveAddRelationToLattice(1, md, srcNode, dstNode);
+          // }
+          // }
+
         }
       }
     }
@@ -823,7 +831,6 @@ public class LocationInference {
           generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(srcNode));
       CompositeLocation dstInferLoc =
           generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(dstNode));
-
       addRelation(methodLattice, methodInfo, srcInferLoc, dstInferLoc);
     } catch (CyclicFlowException e) {
       // there is a cyclic value flow... try to calculate a composite location
@@ -917,6 +924,7 @@ public class LocationInference {
       throws CyclicFlowException {
 
     Descriptor localVarDesc = flowNode.getDescTuple().get(0);
+    NTuple<Location> flowNodelocTuple = flowGraph.getLocationTuple(flowNode);
 
     if (localVarDesc.equals(methodInfo.getMethodDesc())) {
       return false;
@@ -1020,9 +1028,14 @@ public class LocationInference {
         SSJavaLattice<String> lattice = getLattice(desc);
         LocationInfo locInfo = getLocationInfo(desc);
 
-        CompositeLocation inferLocation = methodInfo.getInferLocation(localVarDesc);
+        CompositeLocation inferLocation =
+            generateInferredCompositeLocation(methodInfo, flowNodelocTuple);
+
+        // methodInfo.getInferLocation(localVarDesc);
         CompositeLocation newInferLocation = new CompositeLocation();
 
+        System.out.println("PREV INFER LOCATION=" + inferLocation + "             curPrefix="
+            + curPrefix);
         if (inferLocation.getTuple().startsWith(curPrefix)) {
           // the same infer location is already existed. no need to do
           // anything
@@ -1036,13 +1049,13 @@ public class LocationInference {
           for (int locIdx = 0; locIdx < curPrefix.size(); locIdx++) {
             newInferLocation.addLocation(curPrefix.get(locIdx));
           }
-          Location fieldLoc = new Location(desc, newLocSymbol);
-          newInferLocation.addLocation(fieldLoc);
+          Location newLocationElement = new Location(desc, newLocSymbol);
+          newInferLocation.addLocation(newLocationElement);
 
-          if (flowNode.getDescTuple().size() == 1) {
-            // maps local variable to location types of the common prefix
-            methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation.clone());
-          }
+          // if (flowNode.getDescTuple().size() == 1) {
+          // maps local variable to location types of the common prefix
+          methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation.clone());
+          // }
 
           // methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation);
           addMapLocSymbolToInferredLocation(methodInfo.getMethodDesc(), localVarDesc,
@@ -1144,8 +1157,6 @@ public class LocationInference {
                   flowGraph.getLocationTuple(localOutNode));
 
           if (isCompositeLocation(outNodeInferLoc)) {
-            // need to make sure that newLocSymbol is higher than the infernode
-            // location
             System.out.println("--- srcNode=" + flowNode + "  dstNode=" + localOutNode);
             addRelationToLattice(methodInfo.getMethodDesc(), methodLattice, methodInfo, flowNode,
                 localOutNode);
@@ -1873,7 +1884,6 @@ public class LocationInference {
 
     if (isLHS) {
       // need to create an edge from idx to array
-
       for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
         NTuple<Descriptor> idxTuple = idxIter.next();
         for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
@@ -2057,32 +2067,44 @@ public class LocationInference {
       }
     }
 
+    NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
     if (left instanceof ArrayAccessNode) {
 
       ArrayAccessNode aan = (ArrayAccessNode) left;
       left = aan.getExpression();
-      analyzeFlowExpressionNode(md, nametable, aan.getIndex(), nodeSet, base, implicitFlowTupleSet,
-          isLHS);
+      analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base,
+          implicitFlowTupleSet, isLHS);
+      nodeSet.addTupleSet(idxNodeTupleSet);
     }
-    // fanNodeSet
     base =
         analyzeFlowExpressionNode(md, nametable, left, nodeSet, base, implicitFlowTupleSet, isLHS);
+
     if (base == null) {
       // in this case, field is TOP location
       return null;
     } else {
 
+      NTuple<Descriptor> flowFieldTuple = new NTuple<Descriptor>(base.toList());
+
       if (!left.getType().isPrimitive()) {
 
         if (!fd.getSymbol().equals("length")) {
           // array.length access, just have the location of the array
-          base.add(fd);
+          flowFieldTuple.add(fd);
+          nodeSet.removeTuple(base);
         }
 
       }
+      getFlowGraph(md).createNewFlowNode(flowFieldTuple);
+
+      if (isLHS) {
+        for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
+          NTuple<Descriptor> idxTuple = idxIter.next();
+          getFlowGraph(md).addValueFlowEdge(idxTuple, flowFieldTuple);
+        }
+      }
 
-      getFlowGraph(md).createNewFlowNode(base);
-      return base;
+      return flowFieldTuple;
 
     }
 
index 3040a15ae80d8a2b5389020abcab6cb39fb062da..eaa0e6e9ae74d51c555d3af6c418b88bcda09a17 100644 (file)
@@ -28,6 +28,10 @@ public class NodeTupleSet {
     list.add(tuple);
   }
 
+  public void removeTuple(NTuple<Descriptor> tuple) {
+    list.remove(tuple);
+  }
+
   public Iterator<NTuple<Descriptor>> iterator() {
     return list.iterator();
   }
index 89ca9af541c0a4ee5ffbc4fcbe04a86b249c9872..e2c85f299c768dc678e7307992767f4abcc92a20 100644 (file)
@@ -91,7 +91,6 @@ public class SSJavaLattice<T> extends Lattice<T> {
         getInBetweenElements(cur, end, elementSet);
       }
     }
-    System.out.println("            start=" + start + " end=" + end + "   element=" + elementSet);
   }
 
   public void mergeIntoSharedLocation(Set<T> cycleSet, T newLoc) {