fixes on analyses to compile the eyetracking benchmark
[IRC.git] / Robust / src / IR / TypeDescriptor.java
index 579b4dd5c19fe6290590625c56f4b2cb55454fd0..dfaf3550e600cad9dc908bf117b5426e09883713 100644 (file)
@@ -1,5 +1,9 @@
 package IR;
 
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+
 /**
  * Descriptor
  *
@@ -19,21 +23,28 @@ public class TypeDescriptor extends Descriptor {
   public static final int NULL=10;
   public static final int TAG=11;
   public static final int CLASS=12;
+  public static final int OFFSET=13;
 
 
   int arraycount;
-  int type;
+  private int type;
   ClassDescriptor class_desc;
+  boolean isClassNameRef = false;
+
+  private Vector<AnnotationDescriptor> annotationSet;
+  private TypeExtension typeExtension;
 
   public boolean equals(Object o) {
     if (o instanceof TypeDescriptor) {
       TypeDescriptor t=(TypeDescriptor)o;
       if (t.type!=type)
-       return false;
+        return false;
       if ((type==CLASS)&&(!t.getSymbol().equals(getSymbol())))
-       return false;
+        return false;
       if (t.arraycount!=arraycount)
-       return false;
+        return false;
+      if (t.isClassNameRef != this.isClassNameRef)
+        return false;
       return true;
     }
     return false;
@@ -49,6 +60,14 @@ public class TypeDescriptor extends Descriptor {
     return true;
   }
 
+  public boolean isClassNameRef() {
+    return this.isClassNameRef;
+  }
+
+  public void setClassNameRef() {
+    this.isClassNameRef = true;
+  }
+
   public int hashCode() {
     int hashcode=type^arraycount;
     if (type==CLASS)
@@ -56,6 +75,20 @@ public class TypeDescriptor extends Descriptor {
     return hashcode;
   }
 
+  public boolean iswrapper() {
+    if (arraycount!=0||!isClass())
+      return false;
+    return (name.equals("bytewrapper")||
+            name.equals("booleanwrapper")||
+            name.equals("shortwrapper")||
+            name.equals("intwrapper")||
+            name.equals("longwrapper")||
+            name.equals("charwrapper")||
+            name.equals("floatwrapper")||
+            name.equals("doublewrapper")||
+            name.equals("Objectwrapper"));
+  }
+
   public TypeDescriptor makeArray(State state) {
     TypeDescriptor td=new TypeDescriptor(getSymbol());
     td.arraycount=arraycount+1;
@@ -73,6 +106,13 @@ public class TypeDescriptor extends Descriptor {
     return arraycount;
   }
 
+  /* Only use this method if you really know what you are doing.  It
+   * doesn't have the effect you might expect. */
+
+  public void setArrayCount(int a) {
+    arraycount=a;
+  }
+
   public TypeDescriptor dereference() {
     TypeDescriptor td=new TypeDescriptor(getSymbol());
     if (arraycount==0)
@@ -86,14 +126,16 @@ public class TypeDescriptor extends Descriptor {
   public String getSafeSymbol() {
     if (isArray())
       return IR.Flat.BuildCode.arraytype;
-    else if (isClass())
+    else if (isClass()) {
       return class_desc.getSafeSymbol();
-    else if (isByte())
+    else if (isByte())
       return "char";
     else if (isChar())
       return "short";
     else if (isShort())
       return "short";
+    else if (isEnum())
+      return "int";
     else if (isInt())
       return "int";
     else if (isBoolean())     //Booleans are ints in C
@@ -106,20 +148,25 @@ public class TypeDescriptor extends Descriptor {
       return "double";
     else if (isFloat())
       return "float";
-    else throw new Error("Error Type: "+type);
+    else if (isOffset())
+      return "short";
+    else
+      throw new Error("Error Type: "+type);
   }
 
   public String getRepairSymbol() {
     if (isArray())
       return IR.Flat.BuildCode.arraytype;
-    else if (isClass())
+    else if (isClass()) {
       return class_desc.getSymbol();
-    else if (isByte())
+    else if (isByte())
       return "byte";
     else if (isChar())
       return "short";
     else if (isShort())
       return "short";
+    else if (isEnum())
+      return "int";
     else if (isInt())
       return "int";
     else if (isBoolean())     //Booleans are ints in C
@@ -139,7 +186,7 @@ public class TypeDescriptor extends Descriptor {
     //Can't safely use [ in C
     if (isArray())
       return "_AR_"+this.dereference().getSafeDescriptor();
-    else if (isClass())
+    else if (isClass()||isEnum())
       return class_desc.getSafeDescriptor();
     else if (isByte())
       return "B";
@@ -159,7 +206,7 @@ public class TypeDescriptor extends Descriptor {
       return "F";
     else if (isTag())
       return "T";
-    else throw new Error();
+    else throw new Error(toString());
   }
 
   public boolean isNumber() {
@@ -197,12 +244,16 @@ public class TypeDescriptor extends Descriptor {
     return type==VOID;
   }
 
+  public boolean isOffset() {
+    return type==OFFSET;
+  }
+
   public boolean isPtr() {
     return (isClass()||isNull()||isTag()||isArray());
   }
 
   public boolean isIntegerType() {
-    return (isInt()||isLong()||isShort()||isChar()||isByte());
+    return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
   }
 
   public void setClassDescriptor(ClassDescriptor cd) {
@@ -210,11 +261,20 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public boolean isPrimitive() {
-    return ((type>=BYTE)&&(type<=DOUBLE));
+    return (((type>=BYTE)&&(type<=DOUBLE)) || isEnum());
+  }
+
+  public boolean isEnum() {
+    if(this.type != CLASS) {
+      return false;
+    } else if(this.class_desc != null) {
+      return this.class_desc.isEnum();
+    }
+    return false;
   }
 
   public boolean isClass() {
-    return type==CLASS;
+    return (type==CLASS && !isEnum());
   }
 
   public boolean isTag() {
@@ -222,7 +282,7 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public boolean isImmutable() {
-    return isPrimitive() || isString();
+    return isPrimitive();
   }
 
   public TypeDescriptor(NameDescriptor name) {
@@ -230,6 +290,8 @@ public class TypeDescriptor extends Descriptor {
     this.type=CLASS;
     this.class_desc=null;
     this.arraycount=0;
+    this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public TypeDescriptor(String st) {
@@ -237,6 +299,8 @@ public class TypeDescriptor extends Descriptor {
     this.type=CLASS;
     this.class_desc=null;
     this.arraycount=0;
+    this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public ClassDescriptor getClassDesc() {
@@ -248,12 +312,16 @@ public class TypeDescriptor extends Descriptor {
     this.type=CLASS;
     this.class_desc=cd;
     this.arraycount=0;
+    this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public TypeDescriptor(int t) {
     super(decodeInt(t));
     this.type=t;
     this.arraycount=0;
+    this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public String toString() {
@@ -264,13 +332,13 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public String toPrettyString() {
-    if (type==CLASS) {
-      String str=name;
-      for(int i=0; i<arraycount; i++)
-       str+="[]";
-      return str;
-    } else
-      return decodeInt(type);
+    String str=name;
+    if (type!=CLASS) {
+      str=decodeInt(type);
+    }
+    for(int i=0; i<arraycount; i++)
+      str+="[]";
+    return str;
   }
 
   private static String decodeInt(int type) {
@@ -293,9 +361,28 @@ public class TypeDescriptor extends Descriptor {
     else if (type==VOID)
       return "void";
     else if (type==NULL)
-      return "null";
+      return "NULL";
     else if (type==TAG)
       return TypeUtil.TagClass;
+    else if (type==OFFSET)
+      return "offset";
     else throw new Error();
   }
+
+  public void addAnnotationMarker(AnnotationDescriptor an) {
+    annotationSet.add(an);
+  }
+
+  public Vector<AnnotationDescriptor> getAnnotationMarkers() {
+    return annotationSet;
+  }
+
+  public void setExtension(TypeExtension te) {
+    typeExtension=te;
+  }
+
+  public TypeExtension getExtension() {
+    return typeExtension;
+  }
+
 }