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);
+ public Map<Descriptor, CompositeLocation> getMapDescToInferLocation() {
+ return mapDescToInferCompositeLocation;
+ }
+
+ public void addMapLocSymbolToRelatedInferLoc(String locSymbol, Descriptor enclosingDesc,
+ Descriptor desc) {
+ if (!mapLocSymbolToRelatedInferLocSet.containsKey(locSymbol)) {
+ mapLocSymbolToRelatedInferLocSet.put(locSymbol, new HashSet<Pair<Descriptor, Descriptor>>());
}
- return mapDescSymbolToLocName.get(descSymbol);
+ mapLocSymbolToRelatedInferLocSet.get(locSymbol).add(
+ new Pair<Descriptor, Descriptor>(enclosingDesc, desc));
}
- public void addMappingOfLocNameToDescriptor(String locName, Descriptor desc) {
+ public Set<Pair<Descriptor, Descriptor>> getRelatedInferLocSet(String locSymbol) {
+ return mapLocSymbolToRelatedInferLocSet.get(locSymbol);
+ }
- // System.out.println("### MAP LocName=" + locName + " to " + desc);
+ public void mapDescriptorToLocation(Descriptor desc, CompositeLocation inferLoc) {
+ mapDescToInferCompositeLocation.put(desc, inferLoc);
+ }
- if (!mapLocNameToDescSet.containsKey(locName)) {
- mapLocNameToDescSet.put(locName, new HashSet<Descriptor>());
+ 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);
+ }
- mapLocNameToDescSet.get(locName).add(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);
}
}