changes: now Inference engine works fine with the EyeTracking benchmark.
[IRC.git] / Robust / src / Analysis / SSJava / Location.java
index 7f04ce9a52814aaa52c1d43b4fd7b76b1a6ea2de..6137379c93fb91bbd1f6e53f195a9454a1fc8c1f 100644 (file)
@@ -1,35 +1,67 @@
 package Analysis.SSJava;
 
-import IR.ClassDescriptor;
+import IR.Descriptor;
 import IR.TypeExtension;
 
-public class Location  implements TypeExtension {
+public class Location implements TypeExtension {
 
   public static final int TOP = 1;
   public static final int NORMAL = 2;
   public static final int BOTTOM = 3;
-  public static final int DELTA = 4;
 
   int type;
-  ClassDescriptor cd;
+  Descriptor d;
   String loc;
+  Descriptor locDesc;
 
-  public Location(ClassDescriptor cd, String loc) {
-    this.cd = cd;
+  public Location(Descriptor enclosingDesc, Descriptor locDesc) {
+    this.d = enclosingDesc;
+    this.locDesc = locDesc;
+    this.loc = locDesc.getSymbol();
+  }
+
+  public Location(Descriptor d, String loc) {
+    this.d = d;
     this.loc = loc;
-    this.type = NORMAL;
+
+    if (loc.equals(SSJavaAnalysis.TOP)) {
+      type = TOP;
+    } else if (loc.equals(SSJavaAnalysis.BOTTOM)) {
+      type = BOTTOM;
+    } else {
+      type = NORMAL;
+    }
+
+  }
+
+  public Location(Descriptor d, int type) {
+    this.d = d;
+    this.type = type;
+    if (type == TOP) {
+      loc = SSJavaAnalysis.TOP;
+    } else if (type == BOTTOM) {
+      loc = SSJavaAnalysis.BOTTOM;
+    }
   }
 
-  public Location(ClassDescriptor cd) {
-    this.cd = cd;
+  public void setLocIdentifier(String s) {
+    loc = s;
+  }
+
+  public void setLocDescriptor(Descriptor d) {
+    locDesc = d;
+  }
+
+  public Descriptor getLocDescriptor() {
+    return locDesc;
   }
 
   public void setType(int type) {
     this.type = type;
   }
 
-  public ClassDescriptor getClassDescriptor() {
-    return cd;
+  public Descriptor getDescriptor() {
+    return d;
   }
 
   public String getLocIdentifier() {
@@ -47,13 +79,16 @@ public class Location  implements TypeExtension {
 
     Location loc = (Location) o;
 
-    if (loc.getClassDescriptor().equals(getClassDescriptor())) {
+    if (loc.getDescriptor().equals(getDescriptor())) {
       if (loc.getLocIdentifier() == null || getLocIdentifier() == null) {
         if (loc.getType() == getType()) {
           return true;
         }
       } else {
-        if (loc.getLocIdentifier().equals(getLocIdentifier())) {
+        if (loc.getLocDescriptor() != null && getLocDescriptor() != null
+            && loc.getLocDescriptor().equals(getLocDescriptor())) {
+          return true;
+        } else if (loc.getLocIdentifier().equals(getLocIdentifier())) {
           return true;
         }
       }
@@ -64,34 +99,37 @@ public class Location  implements TypeExtension {
 
   public int hashCode() {
 
-    int hash = cd.hashCode();
+    int hash = d.hashCode();
     if (loc != null) {
       hash += loc.hashCode();
     }
+    if (locDesc != null) {
+      hash += locDesc.hashCode();
+    }
     return hash;
 
   }
 
   public String toString() {
-    return "Loc[" + cd.getSymbol() + "." + loc + "]";
+    return "Loc[" + d.getSymbol() + "." + loc + "]";
+  }
+
+  public String getSymbol() {
+    return d.getSymbol() + "." + loc;
   }
 
-  public static Location createTopLocation(ClassDescriptor cd) {
-    Location topLoc = new Location(cd);
-    topLoc.setType(TOP);
-    topLoc.loc = "_top_";
+  public static Location createTopLocation(Descriptor d) {
+    Location topLoc = new Location(d, TOP);
     return topLoc;
   }
 
-  public static Location createBottomLocation(ClassDescriptor cd) {
-    Location bottomLoc = new Location(cd);
-    bottomLoc.setType(BOTTOM);
-    bottomLoc.loc = "_bottom_";
+  public static Location createBottomLocation(Descriptor d) {
+    Location bottomLoc = new Location(d, BOTTOM);
     return bottomLoc;
   }
-  
-  public boolean isTop(){
-    return type==TOP;
+
+  public boolean isTop() {
+    return type == TOP;
   }
 
 }