changes.
[IRC.git] / Robust / src / Analysis / SSJava / LocationInference.java
index 3ae2d94dca264bccd7f958b3e2c22dc6f6112ab5..6404a8f9984fdc520736c8a12d0ebf077898cf04 100644 (file)
@@ -1,8 +1,11 @@
 package Analysis.SSJava;
 
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileReader;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -13,6 +16,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.Stack;
+import java.util.Vector;
 
 import IR.ClassDescriptor;
 import IR.Descriptor;
@@ -46,6 +50,7 @@ import IR.Tree.SubBlockNode;
 import IR.Tree.SwitchStatementNode;
 import IR.Tree.TertiaryNode;
 import IR.Tree.TreeNode;
+import Util.Pair;
 
 public class LocationInference {
 
@@ -80,6 +85,10 @@ public class LocationInference {
 
   private Map<MethodDescriptor, Set<MethodDescriptor>> mapMethodToCalleeSet;
 
+  private Map<String, Vector<String>> mapFileNameToLineVector;
+
+  private Map<Descriptor, Integer> mapDescToDefinitionLine;
+
   public static final String GLOBALLOC = "GLOBALLOC";
 
   public static final String TOPLOC = "TOPLOC";
@@ -88,6 +97,10 @@ public class LocationInference {
 
   public static final Descriptor TOPDESC = new NameDescriptor(TOPLOC);
 
+  public static String newline = System.getProperty("line.separator");
+
+  LocationInfo curMethodInfo;
+
   boolean debug = true;
 
   public LocationInference(SSJavaAnalysis ssjava, State state) {
@@ -106,6 +119,9 @@ public class LocationInference {
     this.mapMethodDescToMethodLocationInfo = new HashMap<MethodDescriptor, MethodLocationInfo>();
     this.mapMethodToCalleeSet = new HashMap<MethodDescriptor, Set<MethodDescriptor>>();
     this.mapClassToLocationInfo = new HashMap<ClassDescriptor, LocationInfo>();
+
+    this.mapFileNameToLineVector = new HashMap<String, Vector<String>>();
+    this.mapDescToDefinitionLine = new HashMap<Descriptor, Integer>();
   }
 
   public void setupToAnalyze() {
@@ -162,6 +178,333 @@ public class LocationInference {
     // 3) check properties
     checkLattices();
 
+    // 4) generate annotated source codes
+    generateAnnoatedCode();
+
+  }
+
+  private void addMapClassDefinitionToLineNum(ClassDescriptor cd, String strLine, int lineNum) {
+
+    String classSymbol = cd.getSymbol();
+    int idx = classSymbol.lastIndexOf("$");
+    if (idx != -1) {
+      classSymbol = classSymbol.substring(idx + 1);
+    }
+
+    String pattern = "class " + classSymbol + " ";
+    if (strLine.indexOf(pattern) != -1) {
+      mapDescToDefinitionLine.put(cd, lineNum);
+    }
+  }
+
+  private void addMapMethodDefinitionToLineNum(Set<MethodDescriptor> methodSet, String strLine,
+      int lineNum) {
+    for (Iterator iterator = methodSet.iterator(); iterator.hasNext();) {
+      MethodDescriptor md = (MethodDescriptor) iterator.next();
+      String pattern = md.getMethodDeclaration();
+      if (strLine.indexOf(pattern) != -1) {
+        mapDescToDefinitionLine.put(md, lineNum);
+        methodSet.remove(md);
+        return;
+      }
+    }
+
+  }
+
+  private void readOriginalSourceFiles() {
+
+    SymbolTable classtable = state.getClassSymbolTable();
+
+    Set<ClassDescriptor> classDescSet = new HashSet<ClassDescriptor>();
+    classDescSet.addAll(classtable.getValueSet());
+
+    try {
+      // inefficient implement. it may re-visit the same file if the file
+      // contains more than one class definitions.
+      for (Iterator iterator = classDescSet.iterator(); iterator.hasNext();) {
+        ClassDescriptor cd = (ClassDescriptor) iterator.next();
+
+        Set<MethodDescriptor> methodSet = new HashSet<MethodDescriptor>();
+        methodSet.addAll(cd.getMethodTable().getValueSet());
+
+        String sourceFileName = cd.getSourceFileName();
+        Vector<String> lineVec = new Vector<String>();
+
+        mapFileNameToLineVector.put(sourceFileName, lineVec);
+
+        BufferedReader in = new BufferedReader(new FileReader(sourceFileName));
+        String strLine;
+        int lineNum = 1;
+        lineVec.add(""); // the index is started from 1.
+        while ((strLine = in.readLine()) != null) {
+          lineVec.add(lineNum, strLine);
+          addMapClassDefinitionToLineNum(cd, strLine, lineNum);
+          addMapMethodDefinitionToLineNum(methodSet, strLine, lineNum);
+          lineNum++;
+        }
+
+      }
+
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+
+  }
+
+  private String generateLatticeDefinition(Descriptor desc) {
+
+    Set<String> sharedLocSet = new HashSet<String>();
+
+    SSJavaLattice<String> lattice = getLattice(desc);
+    String rtr = "@LATTICE(\"";
+
+    Map<String, Set<String>> map = lattice.getTable();
+    Set<String> keySet = map.keySet();
+    boolean first = true;
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      String key = (String) iterator.next();
+      if (!key.equals(lattice.getTopItem())) {
+        Set<String> connectedSet = map.get(key);
+
+        if (connectedSet.size() == 1) {
+          if (connectedSet.iterator().next().equals(lattice.getBottomItem())) {
+            if (!first) {
+              rtr += ",";
+            } else {
+              rtr += "LOC,";
+              first = false;
+            }
+            rtr += key;
+            if (lattice.isSharedLoc(key)) {
+              rtr += "," + key + "*";
+            }
+          }
+        }
+
+        for (Iterator iterator2 = connectedSet.iterator(); iterator2.hasNext();) {
+          String loc = (String) iterator2.next();
+          if (!loc.equals(lattice.getBottomItem())) {
+            if (!first) {
+              rtr += ",";
+            } else {
+              rtr += "LOC,";
+              first = false;
+            }
+            rtr += loc + "<" + key;
+            if (lattice.isSharedLoc(key) && (!sharedLocSet.contains(key))) {
+              rtr += "," + key + "*";
+              sharedLocSet.add(key);
+            }
+            if (lattice.isSharedLoc(loc) && (!sharedLocSet.contains(loc))) {
+              rtr += "," + loc + "*";
+              sharedLocSet.add(loc);
+            }
+
+          }
+        }
+      }
+    }
+
+    rtr += "\")";
+
+    if (desc instanceof MethodDescriptor) {
+      TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType();
+      if (returnType != null && (!returnType.isVoid())) {
+        rtr += "\n@RETURNLOC(\"RETURNLOC\")";
+      }
+      rtr += "\n@THISLOC(\"this\")\n@PCLOC(\"PCLOC\")\n@GLOBALLOC(\"GLOBALLOC\")";
+
+    }
+
+    return rtr;
+  }
+
+  private void generateAnnoatedCode() {
+
+    readOriginalSourceFiles();
+
+    setupToAnalyze();
+    while (!toAnalyzeIsEmpty()) {
+      ClassDescriptor cd = toAnalyzeNext();
+
+      setupToAnalazeMethod(cd);
+
+      LocationInfo locInfo = mapClassToLocationInfo.get(cd);
+      String sourceFileName = cd.getSourceFileName();
+
+      if (cd.isInterface()) {
+        continue;
+      }
+
+      int classDefLine = mapDescToDefinitionLine.get(cd);
+      Vector<String> sourceVec = mapFileNameToLineVector.get(sourceFileName);
+
+      if (locInfo == null) {
+        locInfo = getLocationInfo(cd);
+      }
+
+      for (Iterator iter = cd.getFields(); iter.hasNext();) {
+        Descriptor fieldDesc = (Descriptor) iter.next();
+        String locIdentifier = locInfo.getFieldInferLocation(fieldDesc).getLocIdentifier();
+        if (!getLattice(cd).containsKey(locIdentifier)) {
+          getLattice(cd).put(locIdentifier);
+        }
+      }
+
+      String fieldLatticeDefStr = generateLatticeDefinition(cd);
+      String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine);
+      sourceVec.set(classDefLine, annoatedSrc);
+
+      // generate annotations for field declarations
+      LocationInfo fieldLocInfo = getLocationInfo(cd);
+      Map<Descriptor, CompositeLocation> inferLocMap = fieldLocInfo.getMapDescToInferLocation();
+
+      for (Iterator iter = cd.getFields(); iter.hasNext();) {
+        FieldDescriptor fd = (FieldDescriptor) iter.next();
+
+        String locAnnotationStr;
+        if (inferLocMap.containsKey(fd)) {
+          CompositeLocation inferLoc = inferLocMap.get(fd);
+          locAnnotationStr = generateLocationAnnoatation(inferLoc);
+        } else {
+          // if the field is not accssed by SS part, just assigns dummy
+          // location
+          locAnnotationStr = "@LOC(\"LOC\")";
+        }
+        int fdLineNum = fd.getLineNum();
+        String orgFieldDeclarationStr = sourceVec.get(fdLineNum);
+        String fieldDeclaration = fd.toString();
+        fieldDeclaration = fieldDeclaration.substring(0, fieldDeclaration.length() - 1);
+
+        String annoatedStr = locAnnotationStr + " " + orgFieldDeclarationStr;
+        sourceVec.set(fdLineNum, annoatedStr);
+
+      }
+
+      while (!toAnalyzeMethodIsEmpty()) {
+        MethodDescriptor md = toAnalyzeMethodNext();
+        SSJavaLattice<String> methodLattice = md2lattice.get(md);
+        if (methodLattice != null) {
+
+          int methodDefLine = md.getLineNum();
+
+          MethodLocationInfo methodLocInfo = getMethodLocationInfo(md);
+
+          Map<Descriptor, CompositeLocation> methodInferLocMap =
+              methodLocInfo.getMapDescToInferLocation();
+          Set<Descriptor> localVarDescSet = methodInferLocMap.keySet();
+
+          for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) {
+            Descriptor localVarDesc = (Descriptor) iterator.next();
+            CompositeLocation inferLoc = methodInferLocMap.get(localVarDesc);
+
+            String locAnnotationStr = generateLocationAnnoatation(inferLoc);
+
+            if (!isParameter(md, localVarDesc)) {
+              if (mapDescToDefinitionLine.containsKey(localVarDesc)) {
+                int varLineNum = mapDescToDefinitionLine.get(localVarDesc);
+                String orgSourceLine = sourceVec.get(varLineNum);
+                int idx =
+                    orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
+                assert (idx != -1);
+                String annoatedStr =
+                    orgSourceLine.substring(0, idx) + locAnnotationStr + " "
+                        + orgSourceLine.substring(idx);
+                sourceVec.set(varLineNum, annoatedStr);
+              }
+            } else {
+              String methodDefStr = sourceVec.get(methodDefLine);
+              int idx = methodDefStr.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
+              assert (idx != -1);
+              String annoatedStr =
+                  methodDefStr.substring(0, idx) + locAnnotationStr + " "
+                      + methodDefStr.substring(idx);
+              sourceVec.set(methodDefLine, annoatedStr);
+            }
+
+          }
+
+          String methodLatticeDefStr = generateLatticeDefinition(md);
+          String annoatedStr = methodLatticeDefStr + newline + sourceVec.get(methodDefLine);
+          sourceVec.set(methodDefLine, annoatedStr);
+
+        }
+      }
+
+    }
+
+    codeGen();
+  }
+
+  private String generateVarDeclaration(VarDescriptor varDesc) {
+
+    TypeDescriptor td = varDesc.getType();
+    String rtr = td.toString();
+    if (td.isArray()) {
+      for (int i = 0; i < td.getArrayCount(); i++) {
+        rtr += "[]";
+      }
+    }
+    rtr += " " + varDesc.getName();
+    return rtr;
+
+  }
+
+  private String generateLocationAnnoatation(CompositeLocation loc) {
+    String rtr = "@LOC(\"";
+
+    // method location
+    Location methodLoc = loc.get(0);
+    rtr += methodLoc.getLocIdentifier();
+
+    for (int i = 1; i < loc.getSize(); i++) {
+      Location element = loc.get(i);
+      rtr += "," + element.getDescriptor().getSymbol() + "." + element.getLocIdentifier();
+    }
+
+    rtr += "\")";
+    return rtr;
+  }
+
+  private boolean isParameter(MethodDescriptor md, Descriptor localVarDesc) {
+    return getFlowGraph(md).isParamDesc(localVarDesc);
+  }
+
+  private String extractFileName(String fileName) {
+    int idx = fileName.lastIndexOf("/");
+    if (idx == -1) {
+      return fileName;
+    } else {
+      return fileName.substring(idx + 1);
+    }
+
+  }
+
+  private void codeGen() {
+
+    Set<String> originalFileNameSet = mapFileNameToLineVector.keySet();
+    for (Iterator iterator = originalFileNameSet.iterator(); iterator.hasNext();) {
+      String orgFileName = (String) iterator.next();
+      String outputFileName = extractFileName(orgFileName);
+
+      Vector<String> sourceVec = mapFileNameToLineVector.get(orgFileName);
+
+      try {
+
+        FileWriter fileWriter = new FileWriter("./infer/" + outputFileName);
+        BufferedWriter out = new BufferedWriter(fileWriter);
+
+        for (int i = 0; i < sourceVec.size(); i++) {
+          out.write(sourceVec.get(i));
+          out.newLine();
+        }
+        out.close();
+      } catch (IOException e) {
+        e.printStackTrace();
+      }
+
+    }
+
   }
 
   private void simplifyLattices() {
@@ -181,11 +524,9 @@ public class LocationInference {
 
       while (!toAnalyzeMethodIsEmpty()) {
         MethodDescriptor md = toAnalyzeMethodNext();
-        if (ssjava.needTobeAnnotated(md)) {
-          SSJavaLattice<String> methodLattice = md2lattice.get(md);
-          if (methodLattice != null) {
-            methodLattice.removeRedundantEdges();
-          }
+        SSJavaLattice<String> methodLattice = md2lattice.get(md);
+        if (methodLattice != null) {
+          methodLattice.removeRedundantEdges();
         }
       }
     }
@@ -231,12 +572,10 @@ public class LocationInference {
 
       while (!toAnalyzeMethodIsEmpty()) {
         MethodDescriptor md = toAnalyzeMethodNext();
-        if (ssjava.needTobeAnnotated(md)) {
-          SSJavaLattice<String> methodLattice = md2lattice.get(md);
-          if (methodLattice != null) {
-            ssjava.writeLatticeDotFile(cd, md, methodLattice);
-            debug_printDescriptorToLocNameMapping(md);
-          }
+        SSJavaLattice<String> methodLattice = md2lattice.get(md);
+        if (methodLattice != null) {
+          ssjava.writeLatticeDotFile(cd, md, methodLattice);
+          debug_printDescriptorToLocNameMapping(md);
         }
       }
     }
@@ -271,7 +610,7 @@ public class LocationInference {
     // dependency in the call graph
     methodDescriptorsToVisitStack.clear();
 
-    descriptorListToAnalyze.removeFirst();
+    // descriptorListToAnalyze.removeFirst();
 
     Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
     methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
@@ -290,6 +629,7 @@ public class LocationInference {
           new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM);
 
       MethodLocationInfo methodInfo = new MethodLocationInfo(md);
+      curMethodInfo = methodInfo;
 
       System.out.println();
       System.out.println("SSJAVA: Inferencing the lattice from " + md);
@@ -438,6 +778,8 @@ public class LocationInference {
 
     // set the global location
     methodInfo.setGlobalLocName(LocationInference.GLOBALLOC);
+    methodInfo.mapDescriptorToLocation(GLOBALDESC, new CompositeLocation(
+        new Location(md, GLOBALLOC)));
 
     // visit each node of method flow graph
     FlowGraph fg = getFlowGraph(md);
@@ -463,33 +805,61 @@ public class LocationInference {
               && srcNodeTuple.get(0).equals(dstNodeTuple.get(0))) {
 
             // value flows between fields
-            VarDescriptor varDesc = (VarDescriptor) srcNodeTuple.get(0);
-            ClassDescriptor varClassDesc = varDesc.getType().getClassDesc();
-            extractRelationFromFieldFlows(varClassDesc, 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 {
+            Descriptor desc = srcNodeTuple.get(0);
+            ClassDescriptor classDesc;
 
-            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);
+            if (desc.equals(GLOBALDESC)) {
+              classDesc = md.getClassDesc();
             } 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);
+              VarDescriptor varDesc = (VarDescriptor) srcNodeTuple.get(0);
+              classDesc = varDesc.getType().getClassDesc();
             }
+            extractRelationFromFieldFlows(classDesc, srcNode, dstNode, 1);
+
+          } else {
+            // 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);
+          // }
+          // }
+
         }
       }
     }
 
+    for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
+      FlowNode flowNode = (FlowNode) iterator.next();
+      if (flowNode.isDeclaratonNode()) {
+        CompositeLocation inferLoc = methodInfo.getInferLocation(flowNode.getDescTuple().get(0));
+        String locIdentifier = inferLoc.get(0).getLocIdentifier();
+        if (!methodLattice.containsKey(locIdentifier)) {
+          methodLattice.put(locIdentifier);
+        }
+
+      }
+    }
+
     // create mapping from param idx to inferred composite location
 
     int offset;
@@ -673,12 +1043,12 @@ public class LocationInference {
                 // CompositeLocation lowerInferLoc =
                 // methodInfo.getInferLocation(argTuple2.get(0));
 
-                CompositeLocation inferLoc1 =
-                    calcualteInferredCompositeLocation(methodInfo, tuple1);
-                CompositeLocation inferLoc2 =
-                    calcualteInferredCompositeLocation(methodInfo, tuple2);
+                CompositeLocation inferLoc1 = generateInferredCompositeLocation(methodInfo, tuple1);
+                CompositeLocation inferLoc2 = generateInferredCompositeLocation(methodInfo, tuple2);
+
+                // addRelation(methodLattice, methodInfo, inferLoc1, inferLoc2);
 
-                addRelation(methodLattice, methodInfo, inferLoc1, inferLoc2);
+                addFlowGraphEdge(mdCaller, argDescTuple1, argDescTuple2);
 
               }
 
@@ -691,38 +1061,53 @@ public class LocationInference {
 
   }
 
-  private CompositeLocation calcualteInferredCompositeLocation(MethodLocationInfo methodInfo,
+  private CompositeLocation generateInferredCompositeLocation(MethodLocationInfo methodInfo,
       NTuple<Location> tuple) {
 
     // first, retrieve inferred location by the local var descriptor
-
     CompositeLocation inferLoc = new CompositeLocation();
 
     CompositeLocation localVarInferLoc =
         methodInfo.getInferLocation(tuple.get(0).getLocDescriptor());
+
+    localVarInferLoc.get(0).setLocDescriptor(tuple.get(0).getLocDescriptor());
+
     for (int i = 0; i < localVarInferLoc.getSize(); i++) {
       inferLoc.addLocation(localVarInferLoc.get(i));
     }
+    // System.out.println("@@@@@localVarInferLoc=" + localVarInferLoc);
 
     for (int i = 1; i < tuple.size(); i++) {
       Location cur = tuple.get(i);
       Descriptor enclosingDesc = cur.getDescriptor();
       Descriptor curDesc = cur.getLocDescriptor();
 
-      String fieldLocSymbol =
-          getLocationInfo(enclosingDesc).getInferLocation(curDesc).get(0).getLocIdentifier();
-      Location inferLocElement = new Location(enclosingDesc, fieldLocSymbol);
+      Location inferLocElement;
+      if (curDesc == null) {
+        // in this case, we have a newly generated location.
+        // System.out.println("!!! generated location=" +
+        // cur.getLocIdentifier());
+        inferLocElement = new Location(enclosingDesc, cur.getLocIdentifier());
+      } else {
+        String fieldLocSymbol =
+            getLocationInfo(enclosingDesc).getInferLocation(curDesc).get(0).getLocIdentifier();
+        inferLocElement = new Location(enclosingDesc, fieldLocSymbol);
+        inferLocElement.setLocDescriptor(curDesc);
+      }
 
       inferLoc.addLocation(inferLocElement);
 
     }
 
+    assert (inferLoc.get(0).getLocDescriptor().getSymbol() == inferLoc.get(0).getLocIdentifier());
     return inferLoc;
   }
 
   private void addRelation(SSJavaLattice<String> methodLattice, MethodLocationInfo methodInfo,
       CompositeLocation srcInferLoc, CompositeLocation dstInferLoc) throws CyclicFlowException {
 
+    System.out.println("addRelation --- srcInferLoc=" + srcInferLoc + "  dstInferLoc="
+        + dstInferLoc);
     String srcLocalLocSymbol = srcInferLoc.get(0).getLocIdentifier();
     String dstLocalLocSymbol = dstInferLoc.get(0).getLocIdentifier();
 
@@ -744,9 +1129,11 @@ public class LocationInference {
       }
     }
 
+    System.out.println();
+
   }
 
-  private LocationInfo getLocationInfo(Descriptor d) {
+  public LocationInfo getLocationInfo(Descriptor d) {
     if (d instanceof MethodDescriptor) {
       return getMethodLocationInfo((MethodDescriptor) d);
     } else {
@@ -782,22 +1169,24 @@ public class LocationInference {
 
     // add a new binary relation of dstNode < srcNode
     FlowGraph flowGraph = getFlowGraph(md);
-
-    calculateCompositeLocation(flowGraph, methodLattice, methodInfo, srcNode);
-
-    CompositeLocation srcInferLoc =
-        calcualteInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(srcNode));
-    CompositeLocation dstInferLoc =
-        calcualteInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(dstNode));
-
     try {
+      System.out.println("***** src composite case::");
+      calculateCompositeLocation(flowGraph, methodLattice, methodInfo, srcNode);
+
+      CompositeLocation srcInferLoc =
+          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
       // for the destination node
+      System.out.println("***** dst composite case::");
       calculateCompositeLocation(flowGraph, methodLattice, methodInfo, dstNode);
-      dstInferLoc =
-          calcualteInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(dstNode));
+      CompositeLocation srcInferLoc =
+          generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(srcNode));
+      CompositeLocation dstInferLoc =
+          generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(dstNode));
       try {
         addRelation(methodLattice, methodInfo, srcInferLoc, dstInferLoc);
       } catch (CyclicFlowException e1) {
@@ -819,6 +1208,7 @@ public class LocationInference {
       // check if it is the case of shared location
       if (srcInferLoc.getSize() == (idx + 1) && dstInferLoc.getSize() == (idx + 1)) {
         Location inferLocElement = srcInferLoc.get(idx);
+        System.out.println("SET SHARED LOCATION=" + inferLocElement);
         getLattice(inferLocElement.getDescriptor())
             .addSharedLoc(inferLocElement.getLocIdentifier());
       } else if (srcInferLoc.getSize() > (idx + 1) && dstInferLoc.getSize() > (idx + 1)) {
@@ -880,6 +1270,11 @@ public class LocationInference {
       throws CyclicFlowException {
 
     Descriptor localVarDesc = flowNode.getDescTuple().get(0);
+    NTuple<Location> flowNodelocTuple = flowGraph.getLocationTuple(flowNode);
+
+    if (localVarDesc.equals(methodInfo.getMethodDesc())) {
+      return false;
+    }
 
     Set<FlowNode> inNodeSet = flowGraph.getIncomingFlowNodeSet(flowNode);
     Set<FlowNode> reachableNodeSet = flowGraph.getReachableFlowNodeSet(flowNode);
@@ -887,28 +1282,23 @@ public class LocationInference {
     Map<NTuple<Location>, Set<NTuple<Location>>> mapPrefixToIncomingLocTupleSet =
         new HashMap<NTuple<Location>, Set<NTuple<Location>>>();
 
-    Set<FlowNode> localInNodeSet = new HashSet<FlowNode>();
-    Set<FlowNode> localOutNodeSet = new HashSet<FlowNode>();
-
-    CompositeLocation flowNodeInferLoc =
-        calcualteInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(flowNode));
-
     List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
 
     for (Iterator iterator = inNodeSet.iterator(); iterator.hasNext();) {
       FlowNode inNode = (FlowNode) iterator.next();
-      NTuple<Location> inTuple = flowGraph.getLocationTuple(inNode);
+      NTuple<Location> inNodeTuple = flowGraph.getLocationTuple(inNode);
 
-      if (inTuple.size() > 1) {
-        for (int i = 1; i < inTuple.size(); i++) {
-          NTuple<Location> prefix = inTuple.subList(0, i);
-          if (!prefixList.contains(prefix)) {
-            prefixList.add(prefix);
-          }
-          addPrefixMapping(mapPrefixToIncomingLocTupleSet, prefix, inTuple);
+      CompositeLocation inNodeInferredLoc =
+          generateInferredCompositeLocation(methodInfo, inNodeTuple);
+
+      NTuple<Location> inNodeInferredLocTuple = inNodeInferredLoc.getTuple();
+
+      for (int i = 1; i < inNodeInferredLocTuple.size(); i++) {
+        NTuple<Location> prefix = inNodeInferredLocTuple.subList(0, i);
+        if (!prefixList.contains(prefix)) {
+          prefixList.add(prefix);
         }
-      } else {
-        localInNodeSet.add(inNode);
+        addPrefixMapping(mapPrefixToIncomingLocTupleSet, prefix, inNodeInferredLocTuple);
       }
     }
 
@@ -926,13 +1316,6 @@ public class LocationInference {
       }
     });
 
-    for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
-      FlowNode reachableNode = (FlowNode) iterator2.next();
-      if (reachableNode.getDescTuple().size() == 1) {
-        localOutNodeSet.add(reachableNode);
-      }
-    }
-
     // find out reachable nodes that have the longest common prefix
     for (int i = 0; i < prefixList.size(); i++) {
       NTuple<Location> curPrefix = prefixList.get(i);
@@ -941,18 +1324,13 @@ public class LocationInference {
       for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
         FlowNode reachableNode = (FlowNode) iterator2.next();
         NTuple<Location> reachLocTuple = flowGraph.getLocationTuple(reachableNode);
-        if (reachLocTuple.startsWith(curPrefix)) {
+        CompositeLocation reachLocInferLoc =
+            generateInferredCompositeLocation(methodInfo, reachLocTuple);
+        if (reachLocInferLoc.getTuple().startsWith(curPrefix)) {
           reachableCommonPrefixSet.add(reachLocTuple);
         }
       }
 
-      // check if the lattice has the relation in which higher prefix is
-      // actually lower than the current node
-      CompositeLocation prefixInferLoc = calcualteInferredCompositeLocation(methodInfo, curPrefix);
-      if (isGreaterThan(methodLattice, flowNodeInferLoc, prefixInferLoc)) {
-        reachableCommonPrefixSet.add(curPrefix);
-      }
-
       if (!reachableCommonPrefixSet.isEmpty()) {
         // found reachable nodes that start with the prefix curPrefix
         // need to assign a composite location
@@ -972,120 +1350,104 @@ public class LocationInference {
         SSJavaLattice<String> lattice = getLattice(desc);
         LocationInfo locInfo = getLocationInfo(desc);
 
-        // CompositeLocation inferLocation =
-        // methodInfo.getInferLocation(flowNode);
-        CompositeLocation inferLocation = methodInfo.getInferLocation(localVarDesc);
+        CompositeLocation inferLocation =
+            generateInferredCompositeLocation(methodInfo, flowNodelocTuple);
 
-        String newlyInsertedLocName;
-        if (inferLocation.getSize() == 1) {
-          // need to replace the old local location with a new composite
-          // location
+        // methodInfo.getInferLocation(localVarDesc);
+        CompositeLocation newInferLocation = new CompositeLocation();
 
-          String oldMethodLocationSymbol = inferLocation.get(0).getLocIdentifier();
+        if (inferLocation.getTuple().startsWith(curPrefix)) {
+          // the same infer location is already existed. no need to do
+          // anything
+          return true;
+        } else {
+          // assign a new composite location
 
+          // String oldMethodLocationSymbol =
+          // inferLocation.get(0).getLocIdentifier();
           String newLocSymbol = "Loc" + (SSJavaLattice.seed++);
-          inferLocation = new CompositeLocation();
           for (int locIdx = 0; locIdx < curPrefix.size(); locIdx++) {
-            inferLocation.addLocation(curPrefix.get(locIdx));
+            newInferLocation.addLocation(curPrefix.get(locIdx));
           }
-          Location fieldLoc = new Location(desc, newLocSymbol);
-          inferLocation.addLocation(fieldLoc);
-
-          methodInfo.mapDescriptorToLocation(localVarDesc, inferLocation);
-          methodInfo.removeMaplocalVarToLocSet(localVarDesc);
-
-          String newMethodLocationSymbol = curPrefix.get(0).getLocIdentifier();
+          Location newLocationElement = new Location(desc, newLocSymbol);
+          newInferLocation.addLocation(newLocationElement);
 
-          replaceOldLocWithNewLoc(methodLattice, oldMethodLocationSymbol, newMethodLocationSymbol);
+          // maps local variable to location types of the common prefix
+          methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation.clone());
 
-        } else {
+          // methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation);
+          addMapLocSymbolToInferredLocation(methodInfo.getMethodDesc(), localVarDesc,
+              newInferLocation);
+          methodInfo.removeMaplocalVarToLocSet(localVarDesc);
 
-          String localLocName = methodInfo.getInferLocation(localVarDesc).get(0).getLocIdentifier();
-          return true;
+          // add the field/var descriptor to the set of the location symbol
+          int lastIdx = flowNode.getDescTuple().size() - 1;
+          Descriptor lastFlowNodeDesc = flowNode.getDescTuple().get(lastIdx);
+          Descriptor enclosinglastLastFlowNodeDesc = flowNodelocTuple.get(lastIdx).getDescriptor();
+
+          CompositeLocation newlyInferredLocForFlowNode =
+              generateInferredCompositeLocation(methodInfo, flowNodelocTuple);
+          Location lastInferLocElement =
+              newlyInferredLocForFlowNode.get(newlyInferredLocForFlowNode.getSize() - 1);
+          Descriptor enclosingLastInferLocElement = lastInferLocElement.getDescriptor();
+
+          // getLocationInfo(enclosingLastInferLocElement).addMapLocSymbolToDescSet(
+          // lastInferLocElement.getLocIdentifier(), lastFlowNodeDesc);
+          getLocationInfo(enclosingLastInferLocElement).addMapLocSymbolToRelatedInferLoc(
+              lastInferLocElement.getLocIdentifier(), enclosinglastLastFlowNodeDesc,
+              lastFlowNodeDesc);
+
+          // clean up the previous location
+          // Location prevInferLocElement =
+          // inferLocation.get(inferLocation.getSize() - 1);
+          // Descriptor prevEnclosingDesc = prevInferLocElement.getDescriptor();
+          //
+          // SSJavaLattice<String> targetLattice;
+          // LocationInfo targetInfo;
+          // if (prevEnclosingDesc.equals(methodInfo.getMethodDesc())) {
+          // targetLattice = methodLattice;
+          // targetInfo = methodInfo;
+          // } else {
+          // targetLattice = getLattice(prevInferLocElement.getDescriptor());
+          // targetInfo = getLocationInfo(prevInferLocElement.getDescriptor());
+          // }
+          //
+          // Set<Pair<Descriptor, Descriptor>> associstedDescSet =
+          // targetInfo.getRelatedInferLocSet(prevInferLocElement.getLocIdentifier());
+          //
+          // if (associstedDescSet.size() == 1) {
+          // targetLattice.remove(prevInferLocElement.getLocIdentifier());
+          // } else {
+          // associstedDescSet.remove(lastFlowNodeDesc);
+          // }
 
         }
 
-        newlyInsertedLocName = inferLocation.get(inferLocation.getSize() - 1).getLocIdentifier();
+        System.out.println("ASSIGN NEW COMPOSITE LOCATION =" + newInferLocation + "    to "
+            + flowNode);
+
+        String newlyInsertedLocName =
+            newInferLocation.get(newInferLocation.getSize() - 1).getLocIdentifier();
 
+        System.out.println("-- add in-flow");
         for (Iterator iterator = incomingCommonPrefixSet.iterator(); iterator.hasNext();) {
           NTuple<Location> tuple = (NTuple<Location>) iterator.next();
-
           Location loc = tuple.get(idx);
-          String higher = locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier();
-          System.out.println("--");
-          System.out.println("add in-flow relation:");
+          String higher = loc.getLocIdentifier();
           addRelationHigherToLower(lattice, locInfo, higher, newlyInsertedLocName);
         }
-        System.out.println("end of add-inflow relation");
-
-        for (Iterator iterator = localInNodeSet.iterator(); iterator.hasNext();) {
-          FlowNode localNode = (FlowNode) iterator.next();
-
-          if (localNode.equals(flowNode)) {
-            continue;
-          }
-
-          Descriptor localInVarDesc = localNode.getDescTuple().get(0);
-          CompositeLocation inNodeInferLoc = methodInfo.getInferLocation(localInVarDesc);
-
-          if (isCompositeLocation(inNodeInferLoc)) {
-            // need to make sure that newLocSymbol is lower than the infernode
-            // location in the field lattice
-
-            if (inNodeInferLoc.getTuple().startsWith(curPrefix)
-                && inNodeInferLoc.getSize() == (curPrefix.size() + 1)) {
-              String higher = inNodeInferLoc.get(inNodeInferLoc.getSize() - 1).getLocIdentifier();
-              if (!higher.equals(newlyInsertedLocName)) {
-                System.out.println("add localInNodeSet relation:");
-                addRelationHigherToLower(lattice, locInfo, higher, newlyInsertedLocName);
-              }
-            } else {
-              throw new Error("Failed to generate a composite location.");
-            }
-
-          }
-
-        }
 
+        System.out.println("-- add out flow");
         for (Iterator iterator = reachableCommonPrefixSet.iterator(); iterator.hasNext();) {
           NTuple<Location> tuple = (NTuple<Location>) iterator.next();
           if (tuple.size() > idx) {
             Location loc = tuple.get(idx);
-            String lower = locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier();
-            // lattice.addRelationHigherToLower(newlyInsertedLocName, lower);
-            System.out.println("add out-flow relation:");
+            String lower = loc.getLocIdentifier();
+            // String lower =
+            // locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier();
             addRelationHigherToLower(lattice, locInfo, newlyInsertedLocName, lower);
           }
         }
-        System.out.println("end of add out-flow relation");
-
-        for (Iterator iterator = localOutNodeSet.iterator(); iterator.hasNext();) {
-          FlowNode localOutNode = (FlowNode) iterator.next();
-
-          if (localOutNode.equals(flowNode)) {
-            continue;
-          }
-
-          Descriptor localOutDesc = localOutNode.getDescTuple().get(0);
-          CompositeLocation outNodeInferLoc = methodInfo.getInferLocation(localOutDesc);
-
-          if (isCompositeLocation(outNodeInferLoc)) {
-            // need to make sure that newLocSymbol is higher than the infernode
-            // location
-
-            if (outNodeInferLoc.getTuple().startsWith(curPrefix)
-                && outNodeInferLoc.getSize() == (curPrefix.size() + 1)) {
-
-              String lower = outNodeInferLoc.get(outNodeInferLoc.getSize() - 1).getLocIdentifier();
-              System.out.println("add outNodeInferLoc relation:");
-
-              addRelationHigherToLower(lattice, locInfo, newlyInsertedLocName, lower);
-
-            } else {
-              throw new Error("Failed to generate a composite location.");
-            }
-          }
-        }
 
         return true;
       }
@@ -1096,6 +1458,15 @@ public class LocationInference {
 
   }
 
+  private void addMapLocSymbolToInferredLocation(MethodDescriptor md, Descriptor localVar,
+      CompositeLocation inferLoc) {
+
+    Location locElement = inferLoc.get((inferLoc.getSize() - 1));
+    Descriptor enclosingDesc = locElement.getDescriptor();
+    LocationInfo locInfo = getLocationInfo(enclosingDesc);
+    locInfo.addMapLocSymbolToRelatedInferLoc(locElement.getLocIdentifier(), md, localVar);
+  }
+
   private boolean isCompositeLocation(CompositeLocation cl) {
     return cl.getSize() > 1;
   }
@@ -1123,12 +1494,12 @@ public class LocationInference {
   private void addRelationHigherToLower(SSJavaLattice<String> lattice, LocationInfo locInfo,
       String higher, String lower) throws CyclicFlowException {
 
+    System.out.println("---addRelationHigherToLower " + higher + " -> " + lower
+        + " to the lattice of " + locInfo.getDescIdentifier());
     // if (higher.equals(lower) && lattice.isSharedLoc(higher)) {
     // return;
     // }
     Set<String> cycleElementSet = lattice.getPossibleCycleElements(higher, lower);
-    System.out.println("#Check cycle=" + lower + " < " + higher);
-    System.out.println("#cycleElementSet=" + cycleElementSet);
 
     boolean hasNonPrimitiveElement = false;
     for (Iterator iterator = cycleElementSet.iterator(); iterator.hasNext();) {
@@ -1142,19 +1513,52 @@ public class LocationInference {
     }
 
     if (hasNonPrimitiveElement) {
+      System.out.println("#Check cycle= " + lower + " < " + higher + "     cycleElementSet="
+          + cycleElementSet);
       // if there is non-primitive element in the cycle, no way to merge cyclic
       // elements into the shared location
       throw new CyclicFlowException();
     }
 
     if (cycleElementSet.size() > 0) {
+
       String newSharedLoc = "SharedLoc" + (SSJavaLattice.seed++);
 
+      System.out.println("---ASSIGN NEW SHARED LOC=" + newSharedLoc + "   to  " + cycleElementSet);
       lattice.mergeIntoSharedLocation(cycleElementSet, newSharedLoc);
 
       for (Iterator iterator = cycleElementSet.iterator(); iterator.hasNext();) {
         String oldLocSymbol = (String) iterator.next();
-        locInfo.mergeMapping(oldLocSymbol, newSharedLoc);
+
+        Set<Pair<Descriptor, Descriptor>> inferLocSet = locInfo.getRelatedInferLocSet(oldLocSymbol);
+        System.out.println("---update related locations=" + inferLocSet);
+        for (Iterator iterator2 = inferLocSet.iterator(); iterator2.hasNext();) {
+          Pair<Descriptor, Descriptor> pair = (Pair<Descriptor, Descriptor>) iterator2.next();
+          Descriptor enclosingDesc = pair.getFirst();
+          Descriptor desc = pair.getSecond();
+
+          CompositeLocation inferLoc;
+          if (curMethodInfo.md.equals(enclosingDesc)) {
+            inferLoc = curMethodInfo.getInferLocation(desc);
+          } else {
+            inferLoc = getLocationInfo(enclosingDesc).getInferLocation(desc);
+          }
+
+          Location locElement = inferLoc.get(inferLoc.getSize() - 1);
+
+          locElement.setLocIdentifier(newSharedLoc);
+          locInfo.addMapLocSymbolToRelatedInferLoc(newSharedLoc, enclosingDesc, desc);
+
+          if (curMethodInfo.md.equals(enclosingDesc)) {
+            inferLoc = curMethodInfo.getInferLocation(desc);
+          } else {
+            inferLoc = getLocationInfo(enclosingDesc).getInferLocation(desc);
+          }
+          System.out.println("---New Infer Loc=" + inferLoc);
+
+        }
+        locInfo.removeRelatedInferLocSet(oldLocSymbol, newSharedLoc);
+
       }
 
       lattice.addSharedLoc(newSharedLoc);
@@ -1477,9 +1881,11 @@ public class LocationInference {
       DeclarationNode dn, NodeTupleSet implicitFlowTupleSet) {
 
     VarDescriptor vd = dn.getVarDescriptor();
+    mapDescToDefinitionLine.put(vd, dn.getNumLine());
     NTuple<Descriptor> tupleLHS = new NTuple<Descriptor>();
     tupleLHS.add(vd);
-    getFlowGraph(md).createNewFlowNode(tupleLHS);
+    FlowNode fn = getFlowGraph(md).createNewFlowNode(tupleLHS);
+    fn.setDeclarationNode();
 
     if (dn.getExpression() != null) {
 
@@ -1521,13 +1927,14 @@ public class LocationInference {
     switch (en.kind()) {
 
     case Kind.AssignmentNode:
-      analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, base, implicitFlowTupleSet);
+      analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, nodeSet, base,
+          implicitFlowTupleSet);
       break;
 
     case Kind.FieldAccessNode:
       flowTuple =
           analyzeFlowFieldAccessNode(md, nametable, (FieldAccessNode) en, nodeSet, base,
-              implicitFlowTupleSet);
+              implicitFlowTupleSet, isLHS);
       if (flowTuple != null) {
         nodeSet.addTuple(flowTuple);
       }
@@ -1722,7 +2129,6 @@ public class LocationInference {
   private void analyzeFlowMethodParameters(MethodDescriptor callermd, SymbolTable nametable,
       MethodInvokeNode min) {
 
-
     if (min.numArgs() > 0) {
 
       int offset;
@@ -1764,7 +2170,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();) {
@@ -1849,7 +2254,6 @@ public class LocationInference {
   private NTuple<Descriptor> analyzeFlowNameNode(MethodDescriptor md, SymbolTable nametable,
       NameNode nn, NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
 
-
     if (base == null) {
       base = new NTuple<Descriptor>();
     }
@@ -1930,8 +2334,7 @@ public class LocationInference {
 
   private NTuple<Descriptor> analyzeFlowFieldAccessNode(MethodDescriptor md, SymbolTable nametable,
       FieldAccessNode fan, NodeTupleSet nodeSet, NTuple<Descriptor> base,
-      NodeTupleSet implicitFlowTupleSet) {
-
+      NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
 
     ExpressionNode left = fan.getExpression();
     TypeDescriptor ltd = left.getType();
@@ -1946,35 +2349,48 @@ public class LocationInference {
     if (ltd.isClassNameRef() || (varName != null && varName.equals("this"))) {
       // using a class name directly or access using this
       if (fd.isStatic() && fd.isFinal()) {
-        // loc.addLocation(Location.createTopLocation(md));
-        // return loc;
+        return null;
       }
     }
 
+    NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
     if (left instanceof ArrayAccessNode) {
+
       ArrayAccessNode aan = (ArrayAccessNode) left;
       left = aan.getExpression();
+      analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base,
+          implicitFlowTupleSet, isLHS);
+      nodeSet.addTupleSet(idxNodeTupleSet);
     }
-    // fanNodeSet
     base =
-        analyzeFlowExpressionNode(md, nametable, left, nodeSet, base, implicitFlowTupleSet, false);
+        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")) {
+        if (!fd.getSymbol().equals("length")) {
           // array.length access, just have the location of the array
-        } else {
-          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;
 
     }
 
@@ -1987,7 +2403,8 @@ public class LocationInference {
   }
 
   private void analyzeFlowAssignmentNode(MethodDescriptor md, SymbolTable nametable,
-      AssignmentNode an, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
+      AssignmentNode an, NodeTupleSet nodeSet, NTuple<Descriptor> base,
+      NodeTupleSet implicitFlowTupleSet) {
 
     NodeTupleSet nodeSetRHS = new NodeTupleSet();
     NodeTupleSet nodeSetLHS = new NodeTupleSet();
@@ -2050,8 +2467,20 @@ public class LocationInference {
         addFlowGraphEdge(md, tuple, tuple);
       }
 
+      // creates edges from implicitFlowTupleSet to LHS
+      for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
+        NTuple<Descriptor> fromTuple = iter.next();
+        for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
+          NTuple<Descriptor> toTuple = iter2.next();
+          addFlowGraphEdge(md, fromTuple, toTuple);
+        }
+      }
+
     }
 
+    if (nodeSet != null) {
+      nodeSet.addTupleSet(nodeSetLHS);
+    }
   }
 
   public FlowGraph getFlowGraph(MethodDescriptor md) {