switch to spaces only..
[IRC.git] / Robust / src / Analysis / Locality / LocalityBinding.java
index d10d9b28de9c8f9e0b18e73f801627ae573690a1..3da793fc0b7caad568eac8eeab2f7dd4217e888b 100644 (file)
@@ -25,7 +25,9 @@ public class LocalityBinding {
   }
 
   private static String globalToString(Integer g) {
-    if (g==LocalityAnalysis.GLOBAL)
+    if (g==null)
+      return "";
+    else if (g==LocalityAnalysis.GLOBAL)
       return "G";
     else if (g==LocalityAnalysis.LOCAL)
       return "L";
@@ -33,7 +35,15 @@ public class LocalityBinding {
       return "E";
     else if (g==LocalityAnalysis.CONFLICT)
       return "C";
-    else throw new Error();
+    else if (g==LocalityAnalysis.SCRATCH)
+      return "S";
+    else if (g==LocalityAnalysis.NORMAL)
+      return "R";
+    else if (g==(LocalityAnalysis.STMCONFLICT))
+      return "C";
+    else if (g==(LocalityAnalysis.STMEITHER))
+      return "E";
+    else throw new Error("unknown value"+g);
   }
 
   public String getSignature() {
@@ -73,23 +83,29 @@ public class LocalityBinding {
       st+="[static] ";
     } else {
       if (isglobalthis.equals(LocalityAnalysis.LOCAL))
-       st+="[local] ";
+        st+="[local] ";
       else if (isglobalthis.equals(LocalityAnalysis.GLOBAL))
-       st+="[global] ";
+        st+="[global] ";
       else if (isglobalthis.equals(LocalityAnalysis.EITHER))
-       st+="[either] ";
+        st+="[either] ";
       else if (isglobalthis.equals(LocalityAnalysis.CONFLICT))
-       st+="[conflict] ";
+        st+="[conflict] ";
+      else
+        st+="[this="+isglobalthis+"]";
     }
     for(int i=0; i<isglobal.length; i++)
-      if (isglobal[i].equals(LocalityAnalysis.LOCAL))
-       st+="local ";
+      if (isglobal[i]==null)
+        st+="NULL";
+      else if (isglobal[i].equals(LocalityAnalysis.LOCAL))
+        st+="local ";
       else if (isglobal[i].equals(LocalityAnalysis.GLOBAL))
-       st+="global ";
+        st+="global ";
       else if (isglobal[i].equals(LocalityAnalysis.EITHER))
-       st+="either ";
+        st+="either ";
       else if (isglobal[i].equals(LocalityAnalysis.CONFLICT))
-       st+="conflict ";
+        st+="conflict ";
+      else
+        st+="["+isglobal[i]+"]";
     return st;
   }
 
@@ -129,34 +145,34 @@ public class LocalityBinding {
     if (isglobal.length!=lb.isglobal.length)
       return false;
     for(int i=0; i<isglobal.length; i++)
-      if (!isglobal[i].equals(lb.isglobal[i]))
-       return false;
+      if (!equiv(isglobal[i],lb.isglobal[i]))
+        return false;
 
-    if (isglobalthis==null) {
-      if (lb.isglobalthis!=null)
-       return false;
-    } else
-    if (!isglobalthis.equals(lb.isglobalthis))
+    if (!equiv(isglobalthis, lb.isglobalthis))
       return false;
     return (isatomic==lb.isatomic);
   }
 
+  public static boolean equiv(Integer a, Integer b) {
+    if (a==null) {
+      return b==null;
+    } else if (b==null) {
+      return a==null;
+    } else return a.equals(b);
+  }
+
   public boolean equals(Object o) {
     if (o instanceof LocalityBinding) {
       LocalityBinding lb=(LocalityBinding)o;
       if (md!=lb.md)
-       return false;
+        return false;
 
       for(int i=0; i<isglobal.length; i++)
-       if (!isglobal[i].equals(lb.isglobal[i]))
-         return false;
-
-      if (isglobalthis==null) {
-       if (lb.isglobalthis!=null)
-         return false;
-      } else
-      if (!isglobalthis.equals(lb.isglobalthis))
-       return false;
+        if (!equiv(isglobal[i], lb.isglobal[i]))
+          return false;
+
+      if (!equiv(isglobalthis, lb.isglobalthis))
+        return false;
       return (isatomic==lb.isatomic);
     }
     return false;
@@ -165,9 +181,10 @@ public class LocalityBinding {
   public int hashCode() {
     int hashcode=md.hashCode();
     for(int i=0; i<isglobal.length; i++) {
-      hashcode=hashcode*31+(isglobal[i].intValue());
+      if (isglobal[i]!=null)
+        hashcode=hashcode*31+(isglobal[i].intValue());
     }
-    hashcode=hashcode*31+(isatomic ? 1 : 0);
+    hashcode=hashcode*31+(isatomic?1:0);
     return hashcode;
   }
 }