changes: fixes the case that a shared location appears in the middle of a composite...
[IRC.git] / Robust / src / Analysis / SSJava / CompositeLocation.java
index 0dd524db8fd7f06f4b00d80f927d294326a6cc91..f7e550c55ba7c8cc6f03989baf66c748f646d3c6 100644 (file)
@@ -10,9 +10,13 @@ public class CompositeLocation implements TypeExtension {
     locTuple = new NTuple<Location>();
   }
 
+  public CompositeLocation(NTuple<Location> locTuple) {
+    this.locTuple = locTuple.clone();
+  }
+
   public CompositeLocation(Location loc) {
     locTuple = new NTuple<Location>();
-    locTuple.addElement(loc);
+    locTuple.add(loc);
   }
 
   public NTuple<Location> getTuple() {
@@ -24,145 +28,31 @@ public class CompositeLocation implements TypeExtension {
   }
 
   public void addLocation(Location loc) {
-    locTuple.addElement(loc);
+    locTuple.add(loc);
   }
 
   public Location get(int idx) {
     return locTuple.get(idx);
   }
-  
-  public boolean isEmpty(){
-    return locTuple.size()==0;
-  }
 
-  // public void addLocationSet(Set<Location> set) {
-  //
-  // for (Iterator iterator = set.iterator(); iterator.hasNext();) {
-  // Location location = (Location) iterator.next();
-  // locTuple.addElement(location);
-  // }
-  //
-  // }
-
-  // public Location getLocation(ClassDescriptor cd) {
-  //
-  // // need to get more optimization version later
-  // Set<Location> locSet = getBaseLocationSet();
-  // for (Iterator iterator = locSet.iterator(); iterator.hasNext();) {
-  // Location location = (Location) iterator.next();
-  // if (location.getClassDescriptor().equals(cd)) {
-  // return location;
-  // }
-  // }
-  //
-  // return null;
-  //
-  // }
-
-  // public Map<ClassDescriptor, Location> getCd2Loc() {
-  //
-  // Map<ClassDescriptor, Location> cd2loc = new Hashtable<ClassDescriptor,
-  // Location>();
-  //
-  // Set<Location> baseLocSet = getBaseLocationSet();
-  // for (Iterator iterator = baseLocSet.iterator(); iterator.hasNext();) {
-  // Location location = (Location) iterator.next();
-  // cd2loc.put(location.getClassDescriptor(), location);
-  // }
-  //
-  // return cd2loc;
-  //
-  // }
-
-  public NTuple<Location> getBaseLocationTuple() {
+  public boolean isEmpty() {
+    return locTuple.size() == 0;
+  }
 
-    return locTuple;
+  public boolean startsWith(CompositeLocation prefix) {
+    // tests if this composite location starts with the prefix
 
-    // NTuple<Location> baseLocationTuple = new NTuple<Location>();
-    // int tupleSize = locTuple.size();
-    // for (int i = 0; i < tupleSize; i++) {
-    // Location locElement = locTuple.at(i);
-    //
-    // if (locElement instanceof DeltaLocation) {
-    // // baseLocationSet.addAll(((DeltaLocation)
-    // // locElement).getDeltaOperandLocationVec());
-    // baseLocationTuple.addAll(((DeltaLocation)
-    // locElement).getBaseLocationTuple());
-    // } else {
-    // baseLocationTuple.addElement(locElement);
-    // }
-    // }
-    // return baseLocationTuple;
+    for (int i = 0; i < prefix.getSize(); i++) {
+      if (!prefix.get(i).equals(get(i))) {
+        return false;
+      }
+    }
+    return true;
 
   }
 
-  // public List<Location> getBaseLocationList() {
-  //
-  // Set<Location> baseLocationSet = new HashSet<Location>();
-  // int tupleSize = locTuple.size();
-  // for (int i = 0; i < tupleSize; i++) {
-  // Location locElement = locTuple.at(i);
-  //
-  // if (locElement instanceof DeltaLocation) {
-  // // baseLocationSet.addAll(((DeltaLocation)
-  // // locElement).getDeltaOperandLocationVec());
-  // baseLocationSet.addAll(((DeltaLocation) locElement).getBaseLocationSet());
-  // } else {
-  // baseLocationSet.add(locElement);
-  // }
-  // }
-  // return baseLocationSet;
-  // }
-
-  // public int getNumofDelta() {
-  //
-  // int result = 0;
-  //
-  // if (locTuple.size() == 1) {
-  // Location locElement = locTuple.at(0);
-  // if (locElement instanceof DeltaLocation) {
-  // result++;
-  // result += getNumofDelta((DeltaLocation) locElement);
-  // }
-  // }
-  // return result;
-  // }
-
-  // public int getNumofDelta(DeltaLocation delta) {
-  // int result = 0;
-  //
-  // if (delta.getDeltaOperandLocationVec().size() == 1) {
-  // Location locElement = delta.getDeltaOperandLocationVec().at(0);
-  // if (locElement instanceof DeltaLocation) {
-  // result++;
-  // result += getNumofDelta((DeltaLocation) locElement);
-  // }
-  // }
-  //
-  // return result;
-  // }
-
-  // public void removieLocation(ClassDescriptor cd) {
-  // for (int i = 0; i < locTuple.size(); i++) {
-  // if (locTuple.at(i).getClassDescriptor().equals(cd)) {
-  // locTuple.removeAt(i);
-  // return;
-  // }
-  // }
-  // }
-
   public String toString() {
 
-    // for better representation
-    // if compositeLoc has only one single location,
-    // just print out single location
-    // if(locTuple.size()==1){
-    // Location locElement=locTuple.at(0);
-    // if(locElement instanceof Location){
-    // return locElement.toString();
-    // }
-    // }
-
     String rtr = "CompLoc[";
 
     int tupleSize = locTuple.size();
@@ -200,4 +90,10 @@ public class CompositeLocation implements TypeExtension {
 
   }
 
+  public CompositeLocation clone() {
+    CompositeLocation clone = new CompositeLocation();
+    clone.getTuple().addAll(locTuple);
+    return clone;
+  }
+
 }