changes.
[IRC.git] / Robust / src / Analysis / SSJava / LocationInference.java
index 103faa85977101ae28962300a1a7cea4acf48c37..916016054b8cfe069e7f276b4db5ec069457c8f2 100644 (file)
@@ -152,6 +152,8 @@ public class LocationInference {
 
   public static int locSeed = 0;
 
+  private Stack<String> arrayAccessNodeStack;
+
   public LocationInference(SSJavaAnalysis ssjava, State state) {
     this.ssjava = ssjava;
     this.state = state;
@@ -193,6 +195,8 @@ public class LocationInference {
     this.mapMethodInvokeNodeToPCLocTupleSet =
         new HashMap<MethodInvokeNode, Set<NTuple<Location>>>();
 
+    this.arrayAccessNodeStack = new Stack<String>();
+
   }
 
   public void setupToAnalyze() {
@@ -243,14 +247,10 @@ public class LocationInference {
 
     constructGlobalFlowGraph();
 
-    do {
-      assignCompositeLocation();
-      updateFlowGraph();
-      calculateExtraLocations();
-      hasChanges = false;
-      addAdditionalOrderingConstraints();
-      System.out.println("&&&&&&&&&&&&&&&&&&&&&&has changes=" + hasChanges);
-    } while (hasChanges);
+    assignCompositeLocation();
+    updateFlowGraph();
+    calculateExtraLocations();
+    addAdditionalOrderingConstraints();
 
     _debug_writeFlowGraph();
 
@@ -414,12 +414,16 @@ public class LocationInference {
 
   private void translateCompositeLocationAssignmentToFlowGraph(MethodDescriptor mdCaller) {
 
+    System.out.println("\n\n###translateCompositeLocationAssignmentToFlowGraph mdCaller="
+        + mdCaller);
+
     // First, assign a composite location to a node in the flow graph
     GlobalFlowGraph callerGlobalFlowGraph = getSubGlobalFlowGraph(mdCaller);
 
     FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
     Map<Location, CompositeLocation> callerMapLocToCompLoc =
         callerGlobalFlowGraph.getMapLocationToInferCompositeLocation();
+
     Set<Location> methodLocSet = callerMapLocToCompLoc.keySet();
     for (Iterator iterator = methodLocSet.iterator(); iterator.hasNext();) {
       Location methodLoc = (Location) iterator.next();
@@ -437,8 +441,93 @@ public class LocationInference {
       // need to translate a composite location that is started with the base
       // tuple of 'min'.
       translateMapLocationToInferCompositeLocationToCalleeGraph(callerGlobalFlowGraph, min);
-      calleeSet.add(min.getMethod());
+      MethodDescriptor mdCallee = min.getMethod();
+      calleeSet.add(mdCallee);
+
+      FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
+
+      NTuple<Descriptor> methodInvokeBaseDescTuple = mapMethodInvokeNodeToBaseTuple.get(min);
+      NTuple<Location> methodInvokeBaseLocTuple = null;
+      if (methodInvokeBaseDescTuple != null) {
+        methodInvokeBaseLocTuple = translateToLocTuple(mdCaller, methodInvokeBaseDescTuple);
+      }
+
+      // ////////////////
+      // ////////////////
+
+      // If the location of an argument has a composite location
+      // need to assign a proper composite location to the corresponding callee parameter
+      // System.out.println("---translate arg composite location to callee param. min="
+      // + min.printNode(0));
+      Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
+      Set<Integer> idxSet = mapIdxToArgTuple.keySet();
+      for (Iterator iterator2 = idxSet.iterator(); iterator2.hasNext();) {
+        Integer idx = (Integer) iterator2.next();
+
+        if (idx == 0 && !min.getMethod().isStatic()) {
+          continue;
+        }
+
+        NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(idx);
+        if (argTuple.size() > 0) {
+          // check if an arg tuple has been already assigned to a composite location
+          NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argTuple);
+          Location argLocalLoc = argLocTuple.get(0);
+
+          // if (!isPrimitiveType(argTuple)) {
+          if (callerMapLocToCompLoc.containsKey(argLocalLoc)) {
+
+            CompositeLocation argLocalCompositeLocation = callerMapLocToCompLoc.get(argLocalLoc);
+            CompositeLocation argCompLoc = argLocalCompositeLocation.clone();
+            for (int i = 1; i < argLocTuple.size(); i++) {
+              argCompLoc.addLocation(argLocTuple.get(i));
+            }
+
+            FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
+
+            System.out
+                .println("----- argLocTuple=" + argLocTuple + "  argLocalLoc=+" + argLocalLoc);
+            System.out.println("-------need to translate argCompLoc=" + argCompLoc
+                + " with baseTuple=" + methodInvokeBaseLocTuple + "   calleeParamLocTuple="
+                + calleeParamFlowNode);
+
+            CompositeLocation paramCompLoc = translateArgCompLocToParamCompLoc(min, argCompLoc);
+            calleeParamFlowNode.setCompositeLocation(paramCompLoc);
+
+            // if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
+            //
+            // FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
+            // NTuple<Descriptor> calleeParamDescTuple = calleeParamFlowNode.getDescTuple();
+            // NTuple<Location> calleeParamLocTuple
+            // =###translateCompositeLocationAssignmentToFlowGraph mdCaller=public static void
+            // huffcodetab.huffman_decoder(int htIdx, int x, BitReserve br)
+
+            // translateToLocTuple(mdCallee, calleeParamDescTuple);
+            //
+            // System.out.println("---need to translate callerCompLoc=" + callerCompLoc
+            // + " with baseTuple=" + baseLocTuple + "   calleeParamLocTuple="
+            // + calleeParamLocTuple);
+            //
+            // CompositeLocation newCalleeCompLoc =
+            // translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
+            //
+            // calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
+            // newCalleeCompLoc);
+            //
+            // System.out.println("---callee loc=" + calleeParamLocTuple.get(0)
+            // + "  newCalleeCompLoc=" + newCalleeCompLoc);
+            //
+            // // System.out.println("###need to assign composite location to=" +
+            // // calleeParamDescTuple
+            // // + " with baseTuple=" + baseLocTuple);
+            // }
+
+          }
+        }
+      }
     }
+    // ////////////////
+    // ////////////////
 
     for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
       MethodDescriptor callee = (MethodDescriptor) iterator.next();
@@ -457,6 +546,46 @@ public class LocationInference {
 
   }
 
+  private CompositeLocation translateArgCompLocToParamCompLoc(MethodInvokeNode min,
+      CompositeLocation argCompLoc) {
+
+    System.out.println("--------translateArgCompLocToParamCompLoc argCompLoc=" + argCompLoc);
+    MethodDescriptor mdCallee = min.getMethod();
+    FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
+
+    NTuple<Location> argLocTuple = argCompLoc.getTuple();
+    Location argLocalLoc = argLocTuple.get(0);
+
+    Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
+    Set<Integer> idxSet = mapIdxToArgTuple.keySet();
+    for (Iterator iterator2 = idxSet.iterator(); iterator2.hasNext();) {
+      Integer idx = (Integer) iterator2.next();
+
+      if (idx == 0 && !min.getMethod().isStatic()) {
+        continue;
+      }
+
+      NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(idx);
+      if (argTuple.size() > 0 && argTuple.get(0).equals(argLocalLoc.getLocDescriptor())) {
+        // it matches with the current argument composite location
+        // so what is the corresponding parameter local descriptor?
+        FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
+        System.out.println("----------found paramNode=" + paramNode);
+        NTuple<Descriptor> paramDescTuple = paramNode.getCurrentDescTuple();
+
+        NTuple<Location> newParamTupleFromArgTuple = translateToLocTuple(mdCallee, paramDescTuple);
+        for (int i = 1; i < argLocTuple.size(); i++) {
+          newParamTupleFromArgTuple.add(argLocTuple.get(i));
+        }
+
+        System.out.println("-----------newParamTuple=" + newParamTupleFromArgTuple);
+        return new CompositeLocation(newParamTupleFromArgTuple);
+
+      }
+    }
+    return null;
+  }
+
   private void addAddtionalOrderingConstraints(MethodDescriptor mdCaller) {
 
     // First, assign a composite location to a node in the flow graph
@@ -481,7 +610,7 @@ public class LocationInference {
       // the corresponding argument in the caller is required to be higher than the translated
       // parameter location in the caller lattice
       // TODO
-      addOrderingConstraintFromCompLocParamToArg(mdCaller, min);
+      // addOrderingConstraintFromCompLocParamToArg(mdCaller, min);
 
       //
       // update return flow nodes in the caller
@@ -631,8 +760,8 @@ public class LocationInference {
       baseLocTuple = translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min));
     }
 
-    // System.out.println("\n-#translate caller=" + mdCaller + " infer composite loc to callee="
-    // + mdCallee + " baseLocTuple=" + baseLocTuple);
+    System.out.println("\n-#translate caller=" + mdCaller + " infer composite loc to callee="
+        + mdCallee + " baseLocTuple=" + baseLocTuple);
     // System.out.println("-mapIdxToArgTuple=" + mapIdxToArgTuple);
     // System.out.println("-callerMapLocToCompLoc=" + callerMapLocToCompLoc);
 
@@ -770,7 +899,8 @@ public class LocationInference {
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       Integer key = (Integer) iterator.next();
       NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(key);
-      if (translateToDescTuple(compLoc.getTuple()).startsWith(argTuple)) {
+      if (argTuple.size() > 0 && translateToDescTuple(compLoc.getTuple()).startsWith(argTuple)) {
+        System.out.println("compLoc.getTuple=" + compLoc + " is started with " + argTuple);
         return key.intValue();
       }
     }
@@ -893,7 +1023,8 @@ public class LocationInference {
 
             CompositeLocation newCompLoc = generateCompositeLocation(curPrefix);
             System.out.println("NEED TO ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix);
-            System.out.println("- newCompLoc=" + newCompLoc);
+            System.out.println("-targetLocalLoc=" + targetLocalLoc + "   - newCompLoc="
+                + newCompLoc);
             globalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc);
             // }
 
@@ -927,17 +1058,23 @@ public class LocationInference {
 
     Set<GlobalFlowNode> incomingNodeSetPrefix =
         graph.getIncomingNodeSetByPrefix(node.getLocTuple().get(0));
-    System.out.println("incomingNodeSetPrefix=" + incomingNodeSetPrefix);
+    // System.out.println("incomingNodeSetPrefix=" + incomingNodeSetPrefix);
 
     Set<GlobalFlowNode> reachableNodeSetPrefix =
         graph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
-    System.out.println("reachableNodeSetPrefix=" + reachableNodeSetPrefix);
+    // System.out.println("reachableNodeSetPrefix=" + reachableNodeSetPrefix);
 
     List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
 
     for (Iterator iterator = incomingNodeSetPrefix.iterator(); iterator.hasNext();) {
       GlobalFlowNode inNode = (GlobalFlowNode) iterator.next();
       NTuple<Location> inNodeTuple = inNode.getLocTuple();
+
+      if (inNodeTuple.get(0).getLocDescriptor() instanceof InterDescriptor
+          || inNodeTuple.get(0).getLocDescriptor().equals(GLOBALDESC)) {
+        continue;
+      }
+
       for (int i = 1; i < inNodeTuple.size(); i++) {
         NTuple<Location> prefix = inNodeTuple.subList(0, i);
         if (!prefixList.contains(prefix)) {
@@ -1039,6 +1176,11 @@ public class LocationInference {
       NTuple<Descriptor> srcDescTuple = edge.getInitTuple();
       NTuple<Descriptor> dstDescTuple = edge.getEndTuple();
 
+      if (flowGraph.getFlowNode(srcDescTuple) instanceof FlowReturnNode
+          || flowGraph.getFlowNode(dstDescTuple) instanceof FlowReturnNode) {
+        continue;
+      }
+
       // here only keep the first element(method location) of the descriptor
       // tuple
       NTuple<Location> srcLocTuple = translateToLocTuple(md, srcDescTuple);
@@ -1095,8 +1237,7 @@ public class LocationInference {
 
   }
 
-  private void addValueFlowsFromCalleeSubGlobalFlowGraph(MethodDescriptor mdCaller,
-      GlobalFlowGraph subGlobalFlowGraph) {
+  private void addValueFlowsFromCalleeSubGlobalFlowGraph(MethodDescriptor mdCaller) {
 
     // the transformation for a call site propagates flows through parameters
     // if the method is virtual, it also grab all relations from any possible
@@ -1129,12 +1270,13 @@ public class LocationInference {
   private void propagateValueFlowsToCallerFromSubGlobalFlowGraph(MethodInvokeNode min,
       MethodDescriptor mdCaller, MethodDescriptor possibleMdCallee) {
 
-    // System.out.println("---propagate from " + min.printNode(0) + " to caller=" + mdCaller);
+    System.out.println("---propagate from " + min.printNode(0) + " to caller=" + mdCaller);
     FlowGraph calleeFlowGraph = getFlowGraph(possibleMdCallee);
     Map<Integer, NTuple<Descriptor>> mapIdxToArg = mapMethodInvokeNodeToArgIdxMap.get(min);
 
-    // System.out.println("-----mapMethodInvokeNodeToArgIdxMap.get(min)="
-    // + mapMethodInvokeNodeToArgIdxMap.get(min));
+    System.out.println("-----mapMethodInvokeNodeToArgIdxMap.get(min)="
+        + mapMethodInvokeNodeToArgIdxMap.get(min));
+
     Set<Integer> keySet = mapIdxToArg.keySet();
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       Integer idx = (Integer) iterator.next();
@@ -1143,10 +1285,14 @@ public class LocationInference {
         NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
         NTuple<Descriptor> paramDescTuple = calleeFlowGraph.getParamFlowNode(idx).getDescTuple();
         NTuple<Location> paramLocTuple = translateToLocTuple(possibleMdCallee, paramDescTuple);
+        System.out.println("-------paramDescTuple=" + paramDescTuple + "->argDescTuple="
+            + argDescTuple);
         addMapCallerArgToCalleeParam(min, argDescTuple, paramDescTuple);
       }
     }
 
+    // addValueFlowBetweenParametersToCaller(min, mdCaller, possibleMdCallee);
+
     NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
     GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(possibleMdCallee);
     Set<GlobalFlowNode> calleeNodeSet = calleeSubGlobalGraph.getNodeSet();
@@ -1155,6 +1301,130 @@ public class LocationInference {
       addValueFlowFromCalleeNode(min, mdCaller, possibleMdCallee, calleeNode);
     }
 
+    System.out.println("$$$GLOBAL PC LOC ADD=" + mdCaller);
+    Set<NTuple<Location>> pcLocTupleSet = mapMethodInvokeNodeToPCLocTupleSet.get(min);
+    System.out.println("---pcLocTupleSet=" + pcLocTupleSet);
+    GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
+    for (Iterator iterator = calleeNodeSet.iterator(); iterator.hasNext();) {
+      GlobalFlowNode calleeNode = (GlobalFlowNode) iterator.next();
+      if (calleeNode.isParamNodeWithIncomingFlows()) {
+        NTuple<Location> callerSrcNodeLocTuple =
+            translateToCallerLocTuple(min, possibleMdCallee, mdCaller, calleeNode.getLocTuple());
+        System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple);
+        if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
+          for (Iterator iterator2 = pcLocTupleSet.iterator(); iterator2.hasNext();) {
+            NTuple<Location> pcLocTuple = (NTuple<Location>) iterator2.next();
+            callerSubGlobalGraph.addValueFlowEdge(pcLocTuple, callerSrcNodeLocTuple);
+          }
+        }
+      }
+
+    }
+
+  }
+
+  private void addValueFlowBetweenParametersToCaller(MethodInvokeNode min,
+      MethodDescriptor mdCaller, MethodDescriptor mdCallee) {
+
+    System.out.println("***addValueFlowBetweenParametersToCaller from mdCallee=" + mdCallee);
+
+    Set<NTuple<Location>> PCLocTupleSet = mapMethodInvokeNodeToPCLocTupleSet.get(min);
+    System.out.println("-PCLocTupleSet=" + PCLocTupleSet);
+
+    GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee);
+    GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
+
+    // if the parameter A reaches to the parameter B
+    // then, add an edge the argument A -> the argument B to the global flow graph
+    FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
+    FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
+    int numParam = calleeFlowGraph.getNumParameters();
+
+    for (int i = 0; i < numParam; i++) {
+      for (int k = 0; k < numParam; k++) {
+
+        if (i != k) {
+
+          System.out.println("i=" + i + " k=" + k);
+
+          FlowNode paramNode1 = calleeFlowGraph.getParamFlowNode(i);
+          FlowNode paramNode2 = calleeFlowGraph.getParamFlowNode(k);
+
+          NTuple<Descriptor> arg1Tuple = getNodeTupleByArgIdx(min, i);
+          NTuple<Descriptor> arg2Tuple = getNodeTupleByArgIdx(min, k);
+
+          NTuple<Descriptor> paramDescTuple1 = paramNode1.getCurrentDescTuple();
+          NTuple<Descriptor> paramDescTuple2 = paramNode2.getCurrentDescTuple();
+
+          if (paramDescTuple1.get(0).equals(paramDescTuple2.get(0))) {
+            // if two parameters share the same prefix
+            // it already has been assigned to a composite location
+            // so we don't need to add an additional ordering relation caused by these two
+            // paramters.
+            continue;
+          }
+
+          NTuple<Location> paramLocTuple1 = translateToLocTuple(mdCallee, paramDescTuple1);
+          NTuple<Location> paramLocTuple2 = translateToLocTuple(mdCallee, paramDescTuple2);
+
+          // check if the callee propagates an ordering constraints through
+          // parameters
+
+          // Set<FlowNode> localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
+
+          Set<GlobalFlowNode> reachToParam1Set =
+              calleeSubGlobalGraph.getIncomingNodeSetByPrefix(paramLocTuple1.get(0));
+
+          // System.out.println("-- localReachSet from param1=" + localReachSet);
+
+          GlobalFlowNode globalFlowNodeParam1 = calleeSubGlobalGraph.getFlowNode(paramLocTuple1);
+          GlobalFlowNode globalFlowNodeParam2 = calleeSubGlobalGraph.getFlowNode(paramLocTuple2);
+
+          System.out.println("-param1CurTuple=" + paramDescTuple1 + " param2CurTuple="
+              + paramDescTuple2);
+
+          System.out.println("arg1Tuple=" + arg1Tuple + "   arg2Tuple=" + arg2Tuple);
+          // System.out.println("-reachToParam1Set=" + reachToParam1Set);
+
+          if (arg1Tuple.size() > 0 && arg2Tuple.size() > 0
+              && reachToParam1Set.contains(globalFlowNodeParam2)) {
+            // need to propagate an ordering relation s.t. arg1 is higher
+            // than arg2
+            System.out.println("---param1=" + paramNode1 + " is higher than param2=" + paramNode2);
+
+            NTuple<Location> callerSrcNodeLocTuple =
+                translateToCallerLocTuple(min, mdCallee, mdCaller, paramLocTuple1);
+
+            NTuple<Location> callerDstNodeLocTuple =
+                translateToCallerLocTuple(min, mdCallee, mdCaller, paramLocTuple2);
+
+            System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple);
+            System.out.println("---callerDstNodeLocTuple=" + callerDstNodeLocTuple);
+
+            System.out.println("-----add global value flow :" + callerSrcNodeLocTuple + "->"
+                + callerDstNodeLocTuple);
+            callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple);
+            for (Iterator iterator = PCLocTupleSet.iterator(); iterator.hasNext();) {
+              NTuple<Location> pcLocTuple = (NTuple<Location>) iterator.next();
+              System.out.println("-----add global value flow PC :" + pcLocTuple + "->"
+                  + callerSrcNodeLocTuple);
+              callerSubGlobalGraph.addValueFlowEdge(pcLocTuple, callerSrcNodeLocTuple);
+            }
+
+            // add a new flow between the corresponding arguments.
+            callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple);
+            System.out.println("arg1=" + arg1Tuple + "   arg2=" + arg2Tuple);
+
+            // System.out
+            // .println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple);
+
+          }
+
+          System.out.println();
+        }
+      }
+    }
+
   }
 
   private void addValueFlowFromCalleeNode(MethodInvokeNode min, MethodDescriptor mdCaller,
@@ -1163,16 +1433,22 @@ public class LocationInference {
     GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee);
     GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
 
+    System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode);
+
     NTuple<Location> callerSrcNodeLocTuple =
         translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple());
+    System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple);
+
+    if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
 
-    if (callerSrcNodeLocTuple != null) {
       Set<GlobalFlowNode> outNodeSet = calleeSubGlobalGraph.getOutNodeSet(calleeSrcNode);
 
       for (Iterator iterator = outNodeSet.iterator(); iterator.hasNext();) {
         GlobalFlowNode outNode = (GlobalFlowNode) iterator.next();
         NTuple<Location> callerDstNodeLocTuple =
             translateToCallerLocTuple(min, mdCallee, mdCaller, outNode.getLocTuple());
+        // System.out.println("outNode=" + outNode + "   callerDstNodeLocTuple="
+        // + callerDstNodeLocTuple);
         if (callerDstNodeLocTuple != null) {
           callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple);
         }
@@ -1193,10 +1469,10 @@ public class LocationInference {
       int paramIdx = calleeFlowGraph.getParamIdx(nodeDescTuple);
       NTuple<Descriptor> argDescTuple = mapMethodInvokeNodeToArgIdxMap.get(min).get(paramIdx);
 
-      if (isPrimitive(nodeLocTuple.get(0).getLocDescriptor())) {
-        // the type of argument is primitive.
-        return nodeLocTuple.clone();
-      }
+      // if (isPrimitive(nodeLocTuple.get(0).getLocDescriptor())) {
+      // // the type of argument is primitive.
+      // return nodeLocTuple.clone();
+      // }
       NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
 
       NTuple<Location> callerLocTuple = new NTuple<Location>();
@@ -1503,7 +1779,7 @@ public class LocationInference {
     Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       Descriptor desc = (Descriptor) iterator.next();
-      System.out.println("SSJAVA: remove redundant edges: " + desc);
+      // System.out.println("SSJAVA: remove redundant edges: " + desc);
       HierarchyGraph simpleHierarchyGraph = getHierarchyGraph(desc).clone();
       simpleHierarchyGraph.setName(desc + "_SIMPLE");
       simpleHierarchyGraph.removeRedundantEdges();
@@ -2097,6 +2373,9 @@ public class LocationInference {
                 String orgSourceLine = sourceVec.get(varLineNum);
                 int idx =
                     orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
+                System.out.println("idx=" + idx
+                    + "  generateVarDeclaration((VarDescriptor) localVarDesc)="
+                    + generateVarDeclaration((VarDescriptor) localVarDesc));
                 assert (idx != -1);
                 String annoatedStr =
                     orgSourceLine.substring(0, idx) + locAnnotationStr + " "
@@ -2448,10 +2727,10 @@ public class LocationInference {
       }
     }
 
-    // System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet);
+    System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet);
 
     if (paramLocTupleHavingInFlowSet.size() > 0
-    /* && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet) */) {
+        && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) {
 
       // Here, generates a location in the method lattice that is higher than the
       // paramLocTupleHavingInFlowSet
@@ -2550,8 +2829,8 @@ public class LocationInference {
         NTuple<Descriptor> returnDescTuple = returnNode.getCurrentDescTuple();
         tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, returnDescTuple));
       }
-      // System.out.println("-flow graph's returnNodeSet=" + returnNodeSet);
-      // System.out.println("tupleSetToBeHigherThanReturnLoc=" + tupleToBeHigherThanReturnLocSet);
+      System.out.println("-flow graph's returnNodeSet=" + returnNodeSet);
+      System.out.println("tupleSetToBeHigherThanReturnLoc=" + tupleToBeHigherThanReturnLocSet);
 
       // Here, generates a return location in the method lattice that is lower than the
       // locFlowingToReturnValueSet
@@ -2647,6 +2926,7 @@ public class LocationInference {
           break;
         }
         Location newLocElement = new Location(curLoc.getDescriptor(), curLoc.getLocDescriptor());
+        System.out.println("newLocElement" + newLocElement);
         higherLocTuple.add(newLocElement);
         enclosingDesc = getClassTypeDescriptor(curLoc.getLocDescriptor());
       }
@@ -2657,7 +2937,6 @@ public class LocationInference {
     NameDescriptor pcLocDesc = new NameDescriptor(pcLocIdentifier);
     Location newLoc = new Location(enclosingDesc, pcLocDesc);
     higherLocTuple.add(newLoc);
-
     System.out.println("---new loc tuple=" + higherLocTuple);
 
     return higherLocTuple;
@@ -3034,52 +3313,6 @@ public class LocationInference {
 
   }
 
-  private List<NTuple<Descriptor>> calculatePrefixList(FlowGraph flowGraph, FlowNode flowNode) {
-
-    System.out.println("\n##### calculatePrefixList=" + flowNode);
-
-    Set<FlowNode> inNodeSet = flowGraph.getIncomingFlowNodeSet(flowNode);
-    inNodeSet.add(flowNode);
-
-    System.out.println("inNodeSet=" + inNodeSet);
-
-    List<NTuple<Descriptor>> prefixList = new ArrayList<NTuple<Descriptor>>();
-
-    for (Iterator iterator = inNodeSet.iterator(); iterator.hasNext();) {
-      FlowNode inNode = (FlowNode) iterator.next();
-
-      NTuple<Descriptor> inNodeTuple = inNode.getCurrentDescTuple();
-
-      // CompositeLocation inNodeInferredLoc =
-      // generateInferredCompositeLocation(methodInfo, inNodeTuple);
-      // NTuple<Location> inNodeInferredLocTuple = inNodeInferredLoc.getTuple();
-
-      for (int i = 1; i < inNodeTuple.size(); i++) {
-        NTuple<Descriptor> prefix = inNodeTuple.subList(0, i);
-        if (!prefixList.contains(prefix)) {
-          prefixList.add(prefix);
-        }
-      }
-    }
-
-    Collections.sort(prefixList, new Comparator<NTuple<Descriptor>>() {
-      public int compare(NTuple<Descriptor> arg0, NTuple<Descriptor> arg1) {
-        int s0 = arg0.size();
-        int s1 = arg1.size();
-        if (s0 > s1) {
-          return -1;
-        } else if (s0 == s1) {
-          return 0;
-        } else {
-          return 1;
-        }
-      }
-    });
-
-    return prefixList;
-
-  }
-
   public CompositeLocation convertToCompositeLocation(MethodDescriptor md, NTuple<Descriptor> tuple) {
 
     CompositeLocation compLoc = new CompositeLocation();
@@ -3430,17 +3663,42 @@ public class LocationInference {
         System.out.println();
         System.out.println("SSJAVA: Constructing a sub global flow graph: " + md);
 
-        GlobalFlowGraph subGlobalFlowGraph = constructSubGlobalFlowGraph(getFlowGraph(md));
+        constructSubGlobalFlowGraph(getFlowGraph(md));
 
         // TODO
         System.out.println("-add Value Flows From CalleeSubGlobalFlowGraph");
-        addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph);
+        addValueFlowsFromCalleeSubGlobalFlowGraph(md);
         // subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
 
         // System.out.println("-propagate Flows From Callees With No CompositeLocation");
         // propagateFlowsFromCalleesWithNoCompositeLocation(md);
 
+        // mark if a parameter has incoming flows
+        checkParamNodesInSubGlobalFlowGraph(md);
+
+      }
+    }
+  }
+
+  private void checkParamNodesInSubGlobalFlowGraph(MethodDescriptor md) {
+    GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
+    FlowGraph flowGraph = getFlowGraph(md);
+
+    Set<FlowNode> paramFlowNodeSet = flowGraph.getParamFlowNodeSet();
+    for (Iterator iterator = paramFlowNodeSet.iterator(); iterator.hasNext();) {
+      FlowNode paramFlowNode = (FlowNode) iterator.next();
+      System.out.println("paramFlowNode=" + paramFlowNode);
+      NTuple<Descriptor> paramDescTuple = paramFlowNode.getDescTuple();
+      NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
+      GlobalFlowNode paramGlobalNode = globalFlowGraph.getFlowNode(paramLocTuple);
+
+      Set<GlobalFlowNode> incomingNodeSet =
+          globalFlowGraph.getIncomingNodeSetByPrefix(paramLocTuple.get(0));
+
+      if (incomingNodeSet.size() > 0) {
+        paramGlobalNode.setParamNodeWithIncomingFlows(true);
       }
+
     }
   }
 
@@ -3687,6 +3945,9 @@ public class LocationInference {
       newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
       newImplicitTupleSet.addTupleSet(condTupleNode);
 
+      newImplicitTupleSet.addGlobalFlowTupleSet(implicitFlowTupleSet.getGlobalLocTupleSet());
+      newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
+
       if (needToGenerateInterLoc(newImplicitTupleSet)) {
         // need to create an intermediate node for the GLB of conditional
         // locations & implicit flows
@@ -3807,12 +4068,12 @@ public class LocationInference {
     newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
     newImplicitTupleSet.addTupleSet(condTupleNode);
 
+    // System.out.println("$$$GGGcondTupleNode=" + condTupleNode.getGlobalLocTupleSet());
     // System.out.println("-condTupleNode=" + condTupleNode);
     // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
     // System.out.println("-newImplicitTupleSet=" + newImplicitTupleSet);
 
     if (needToGenerateInterLoc(newImplicitTupleSet)) {
-      System.out.println("2");
       // need to create an intermediate node for the GLB of conditional locations & implicit flows
       NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
       for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
@@ -3823,6 +4084,18 @@ public class LocationInference {
       newImplicitTupleSet.addTuple(interTuple);
     }
 
+    // GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
+    // for (Iterator<NTuple<Location>> iterator = condTupleNode.globalIterator();
+    // iterator.hasNext();) {
+    // NTuple<Location> calleeReturnLocTuple = iterator.next();
+    // for (Iterator<NTuple<Descriptor>> iter2 = newImplicitTupleSet.iterator(); iter2.hasNext();) {
+    // NTuple<Descriptor> callerImplicitTuple = iter2.next();
+    // globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
+    // translateToLocTuple(md, callerImplicitTuple));
+    // }
+    // }
+    newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
+
     analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet);
 
     if (isn.getFalseBlock() != null) {
@@ -3865,6 +4138,12 @@ public class LocationInference {
         addFlowGraphEdge(md, implicitTuple, tupleLHS);
       }
 
+      GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
+      for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
+        NTuple<Location> calleeReturnLocTuple = iterator.next();
+        globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS));
+      }
+
     }
 
   }
@@ -3887,9 +4166,7 @@ public class LocationInference {
     // note that expression node can create more than one flow node
     // nodeSet contains of flow nodes
     // base is always assigned to null except the case of a name node!
-
     NTuple<Descriptor> flowTuple;
-
     switch (en.kind()) {
 
     case Kind.AssignmentNode:
@@ -3961,6 +4238,7 @@ public class LocationInference {
     // return null;
 
     }
+
     return null;
 
   }
@@ -4029,12 +4307,19 @@ public class LocationInference {
   private void analyzeFlowMethodInvokeNode(MethodDescriptor mdCaller, SymbolTable nametable,
       MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
 
-    // System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0));
+    System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0));
+
+    if (!toanalyze_methodDescList.contains(min.getMethod())) {
+      return;
+    }
 
     Set<NTuple<Location>> pcLocTupleSet = getPCLocTupleSet(min);
     for (Iterator iterator = implicitFlowTupleSet.iterator(); iterator.hasNext();) {
       NTuple<Descriptor> pcDescTuple = (NTuple<Descriptor>) iterator.next();
-      pcLocTupleSet.add(translateToLocTuple(mdCaller, pcDescTuple));
+      if (!pcDescTuple.get(0).equals(LITERALDESC)) {
+        // here we don't need to add the literal value as a PC location
+        pcLocTupleSet.add(translateToLocTuple(mdCaller, pcDescTuple));
+      }
     }
 
     mapMethodInvokeNodeToArgIdxMap.put(min, new HashMap<Integer, NTuple<Descriptor>>());
@@ -4057,7 +4342,7 @@ public class LocationInference {
       addMapCallerMethodDescToMethodInvokeNodeSet(mdCaller, min);
 
       FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
-
+      System.out.println("mdCallee=" + mdCallee);
       Set<FlowNode> calleeReturnSet = calleeFlowGraph.getReturnNodeSet();
 
       System.out.println("---calleeReturnSet=" + calleeReturnSet);
@@ -4072,7 +4357,7 @@ public class LocationInference {
         nodeSet.addGlobalFlowTuple(calleeReturnLocTuple);
       }
 
-      FlowReturnNode setNode = getFlowGraph(mdCaller).createReturnNode(min);
+      NodeTupleSet tupleSet = new NodeTupleSet();
 
       if (min.getExpression() != null) {
 
@@ -4096,7 +4381,7 @@ public class LocationInference {
               NTuple<Descriptor> inFlowTuple = new NTuple<Descriptor>(baseTuple.getList());
               inFlowTuple.addAll(returnDescTuple.subList(1, returnDescTuple.size()));
               // nodeSet.addTuple(inFlowTuple);
-              setNode.addTuple(inFlowTuple);
+              tupleSet.addTuple(inFlowTuple);
             } else {
               // TODO
               Set<FlowNode> inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode);
@@ -4105,7 +4390,7 @@ public class LocationInference {
                 FlowNode inFlowNode = (FlowNode) iterator2.next();
                 if (inFlowNode.getDescTuple().startsWith(mdCallee.getThis())) {
                   // nodeSet.addTupleSet(baseNodeSet);
-                  setNode.addTupleSet(baseNodeSet);
+                  tupleSet.addTupleSet(baseNodeSet);
 
                 }
               }
@@ -4131,20 +4416,21 @@ public class LocationInference {
           NodeTupleSet argTupleSet = new NodeTupleSet();
           analyzeFlowExpressionNode(mdCaller, nametable, en, argTupleSet, false);
           // if argument is liternal node, argTuple is set to NULL
-
-          NTuple<Descriptor> argTuple = new NTuple<Descriptor>();
-          if (needToGenerateInterLoc(argTupleSet)) {
+          System.out.println("argTupleSet=" + argTupleSet);
+          NTuple<Descriptor> argTuple = generateArgTuple(mdCaller, argTupleSet);
+
+          // if an argument is literal value,
+          // we need to create an itermediate node so that we could assign a composite location to
+          // that node if needed
+          if (argTuple.size() > 0
+              && (argTuple.get(0).equals(GLOBALDESC) || argTuple.get(0).equals(LITERALDESC))) {
+            System.out.println("***GLOBAL ARG TUPLE CASE=" + argTuple);
             NTuple<Descriptor> interTuple =
                 getFlowGraph(mdCaller).createIntermediateNode().getDescTuple();
-            for (Iterator<NTuple<Descriptor>> idxIter = argTupleSet.iterator(); idxIter.hasNext();) {
-              NTuple<Descriptor> tuple = idxIter.next();
-              addFlowGraphEdge(mdCaller, tuple, interTuple);
-            }
+            addFlowGraphEdge(mdCaller, argTuple, interTuple);
             argTuple = interTuple;
-          } else if (argTupleSet.size() == 1) {
-            argTuple = argTupleSet.iterator().next();
-          } else {
-            argTuple = new NTuple<Descriptor>();
+            addArgIdxMap(min, idx, argTuple);
+            System.out.println("new min mapping i=" + idx + "  ->" + argTuple);
           }
 
           addArgIdxMap(min, idx, argTuple);
@@ -4167,13 +4453,17 @@ public class LocationInference {
               || mdCallee.getModifiers().isNative()) {
             addParamNodeFlowingToReturnValue(mdCallee, paramNode);
             // nodeSet.addTupleSet(argTupleSet);
-            setNode.addTupleSet(argTupleSet);
+            tupleSet.addTupleSet(argTupleSet);
           }
         }
 
       }
 
-      nodeSet.addTuple(setNode.getDescTuple());
+      if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) {
+        FlowReturnNode setNode = getFlowGraph(mdCaller).createReturnNode(min);
+        nodeSet.addTuple(setNode.getDescTuple());
+      }
+
       // propagateFlowsFromCallee(min, md, min.getMethod());
 
       System.out.println("min nodeSet=" + nodeSet);
@@ -4181,6 +4471,42 @@ public class LocationInference {
 
   }
 
+  private NTuple<Descriptor> generateArgTuple(MethodDescriptor mdCaller, NodeTupleSet argTupleSet) {
+
+    int size = 0;
+
+    // if argTupleSet is empty, it comes from the top location
+    if (argTupleSet.size() == 0) {
+      NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
+      descTuple.add(LITERALDESC);
+      return descTuple;
+    }
+
+    Set<NTuple<Descriptor>> argTupleSetNonLiteral = new HashSet<NTuple<Descriptor>>();
+
+    for (Iterator<NTuple<Descriptor>> iter = argTupleSet.iterator(); iter.hasNext();) {
+      NTuple<Descriptor> descTuple = iter.next();
+      if (!descTuple.get(0).equals(LITERALDESC)) {
+        argTupleSetNonLiteral.add(descTuple);
+      }
+    }
+
+    if (argTupleSetNonLiteral.size() > 1) {
+      NTuple<Descriptor> interTuple =
+          getFlowGraph(mdCaller).createIntermediateNode().getDescTuple();
+      for (Iterator<NTuple<Descriptor>> idxIter = argTupleSet.iterator(); idxIter.hasNext();) {
+        NTuple<Descriptor> tuple = idxIter.next();
+        addFlowGraphEdge(mdCaller, tuple, interTuple);
+      }
+      return interTuple;
+    } else if (argTupleSetNonLiteral.size() == 1) {
+      return argTupleSetNonLiteral.iterator().next();
+    } else {
+      return argTupleSet.iterator().next();
+    }
+
+  }
+
   private boolean hasInFlowTo(FlowGraph fg, FlowNode inNode, Set<FlowNode> nodeSet) {
     // return true if inNode has in-flows to nodeSet
 
@@ -4223,6 +4549,10 @@ public class LocationInference {
   private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable,
       ArrayAccessNode aan, NodeTupleSet nodeSet, boolean isLHS) {
 
+    // System.out.println("analyzeFlowArrayAccessNode aan=" + aan.printNode(0));
+    String currentArrayAccessNodeExpStr = aan.printNode(0);
+    arrayAccessNodeStack.push(aan.printNode(0));
+
     NodeTupleSet expNodeTupleSet = new NodeTupleSet();
     NTuple<Descriptor> base =
         analyzeFlowExpressionNode(md, nametable, aan.getExpression(), expNodeTupleSet, isLHS);
@@ -4230,6 +4560,8 @@ public class LocationInference {
     NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
     analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, isLHS);
 
+    arrayAccessNodeStack.pop();
+
     if (isLHS) {
       // need to create an edge from idx to array
       for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
@@ -4240,6 +4572,16 @@ public class LocationInference {
         }
       }
 
+      GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
+      for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
+          .hasNext();) {
+        NTuple<Location> calleeReturnLocTuple = iterator.next();
+        for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
+          NTuple<Descriptor> arrTuple = arrIter.next();
+          globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, arrTuple));
+        }
+      }
+
       nodeSet.addTupleSet(expNodeTupleSet);
     } else {
 
@@ -4248,19 +4590,26 @@ public class LocationInference {
       nodeSetArrayAccessExp.addTupleSet(expNodeTupleSet);
       nodeSetArrayAccessExp.addTupleSet(idxNodeTupleSet);
 
-      if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
-        NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
+      if (arrayAccessNodeStack.isEmpty()
+          || !arrayAccessNodeStack.peek().startsWith(currentArrayAccessNodeExpStr)) {
+
+        if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
+          NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
 
-        for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter.hasNext();) {
-          NTuple<Descriptor> higherTuple = iter.next();
-          addFlowGraphEdge(md, higherTuple, interTuple);
+          for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter.hasNext();) {
+            NTuple<Descriptor> higherTuple = iter.next();
+            addFlowGraphEdge(md, higherTuple, interTuple);
+          }
+          nodeSetArrayAccessExp.clear();
+          nodeSetArrayAccessExp.addTuple(interTuple);
         }
-        nodeSetArrayAccessExp.clear();
-        nodeSetArrayAccessExp.addTuple(interTuple);
       }
 
+      nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
       nodeSet.addTupleSet(nodeSetArrayAccessExp);
+
     }
+
   }
 
   private void analyzeCreateObjectNode(MethodDescriptor md, SymbolTable nametable,
@@ -4321,6 +4670,10 @@ public class LocationInference {
       // there are two operands
       nodeSet.addTupleSet(leftOpSet);
       nodeSet.addTupleSet(rightOpSet);
+
+      nodeSet.addGlobalFlowTupleSet(leftOpSet.getGlobalLocTupleSet());
+      nodeSet.addGlobalFlowTupleSet(rightOpSet.getGlobalLocTupleSet());
+
       break;
 
     default:
@@ -4412,10 +4765,13 @@ public class LocationInference {
   private NTuple<Descriptor> analyzeFlowFieldAccessNode(MethodDescriptor md, SymbolTable nametable,
       FieldAccessNode fan, NodeTupleSet nodeSet, NTuple<Descriptor> base,
       NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
+    // System.out.println("analyzeFlowFieldAccessNode=" + fan.printNode(0));
 
+    String currentArrayAccessNodeExpStr = null;
     ExpressionNode left = fan.getExpression();
     TypeDescriptor ltd = left.getType();
     FieldDescriptor fd = fan.getField();
+    ArrayAccessNode aan = null;
 
     String varName = null;
     if (left.kind() == Kind.NameNode) {
@@ -4432,9 +4788,15 @@ public class LocationInference {
 
     NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
 
+    boolean isArrayCase = false;
     if (left instanceof ArrayAccessNode) {
 
-      ArrayAccessNode aan = (ArrayAccessNode) left;
+      isArrayCase = true;
+      aan = (ArrayAccessNode) left;
+
+      currentArrayAccessNodeExpStr = aan.printNode(0);
+      arrayAccessNodeStack.push(currentArrayAccessNodeExpStr);
+
       left = aan.getExpression();
       analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base,
           implicitFlowTupleSet, isLHS);
@@ -4452,13 +4814,11 @@ public class LocationInference {
       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
           flowFieldTuple.add(fd);
           nodeSet.removeTuple(base);
         }
-
       }
       getFlowGraph(md).createNewFlowNode(flowFieldTuple);
 
@@ -4467,9 +4827,47 @@ public class LocationInference {
           NTuple<Descriptor> idxTuple = idxIter.next();
           getFlowGraph(md).addValueFlowEdge(idxTuple, flowFieldTuple);
         }
+
+        GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
+        for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
+            .hasNext();) {
+          NTuple<Location> calleeReturnLocTuple = iterator.next();
+          globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
+              translateToLocTuple(md, flowFieldTuple));
+        }
+
+      } else {
+
+        // if it is the array case and not the LHS case
+        if (isArrayCase) {
+          arrayAccessNodeStack.pop();
+
+          if (arrayAccessNodeStack.isEmpty()
+              || !arrayAccessNodeStack.peek().startsWith(currentArrayAccessNodeExpStr)) {
+            NodeTupleSet nodeSetArrayAccessExp = new NodeTupleSet();
+
+            nodeSetArrayAccessExp.addTuple(flowFieldTuple);
+            nodeSetArrayAccessExp.addTupleSet(idxNodeTupleSet);
+
+            if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
+              NTuple<Descriptor> interTuple =
+                  getFlowGraph(md).createIntermediateNode().getDescTuple();
+
+              for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter
+                  .hasNext();) {
+                NTuple<Descriptor> higherTuple = iter.next();
+                addFlowGraphEdge(md, higherTuple, interTuple);
+              }
+              flowFieldTuple = interTuple;
+            }
+
+            nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
+          }
+
+        }
+
       }
       return flowFieldTuple;
-
     }
 
   }
@@ -4545,17 +4943,27 @@ public class LocationInference {
       }
 
       // create global flow edges if the callee gives return value flows to the caller
-      if (nodeSetRHS.globalLocTupleSize() > 0) {
-        GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
-        for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
-          NTuple<Location> calleeReturnLocTuple = iterator.next();
-          for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
-            NTuple<Descriptor> callerLHSTuple = iter2.next();
-            globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
-                translateToLocTuple(md, callerLHSTuple));
-            // System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> "
-            // + translateToLocTuple(md, callerLHSTuple));
-          }
+      GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
+      for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
+        NTuple<Location> calleeReturnLocTuple = iterator.next();
+        for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
+          NTuple<Descriptor> callerLHSTuple = iter2.next();
+          globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
+              translateToLocTuple(md, callerLHSTuple));
+          System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> "
+              + translateToLocTuple(md, callerLHSTuple));
+        }
+      }
+
+      for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
+          .hasNext();) {
+        NTuple<Location> calleeReturnLocTuple = iterator.next();
+        for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
+          NTuple<Descriptor> callerLHSTuple = iter2.next();
+          globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
+              translateToLocTuple(md, callerLHSTuple));
+          System.out.println("$$$ GLOBAL FLOW PCLOC ADD=" + calleeReturnLocTuple + " -> "
+              + translateToLocTuple(md, callerLHSTuple));
         }
       }
 
@@ -4576,10 +4984,24 @@ public class LocationInference {
         }
       }
 
+      GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
+      for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
+          .hasNext();) {
+        NTuple<Location> calleeReturnLocTuple = iterator.next();
+        for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
+          NTuple<Descriptor> callerLHSTuple = iter2.next();
+          globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
+              translateToLocTuple(md, callerLHSTuple));
+          System.out.println("$$$ GLOBAL FLOW PC ADD=" + calleeReturnLocTuple + " -> "
+              + translateToLocTuple(md, callerLHSTuple));
+        }
+      }
+
     }
 
     if (nodeSet != null) {
       nodeSet.addTupleSet(nodeSetLHS);
+      nodeSet.addGlobalFlowTupleSet(nodeSetLHS.getGlobalLocTupleSet());
     }
   }