changes on the definite clearance for shared locations analysis
authoryeom <yeom>
Mon, 29 Aug 2011 00:57:15 +0000 (00:57 +0000)
committeryeom <yeom>
Mon, 29 Aug 2011 00:57:15 +0000 (00:57 +0000)
Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java
Robust/src/Analysis/SSJava/FlowDownCheck.java
Robust/src/Analysis/SSJava/SharedStatus.java

index c1dfbbbcdb46c57dd775880c0500e2eceb1f477d..3ab04e361ea7e4d14417038c885a432424d74909 100644 (file)
@@ -15,6 +15,7 @@ import IR.MethodDescriptor;
 import IR.Operation;
 import IR.State;
 import IR.TypeDescriptor;
+import IR.TypeExtension;
 import IR.Flat.FKind;
 import IR.Flat.FlatCall;
 import IR.Flat.FlatElementNode;
@@ -140,8 +141,8 @@ public class DefinitelyWrittenCheck {
     if (!ssjava.getAnnotationRequireSet().isEmpty()) {
       methodReadOverWriteAnalysis();
       writtenAnalyis();
-      // sharedLocationAnalysis();
-      // checkSharedLocationResult();
+      sharedLocationAnalysis();
+      checkSharedLocationResult();
     }
   }
 
@@ -149,8 +150,11 @@ public class DefinitelyWrittenCheck {
 
     // mapping of method containing ssjava loop has the final result of
     // shared location analysis
+
     ClearingSummary result =
-        mapMethodDescriptorToCompleteClearingSummary.get(sortedDescriptors.peekFirst());
+        mapMethodDescriptorToCompleteClearingSummary.get(methodContainingSSJavaLoop);
+
+    System.out.println("###RESULT=" + result);
 
     Set<NTuple<Descriptor>> hpKeySet = result.keySet();
     for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
@@ -161,7 +165,8 @@ public class DefinitelyWrittenCheck {
         Location locKey = (Location) iterator2.next();
         if (!state.getFlag(locKey)) {
           throw new Error(
-              "Some concrete locations of the shared abstract location are not cleared at the same time.");
+              "Some concrete locations of the shared abstract location are not cleared at the same time:"
+                  + state);
         }
       }
     }
@@ -174,9 +179,25 @@ public class DefinitelyWrittenCheck {
 
     computeReadSharedDescriptorSet();
 
+
+    // methodDescriptorsToVisitStack.clear();
+    // methodDescriptorsToVisitStack.add(sortedDescriptors.peekFirst());
+
+    LinkedList<MethodDescriptor> descriptorListToAnalyze =
+        (LinkedList<MethodDescriptor>) sortedDescriptors.clone();
+
+    // current descriptors to visit in fixed-point interprocedural analysis,
+    // prioritized by
+    // dependency in the call graph
     methodDescriptorsToVisitStack.clear();
 
-    methodDescriptorsToVisitStack.add(sortedDescriptors.peekFirst());
+    Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
+    methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
+
+    while (!descriptorListToAnalyze.isEmpty()) {
+      MethodDescriptor md = descriptorListToAnalyze.removeFirst();
+      methodDescriptorsToVisitStack.add(md);
+    }
 
     // analyze scheduled methods until there are no more to visit
     while (!methodDescriptorsToVisitStack.isEmpty()) {
@@ -189,6 +210,12 @@ public class DefinitelyWrittenCheck {
 
       if (!completeSummary.equals(prevCompleteSummary)) {
 
+        ClearingSummary summaryFromCaller = mapMethodDescriptorToInitialClearingSummary.get(md);
+//        System.out.println("# summaryFromCaller=" + summaryFromCaller);
+//        System.out.println("# completeSummary=" + completeSummary);
+//        System.out.println("# prev=" + prevCompleteSummary);
+//        System.out.println("# changed!\n");
+
         mapMethodDescriptorToCompleteClearingSummary.put(md, completeSummary);
 
         // results for callee changed, so enqueue dependents caller for
@@ -319,8 +346,10 @@ public class DefinitelyWrittenCheck {
           mapMethodDescriptorToInitialClearingSummary.get(fm.getMethod());
 
       Set<ClearingSummary> inSet = new HashSet<ClearingSummary>();
-      inSet.add(summaryFromCaller);
-      mergeSharedLocationAnaylsis(curr, inSet);
+      if (summaryFromCaller != null) {
+        inSet.add(summaryFromCaller);
+        mergeSharedLocationAnaylsis(curr, inSet);
+      }
 
     }
       break;
@@ -371,14 +400,23 @@ public class DefinitelyWrittenCheck {
       // read field
       NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
 
-      // if (srcHeapPath != null) {
-      // // if lhs srcHeapPath is null, it means that it is not reachable from
-      // // callee's parameters. so just ignore it
-      NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
+      if (srcHeapPath != null) {
+        // if lhs srcHeapPath is null, it means that it is not reachable from
+        // callee's parameters. so just ignore it
+        NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
+
+        if (fld.getType().isImmutable()) {
+          readLocation(curr, fldHeapPath, fld);
+        }else{
+          fldHeapPath.add(fld);
+          mapHeapPath.put(lhs, fldHeapPath);
+        }
+
+
+        
 
-      if (fld.getType().isImmutable()) {
-        readLocation(curr, fldHeapPath, fld);
       }
+
       // }
 
     }
@@ -387,15 +425,25 @@ public class DefinitelyWrittenCheck {
     case FKind.FlatSetFieldNode:
     case FKind.FlatSetElementNode: {
 
-      FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
-      lhs = fsfn.getDst();
-      fld = fsfn.getField();
+      if (fn.kind() == FKind.FlatSetFieldNode) {
+        FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
+        lhs = fsfn.getDst();
+        fld = fsfn.getField();
+        rhs = fsfn.getSrc();
+      } else {
+        FlatSetElementNode fsen = (FlatSetElementNode) fn;
+        lhs = fsen.getDst();
+        rhs = fsen.getSrc();
+        TypeDescriptor td = lhs.getType().dereference();
+        fld = getArrayField(td);
+      }
 
       // write(field)
       NTuple<Descriptor> lhsHeapPath = computePath(lhs);
       NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
       if (fld.getType().isImmutable()) {
         writeLocation(curr, fldHeapPath, fld);
+        fldHeapPath.add(fld);
       } else {
         // updates reference field case:
         // 2. if there exists a tuple t in sharing summary that starts with
@@ -417,46 +465,65 @@ public class DefinitelyWrittenCheck {
 
       FlatCall fc = (FlatCall) fn;
 
-      // find out the set of callees
-      MethodDescriptor mdCallee = fc.getMethod();
-      FlatMethod fmCallee = state.getMethodFlat(mdCallee);
-      Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
-      // TypeDescriptor typeDesc = fc.getThis().getType();
-      setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
+      if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
+        // ssjava util case!
+        // have write effects on the first argument
+        NTuple<Descriptor> argHeapPath = computePath(fc.getArg(0));
+        // writeLocation(curr, argHeapPath, fc.getArg(0));
+      } else {
+        // find out the set of callees
+        MethodDescriptor mdCallee = fc.getMethod();
+        FlatMethod fmCallee = state.getMethodFlat(mdCallee);
+        Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
+        // TypeDescriptor typeDesc = fc.getThis().getType();
+        setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
 
-      possibleCalleeCompleteSummarySetToCaller.clear();
+        possibleCalleeCompleteSummarySetToCaller.clear();
 
-      for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
-        MethodDescriptor mdPossibleCallee = (MethodDescriptor) iterator.next();
-        FlatMethod calleeFlatMethod = state.getMethodFlat(mdPossibleCallee);
 
-        addDependent(mdPossibleCallee, // callee
-            caller); // caller
+        for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
+          MethodDescriptor mdPossibleCallee = (MethodDescriptor) iterator.next();
+          FlatMethod calleeFlatMethod = state.getMethodFlat(mdPossibleCallee);
 
-        calleesToEnqueue.add(mdPossibleCallee);
+          addDependent(mdPossibleCallee, // callee
+              caller); // caller
 
-        // updates possible callee's initial summary using caller's current
-        // writing status
-        ClearingSummary prevCalleeInitSummary =
-            mapMethodDescriptorToInitialClearingSummary.get(mdPossibleCallee);
+          calleesToEnqueue.add(mdPossibleCallee);
 
-        ClearingSummary calleeInitSummary =
-            bindHeapPathOfCalleeCallerEffects(fc, calleeFlatMethod, curr);
+          // updates possible callee's initial summary using caller's current
+          // writing status
+          ClearingSummary prevCalleeInitSummary =
+              mapMethodDescriptorToInitialClearingSummary.get(mdPossibleCallee);
 
-        // if changes, update the init summary
-        // and reschedule the callee for analysis
-        if (!calleeInitSummary.equals(prevCalleeInitSummary)) {
+          ClearingSummary calleeInitSummary =
+              bindHeapPathOfCalleeCallerEffects(fc, calleeFlatMethod, curr);
 
-          if (!methodDescriptorsToVisitStack.contains(mdPossibleCallee)) {
-            methodDescriptorsToVisitStack.add(mdPossibleCallee);
+          Set<ClearingSummary> inSet = new HashSet<ClearingSummary>();
+          if (prevCalleeInitSummary != null) {
+            inSet.add(prevCalleeInitSummary);
+            mergeSharedLocationAnaylsis(calleeInitSummary, inSet);
           }
-          mapMethodDescriptorToInitialClearingSummary.put(mdPossibleCallee, calleeInitSummary);
-        }
 
-      }
+          // if changes, update the init summary
+          // and reschedule the callee for analysis
+          if (!calleeInitSummary.equals(prevCalleeInitSummary)) {
+//            System.out.println("#CALLEE INIT CHANGED=" + mdPossibleCallee);
+//            System.out.println("# prev=" + prevCalleeInitSummary);
+//            System.out.println("# current=" + calleeInitSummary);
+//            System.out.println("#");
+
+            if (!methodDescriptorsToVisitStack.contains(mdPossibleCallee)) {
+              methodDescriptorsToVisitStack.add(mdPossibleCallee);
+            }
 
-      // contribute callee's writing effects to the caller
-      mergeSharedLocationAnaylsis(curr, possibleCalleeCompleteSummarySetToCaller);
+            mapMethodDescriptorToInitialClearingSummary.put(mdPossibleCallee, calleeInitSummary);
+          }
+
+        }
+//        System.out.println("callee " + fc + " summary=" + possibleCalleeCompleteSummarySetToCaller);
+        // contribute callee's writing effects to the caller
+        mergeSharedLocationAnaylsis(curr, possibleCalleeCompleteSummarySetToCaller);
+      }
 
     }
       break;
@@ -499,28 +566,39 @@ public class DefinitelyWrittenCheck {
 
     Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
         new Hashtable<Integer, TempDescriptor>();
+    int offset = 0;
+    if (calleeFlatMethod.getMethod().isStatic()) {
+      // static method does not have implicit 'this' arg
+      offset = 1;
+    }
     for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
       TempDescriptor param = calleeFlatMethod.getParameter(i);
-      mapParamIdx2ParamTempDesc.put(Integer.valueOf(i), param);
+      mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
     }
 
     // binding caller's writing effects to callee's params
     for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
       NTuple<Descriptor> argHeapPath = mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i));
-      TempDescriptor calleeParamHeapPath = mapParamIdx2ParamTempDesc.get(Integer.valueOf(i));
 
-      // iterate over caller's writing effect set
-      Set<NTuple<Descriptor>> hpKeySet = curr.keySet();
-      for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
-        NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
-        // current element is reachable caller's arg
-        // so need to bind it to the caller's side and add it to the callee's
-        // init summary
-        if (hpKey.startsWith(argHeapPath)) {
-          NTuple<Descriptor> boundHeapPath = replace(hpKey, argHeapPath, calleeParamHeapPath);
-          boundSet.put(boundHeapPath, curr.get(hpKey).clone());
-        }
+      if (argHeapPath != null) {
+        // if method is static, the first argument is nulll because static
+        // method does not have implicit "THIS" arg
+        TempDescriptor calleeParamHeapPath = mapParamIdx2ParamTempDesc.get(Integer.valueOf(i));
 
+        // iterate over caller's writing effect set
+        Set<NTuple<Descriptor>> hpKeySet = curr.keySet();
+        for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
+          NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
+          // current element is reachable caller's arg
+          // so need to bind it to the caller's side and add it to the
+          // callee's
+          // init summary
+          if (hpKey.startsWith(argHeapPath)) {
+            NTuple<Descriptor> boundHeapPath = replace(hpKey, argHeapPath, calleeParamHeapPath);
+            boundSet.put(boundHeapPath, curr.get(hpKey).clone());
+          }
+
+        }
       }
 
     }
@@ -528,29 +606,37 @@ public class DefinitelyWrittenCheck {
     // contribute callee's complete summary into the caller's current summary
     ClearingSummary calleeCompleteSummary =
         mapMethodDescriptorToCompleteClearingSummary.get(calleeFlatMethod.getMethod());
-
     if (calleeCompleteSummary != null) {
       ClearingSummary boundCalleeEfffects = new ClearingSummary();
       for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
+        // for (int i = 0; i < fc.numArgs(); i++) {
         NTuple<Descriptor> argHeapPath = mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i));
-        TempDescriptor calleeParamHeapPath = mapParamIdx2ParamTempDesc.get(Integer.valueOf(i));
 
-        // iterate over callee's writing effect set
-        Set<NTuple<Descriptor>> hpKeySet = calleeCompleteSummary.keySet();
-        for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
-          NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
-          // current element is reachable caller's arg
-          // so need to bind it to the caller's side and add it to the callee's
-          // init summary
-          if (hpKey.startsWith(calleeParamHeapPath)) {
+        if (argHeapPath != null) {
+          // if method is static, the first argument is nulll because static
+          // method does not have implicit "THIS" arg
+          TempDescriptor calleeParamHeapPath = mapParamIdx2ParamTempDesc.get(Integer.valueOf(i));
+
+          // iterate over callee's writing effect set
+          Set<NTuple<Descriptor>> hpKeySet = calleeCompleteSummary.keySet();
+          for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
+            NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
+            // current element is reachable caller's arg
+            // so need to bind it to the caller's side and add it to the
+            // callee's
+            // init summary
+            if (hpKey.startsWith(calleeParamHeapPath)) {
 
-            NTuple<Descriptor> boundHeapPathForCaller = replace(hpKey, argHeapPath);
+              NTuple<Descriptor> boundHeapPathForCaller = replace(hpKey, argHeapPath);
 
-            boundCalleeEfffects.put(boundHeapPathForCaller, calleeCompleteSummary.get(hpKey)
-                .clone());
+              boundCalleeEfffects.put(boundHeapPathForCaller, calleeCompleteSummary.get(hpKey)
+                  .clone());
 
+            }
           }
+
         }
+
       }
       possibleCalleeCompleteSummarySetToCaller.add(boundCalleeEfffects);
     }
@@ -668,30 +754,36 @@ public class DefinitelyWrittenCheck {
         lhs = ffn.getDst();
         rhs = ffn.getSrc();
         fld = ffn.getField();
+        if (fld.isStatic() && fld.isFinal()) {
+          break;
+        }
       } else {
         FlatElementNode fen = (FlatElementNode) fn;
         lhs = fen.getDst();
         rhs = fen.getSrc();
         TypeDescriptor td = rhs.getType().dereference();
         fld = getArrayField(td);
+        if (fld.isStatic() && fld.isFinal()) {
+          break;
+        }
       }
 
-      // FlatFieldNode ffn = (FlatFieldNode) fn;
-      // lhs = ffn.getDst();
-      // rhs = ffn.getSrc();
-      // fld = ffn.getField();
-
       // read field
       NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
-      NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
-      // fldHeapPath.add(fld);
+      if (srcHeapPath != null) {
+        // if srcHeapPath is null, it means that it is not reachable from
+        // callee's parameters. so just ignore it
 
-      if (fld.getType().isImmutable()) {
-        addReadDescriptor(fldHeapPath, fld);
-      }
+        NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
+        // fldHeapPath.add(fld);
 
-      // propagate rhs's heap path to the lhs
-      mapHeapPath.put(lhs, fldHeapPath);
+        if (fld.getType().isImmutable()) {
+          addReadDescriptor(fldHeapPath, fld);
+        }
+
+        // propagate rhs's heap path to the lhs
+        mapHeapPath.put(lhs, fldHeapPath);
+      }
 
     }
       break;
@@ -699,9 +791,17 @@ public class DefinitelyWrittenCheck {
     case FKind.FlatSetFieldNode:
     case FKind.FlatSetElementNode: {
 
-      FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
-      lhs = fsfn.getDst();
-      fld = fsfn.getField();
+      if (fn.kind() == FKind.FlatSetFieldNode) {
+        FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
+        lhs = fsfn.getDst();
+        fld = fsfn.getField();
+      } else {
+        FlatSetElementNode fsen = (FlatSetElementNode) fn;
+        lhs = fsen.getDst();
+        rhs = fsen.getSrc();
+        TypeDescriptor td = lhs.getType().dereference();
+        fld = getArrayField(td);
+      }
 
       // write(field)
       NTuple<Descriptor> lhsHeapPath = computePath(lhs);
@@ -725,15 +825,14 @@ public class DefinitelyWrittenCheck {
   private void addReadDescriptor(NTuple<Descriptor> hp, Descriptor d) {
 
     Location loc = getLocation(d);
-
     if (loc != null && ssjava.isSharedLocation(loc)) {
-
       Set<Descriptor> set = mapSharedLocation2DescriptorSet.get(loc);
       if (set == null) {
         set = new HashSet<Descriptor>();
         mapSharedLocation2DescriptorSet.put(loc, set);
       }
       set.add(d);
+
     }
 
   }
@@ -744,20 +843,27 @@ public class DefinitelyWrittenCheck {
       return (Location) ((FieldDescriptor) d).getType().getExtension();
     } else {
       assert d instanceof TempDescriptor;
-      CompositeLocation comp = (CompositeLocation) ((TempDescriptor) d).getType().getExtension();
-      if (comp == null) {
-        return null;
-      } else {
-        return comp.get(comp.getSize() - 1);
+      TempDescriptor td = (TempDescriptor) d;
+
+      TypeExtension te = td.getType().getExtension();
+      if (te != null) {
+        if (te instanceof CompositeLocation) {
+          CompositeLocation comp = (CompositeLocation) te;
+
+          return comp.get(comp.getSize() - 1);
+        } else {
+          return (Location) te;
+        }
       }
     }
 
+    return null;
   }
 
   private void writeLocation(ClearingSummary curr, NTuple<Descriptor> hp, Descriptor d) {
+
     Location loc = getLocation(d);
     if (loc != null && hasReadingEffectOnSharedLocation(hp, loc, d)) {
-
       // 1. add field x to the clearing set
       SharedStatus state = getState(curr, hp);
       state.addVar(loc, d);
@@ -1509,7 +1615,6 @@ public class DefinitelyWrittenCheck {
   }
 
   private void mergeSharedLocationAnaylsis(ClearingSummary curr, Set<ClearingSummary> inSet) {
-
     if (inSet.size() == 0) {
       return;
     }
@@ -1526,7 +1631,6 @@ public class DefinitelyWrittenCheck {
       for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
         NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
         SharedStatus inState = inTable.get(hpKey);
-
         SharedStatus currState = curr.get(hpKey);
         if (currState == null) {
           currState = new SharedStatus();
index 259893ce05396cae07296c3fb0cdea3968be48d1..a1397dae02aa1ccaff911dff574af5c1f5318eaf 100644 (file)
@@ -292,7 +292,6 @@ public class FlowDownCheck {
   private void checkDeclarationInMethodBody(ClassDescriptor cd, MethodDescriptor md) {
     BlockNode bn = state.getMethodBody(md);
 
-    System.out.println("\n#checkDeclarationInMethodBody=" + md);
 
     // first, check annotations on method parameters
     List<CompositeLocation> paramList = new ArrayList<CompositeLocation>();
@@ -347,8 +346,8 @@ public class FlowDownCheck {
       CompositeLocation thisLoc = new CompositeLocation(new Location(md, thisLocId));
       paramList.add(0, thisLoc);
 
-      System.out.println("### ReturnLocGenerator=" + md);
-      System.out.println("### md2ReturnLoc.get(md)=" + md2ReturnLoc.get(md));
+//      System.out.println("### ReturnLocGenerator=" + md);
+//      System.out.println("### md2ReturnLoc.get(md)=" + md2ReturnLoc.get(md));
 
       md2ReturnLocGen.put(md, new ReturnLocGenerator(md2ReturnLoc.get(md), md, paramList, md
           + " of " + cd.getSourceFileName()));
@@ -875,8 +874,8 @@ public class FlowDownCheck {
 
       }
 
-      System.out.println("\n#checkLocationFromMethodInvokeNode=" + min.printNode(0)
-          + " baseLocation=" + baseLocation + " constraint=" + constraint);
+//      System.out.println("\n#checkLocationFromMethodInvokeNode=" + min.printNode(0)
+//          + " baseLocation=" + baseLocation + " constraint=" + constraint);
 
       if (constraint != null) {
         int compareResult =
@@ -890,8 +889,8 @@ public class FlowDownCheck {
           // no need to check constraints!
           CompositeLocation calleeConstraint =
               translateCallerLocToCalleeLoc(calleeMD, baseLocation, constraint);
-          System.out.println("check method body for constraint:" + calleeMD + " calleeConstraint="
-              + calleeConstraint);
+//          System.out.println("check method body for constraint:" + calleeMD + " calleeConstraint="
+//              + calleeConstraint);
           checkMethodBody(calleeMD.getClassDesc(), calleeMD, calleeConstraint);
         }
       }
@@ -965,8 +964,8 @@ public class FlowDownCheck {
 
     String errorMsg = generateErrorMessage(md.getClassDesc(), min);
 
-    System.out.println("checkCallerArgumentLocationConstraints=" + min.printNode(0));
-    System.out.println("base location=" + callerBaseLoc + " constraint=" + constraint);
+//    System.out.println("checkCallerArgumentLocationConstraints=" + min.printNode(0));
+//    System.out.println("base location=" + callerBaseLoc + " constraint=" + constraint);
 
     for (int i = 0; i < calleeParamList.size(); i++) {
       CompositeLocation calleeParamLoc = calleeParamList.get(i);
@@ -1011,7 +1010,7 @@ public class FlowDownCheck {
       translate.addLocation(calleeParamLoc.get(i));
     }
 
-    System.out.println("TRANSLATED=" + translate + " from calleeParamLoc=" + calleeParamLoc);
+//    System.out.println("TRANSLATED=" + translate + " from calleeParamLoc=" + calleeParamLoc);
 
     return translate;
   }
@@ -1032,9 +1031,9 @@ public class FlowDownCheck {
       argList.add(callerArg);
     }
 
-    System.out.println("\n## computeReturnLocation=" + min.getMethod() + " argList=" + argList);
+//    System.out.println("\n## computeReturnLocation=" + min.getMethod() + " argList=" + argList);
     CompositeLocation ceilLoc = md2ReturnLocGen.get(min.getMethod()).computeReturnLocation(argList);
-    System.out.println("## ReturnLocation=" + ceilLoc);
+//    System.out.println("## ReturnLocation=" + ceilLoc);
 
     return ceilLoc;
 
@@ -1043,7 +1042,7 @@ public class FlowDownCheck {
   private void checkCalleeConstraints(MethodDescriptor md, SymbolTable nametable,
       MethodInvokeNode min, CompositeLocation callerBaseLoc, CompositeLocation constraint) {
 
-    System.out.println("checkCalleeConstraints=" + min.printNode(0));
+//    System.out.println("checkCalleeConstraints=" + min.printNode(0));
 
     MethodDescriptor calleemd = min.getMethod();
 
@@ -1077,7 +1076,7 @@ public class FlowDownCheck {
       for (int i = 0; i < calleemd.numParameters(); i++) {
         VarDescriptor calleevd = (VarDescriptor) calleemd.getParameter(i);
         CompositeLocation calleeLoc = d2loc.get(calleevd);
-        System.out.println("calleevd=" + calleevd + " loc=" + calleeLoc);
+//        System.out.println("calleevd=" + calleevd + " loc=" + calleeLoc);
         calleeParamList.add(calleeLoc);
       }
 
@@ -1097,8 +1096,8 @@ public class FlowDownCheck {
               continue CHECK;
             }
 
-            System.out.println("calleeLoc1=" + calleeLoc1);
-            System.out.println("calleeLoc2=" + calleeLoc2 + "calleeParamList=" + calleeParamList);
+//            System.out.println("calleeLoc1=" + calleeLoc1);
+//            System.out.println("calleeLoc2=" + calleeLoc2 + "calleeParamList=" + calleeParamList);
 
             int callerResult =
                 CompositeLattice.compare(callerLoc1, callerLoc2, true,
@@ -1197,11 +1196,11 @@ public class FlowDownCheck {
       // addTypeLocation(on.getRight().getType(), rightLoc);
     }
 
-    System.out.println("\n# OP NODE=" + on.printNode(0));
-    System.out.println("# left loc=" + leftLoc + " from " + on.getLeft().getClass());
-    if (on.getRight() != null) {
-      System.out.println("# right loc=" + rightLoc + " from " + on.getRight().getClass());
-    }
+//    System.out.println("\n# OP NODE=" + on.printNode(0));
+//    System.out.println("# left loc=" + leftLoc + " from " + on.getLeft().getClass());
+//    if (on.getRight() != null) {
+//      System.out.println("# right loc=" + rightLoc + " from " + on.getRight().getClass());
+//    }
 
     Operation op = on.getOp();
 
@@ -1240,7 +1239,7 @@ public class FlowDownCheck {
       inputSet.add(rightLoc);
       CompositeLocation glbCompLoc =
           CompositeLattice.calculateGLB(inputSet, generateErrorMessage(cd, on));
-      System.out.println("# glbCompLoc=" + glbCompLoc);
+//      System.out.println("# glbCompLoc=" + glbCompLoc);
       return glbCompLoc;
 
     default:
@@ -1363,26 +1362,25 @@ public class FlowDownCheck {
     }
 
     if (left instanceof ArrayAccessNode) {
-      System.out.println("HEREE!!");
       ArrayAccessNode aan = (ArrayAccessNode) left;
       left = aan.getExpression();
     }
 
     loc = checkLocationFromExpressionNode(md, nametable, left, loc, constraint, false);
-    System.out.println("### checkLocationFromFieldAccessNode=" + fan.printNode(0));
-    System.out.println("### left=" + left.printNode(0));
+//    System.out.println("### checkLocationFromFieldAccessNode=" + fan.printNode(0));
+//    System.out.println("### left=" + left.printNode(0));
     if (!left.getType().isPrimitive()) {
       Location fieldLoc = getFieldLocation(fd);
       loc.addLocation(fieldLoc);
     }
-    System.out.println("### field loc=" + loc);
+//    System.out.println("### field loc=" + loc);
     return loc;
   }
 
   private Location getFieldLocation(FieldDescriptor fd) {
 
-    System.out.println("### getFieldLocation=" + fd);
-    System.out.println("### fd.getType().getExtension()=" + fd.getType().getExtension());
+//    System.out.println("### getFieldLocation=" + fd);
+//    System.out.println("### fd.getType().getExtension()=" + fd.getType().getExtension());
 
     Location fieldLoc = (Location) fd.getType().getExtension();
 
@@ -1399,7 +1397,7 @@ public class FlowDownCheck {
   private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md,
       SymbolTable nametable, AssignmentNode an, CompositeLocation loc, CompositeLocation constraint) {
 
-    System.out.println("\n# ASSIGNMENTNODE=" + an.printNode(0));
+//    System.out.println("\n# ASSIGNMENTNODE=" + an.printNode(0));
 
     ClassDescriptor cd = md.getClassDesc();
 
@@ -1435,10 +1433,10 @@ public class FlowDownCheck {
       }
       // }
 
-      System.out.println("dstLocation=" + destLocation);
-      System.out.println("rhsLocation=" + rhsLocation);
-      System.out.println("srcLocation=" + srcLocation);
-      System.out.println("constraint=" + constraint);
+//      System.out.println("dstLocation=" + destLocation);
+//      System.out.println("rhsLocation=" + rhsLocation);
+//      System.out.println("srcLocation=" + srcLocation);
+//      System.out.println("constraint=" + constraint);
 
       if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) {
 
@@ -1466,9 +1464,9 @@ public class FlowDownCheck {
         srcLocation = rhsLocation;
       }
 
-      System.out.println("srcLocation=" + srcLocation);
-      System.out.println("rhsLocation=" + rhsLocation);
-      System.out.println("constraint=" + constraint);
+//      System.out.println("srcLocation=" + srcLocation);
+//      System.out.println("rhsLocation=" + rhsLocation);
+//      System.out.println("constraint=" + constraint);
 
       if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) {
 
@@ -1564,7 +1562,7 @@ public class FlowDownCheck {
     Descriptor d = state.getClassSymbolTable().get(className);
 
     if (d == null) {
-      System.out.println("state.getClassSymbolTable()=" + state.getClassSymbolTable());
+//      System.out.println("state.getClassSymbolTable()=" + state.getClassSymbolTable());
       throw new Error("The class in the location declaration '" + decl + "' does not exist at "
           + msg);
     }
@@ -1600,7 +1598,6 @@ public class FlowDownCheck {
     SSJavaLattice<String> localLattice = CompositeLattice.getLatticeByDescriptor(md);
     Location localLoc = new Location(md, localLocId);
     if (localLattice == null || (!localLattice.containsKey(localLocId))) {
-      System.out.println("locDec=" + locDec);
       throw new Error("Location " + localLocId
           + " is not defined in the local variable lattice at "
           + md.getClassDesc().getSourceFileName() + "::" + (n != null ? n.getNumLine() : md) + ".");
@@ -1702,7 +1699,7 @@ public class FlowDownCheck {
 
     public static boolean isGreaterThan(CompositeLocation loc1, CompositeLocation loc2, String msg) {
 
-      System.out.println("\nisGreaterThan=" + loc1 + " " + loc2 + " msg=" + msg);
+//      System.out.println("\nisGreaterThan=" + loc1 + " " + loc2 + " msg=" + msg);
       int baseCompareResult = compareBaseLocationSet(loc1, loc2, true, false, msg);
       if (baseCompareResult == ComparisonResult.EQUAL) {
         if (compareDelta(loc1, loc2) == ComparisonResult.GREATER) {
@@ -1721,7 +1718,7 @@ public class FlowDownCheck {
     public static int compare(CompositeLocation loc1, CompositeLocation loc2, boolean ignore,
         String msg) {
 
-      System.out.println("compare=" + loc1 + " " + loc2);
+//      System.out.println("compare=" + loc1 + " " + loc2);
       int baseCompareResult = compareBaseLocationSet(loc1, loc2, false, ignore, msg);
 
       if (baseCompareResult == ComparisonResult.EQUAL) {
@@ -1838,7 +1835,7 @@ public class FlowDownCheck {
 
     public static CompositeLocation calculateGLB(Set<CompositeLocation> inputSet, String errMsg) {
 
-      System.out.println("Calculating GLB=" + inputSet);
+//      System.out.println("Calculating GLB=" + inputSet);
       CompositeLocation glbCompLoc = new CompositeLocation();
 
       // calculate GLB of the first(priority) element
@@ -1970,7 +1967,7 @@ public class FlowDownCheck {
         }
       }
 
-      System.out.println("GLB=" + glbCompLoc);
+//      System.out.println("GLB=" + glbCompLoc);
       return glbCompLoc;
 
     }
index dc3056ecf6ca493f4e1ea67ee2d39b07c621a9f6..ffda79db098ae4404a9bb6d6732b209c92b70f07 100644 (file)
@@ -31,7 +31,16 @@ public class SharedStatus {
   }
 
   public void removeVar(Location loc, Descriptor d) {
-    getStatus(loc).getFirst().remove(d);
+
+    Set<Descriptor> dSet = getStatus(loc).getFirst();
+    boolean isClared = getStatus(loc).getSecond().booleanValue();
+    dSet.remove(d);
+
+//    if (dSet.isEmpty() && !isClared) {
+      // if status has empty descriptor set and 'false' status, remove it!
+//      mapLocation2Status.remove(loc);
+//    }
+
   }
 
   public String toString() {