changes: building field/method hierarchy graph + inserting combination nodes at the...
[IRC.git] / Robust / src / Analysis / SSJava / LocationInfo.java
index 8709ad30e34e59a7d1a1f0f865aae23ff6d8fef6..c7cedcdf125833000d9fdda5f8989107bc5b01b0 100644 (file)
@@ -8,60 +8,112 @@ import java.util.Set;
 import IR.ClassDescriptor;
 import IR.Descriptor;
 import IR.MethodDescriptor;
+import Util.Pair;
 
 public class LocationInfo {
 
-  Map<String, Set<Descriptor>> mapLocNameToDescSet;
-  Map<String, String> mapDescSymbolToLocName;
+  Map<String, Set<Descriptor>> mapLocSymbolToDescSet;
+  Map<String, Set<Pair<Descriptor, Descriptor>>> mapLocSymbolToRelatedInferLocSet;
   Map<Descriptor, CompositeLocation> mapDescToInferCompositeLocation;
   MethodDescriptor md;
   ClassDescriptor cd;
 
   public LocationInfo() {
-    mapDescSymbolToLocName = new HashMap<String, String>();
-    mapLocNameToDescSet = new HashMap<String, Set<Descriptor>>();
     mapDescToInferCompositeLocation = new HashMap<Descriptor, CompositeLocation>();
+    mapLocSymbolToDescSet = new HashMap<String, Set<Descriptor>>();
+    mapLocSymbolToRelatedInferLocSet = new HashMap<String, Set<Pair<Descriptor, Descriptor>>>();
   }
 
   public LocationInfo(ClassDescriptor cd) {
+    this();
     this.cd = cd;
-    this.mapDescSymbolToLocName = new HashMap<String, String>();
   }
 
-  public void mapDescriptorToCompositeLocation(Descriptor desc, CompositeLocation inferLoc) {
-    mapDescToInferCompositeLocation.put(desc, inferLoc);
+  public Descriptor getDescIdentifier() {
+    if (md != null) {
+      return md;
+    }
+    {
+      return cd;
+    }
   }
 
-  public void mapDescSymbolToLocName(String descSymbol, String locName) {
-    mapDescSymbolToLocName.put(descSymbol, locName);
+  public Map<String, Set<Descriptor>> getMapLocSymbolToDescSet() {
+    return mapLocSymbolToDescSet;
   }
 
-  public String getLocName(String descSymbol) {
-    if (!mapDescSymbolToLocName.containsKey(descSymbol)) {
-      mapDescSymbolToLocName.put(descSymbol, descSymbol);
-    }
-    return mapDescSymbolToLocName.get(descSymbol);
+  public Map<Descriptor, CompositeLocation> getMapDescToInferLocation() {
+    return mapDescToInferCompositeLocation;
   }
 
-  public void addMappingOfLocNameToDescriptor(String locName, Descriptor desc) {
+  public void addMapLocSymbolToRelatedInferLoc(String locSymbol, Descriptor enclosingDesc,
+      Descriptor desc) {
+    if (!mapLocSymbolToRelatedInferLocSet.containsKey(locSymbol)) {
+      mapLocSymbolToRelatedInferLocSet.put(locSymbol, new HashSet<Pair<Descriptor, Descriptor>>());
+    }
+    mapLocSymbolToRelatedInferLocSet.get(locSymbol).add(
+        new Pair<Descriptor, Descriptor>(enclosingDesc, desc));
+
+    addMapLocSymbolToDescSet(locSymbol, desc);
+  }
 
-    // System.out.println("### MAP LocName=" + locName + " to " + desc);
+  public Set<Pair<Descriptor, Descriptor>> getRelatedInferLocSet(String locSymbol) {
 
-    if (!mapLocNameToDescSet.containsKey(locName)) {
-      mapLocNameToDescSet.put(locName, new HashSet<Descriptor>());
+    if (!mapLocSymbolToRelatedInferLocSet.containsKey(locSymbol)) {
+      mapLocSymbolToRelatedInferLocSet.put(locSymbol, new HashSet<Pair<Descriptor, Descriptor>>());
     }
+    return mapLocSymbolToRelatedInferLocSet.get(locSymbol);
+  }
 
-    mapLocNameToDescSet.get(locName).add(desc);
+  public void mapDescriptorToLocation(Descriptor desc, CompositeLocation inferLoc) {
+    mapDescToInferCompositeLocation.put(desc, inferLoc);
+  }
+
+  public CompositeLocation getInferLocation(Descriptor desc) {
+    if (!mapDescToInferCompositeLocation.containsKey(desc)) {
+      CompositeLocation newInferLoc = new CompositeLocation();
+      Location loc;
+      Descriptor enclosingDesc;
+      if (md != null) {
+        // method lattice
+        enclosingDesc = md;
+      } else {
+        enclosingDesc = cd;
+      }
+      loc = new Location(enclosingDesc, desc.getSymbol());
+
+      newInferLoc.addLocation(loc);
+      mapDescToInferCompositeLocation.put(desc, newInferLoc);
+      // addMapLocSymbolToDescSet(desc.getSymbol(), desc);
+      addMapLocSymbolToRelatedInferLoc(desc.getSymbol(), enclosingDesc, desc);
+    }
+    return mapDescToInferCompositeLocation.get(desc);
+  }
 
+  public void addMapLocSymbolToDescSet(String locSymbol, Descriptor desc) {
+    if (!mapLocSymbolToDescSet.containsKey(locSymbol)) {
+      mapLocSymbolToDescSet.put(locSymbol, new HashSet<Descriptor>());
+    }
+    mapLocSymbolToDescSet.get(locSymbol).add(desc);
   }
 
-  public Set<Descriptor> getFlowNodeSet(String locName) {
+  public Location getFieldInferLocation(Descriptor desc) {
+    return getInferLocation(desc).get(0);
+  }
 
-    if (!mapLocNameToDescSet.containsKey(locName)) {
-      mapLocNameToDescSet.put(locName, new HashSet<Descriptor>());
+  public Set<Descriptor> getDescSet(String locSymbol) {
+    if (!mapLocSymbolToDescSet.containsKey(locSymbol)) {
+      mapLocSymbolToDescSet.put(locSymbol, new HashSet<Descriptor>());
     }
+    return mapLocSymbolToDescSet.get(locSymbol);
+  }
 
-    return mapLocNameToDescSet.get(locName);
+  public void removeRelatedInferLocSet(String oldLocSymbol, String newSharedLoc) {
+    Set<Descriptor> descSet = getDescSet(oldLocSymbol);
+    getDescSet(newSharedLoc).addAll(descSet);
+    // getRelatedInferLocSet(newSharedLoc).addAll(getRelatedInferLocSet(oldLocSymbol));
+    mapLocSymbolToDescSet.remove(oldLocSymbol);
+    mapLocSymbolToRelatedInferLocSet.remove(oldLocSymbol);
   }
 
 }