fix for ssJava: realized that annotation should not be a part of hash code.
[IRC.git] / Robust / src / IR / TypeDescriptor.java
index 1ca436236593d1d1769a5684938ff2978c34a493..855345789a76f69727efd793c2f889d191fbc3ce 100644 (file)
@@ -1,5 +1,9 @@
 package IR;
 
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+
 /**
  * Descriptor
  *
@@ -26,6 +30,8 @@ public class TypeDescriptor extends Descriptor {
   private int type;
   ClassDescriptor class_desc;
   boolean isClassNameRef = false;
+  
+  private Vector<AnnotationDescriptor> annotationSet;
 
   public boolean equals(Object o) {
     if (o instanceof TypeDescriptor) {
@@ -82,14 +88,12 @@ public class TypeDescriptor extends Descriptor {
            name.equals("Objectwrapper"));
   }
 
-  public TypeDescriptor makeArray(State state, boolean addflag) {
+  public TypeDescriptor makeArray(State state) {
     TypeDescriptor td=new TypeDescriptor(getSymbol());
     td.arraycount=arraycount+1;
     td.type=type;
     td.class_desc=class_desc;
-    if(addflag) {
-      state.addArrayType(td);
-    }
+    state.addArrayType(td);
     return td;
   }
 
@@ -129,6 +133,8 @@ public class TypeDescriptor extends Descriptor {
       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
@@ -143,7 +149,8 @@ public class TypeDescriptor extends Descriptor {
       return "float";
     else if (isOffset())
       return "short";
-    else throw new Error("Error Type: "+type);
+    else 
+      throw new Error("Error Type: "+type);
   }
 
   public String getRepairSymbol() {
@@ -157,6 +164,8 @@ public class TypeDescriptor extends Descriptor {
       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
@@ -176,7 +185,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";
@@ -196,7 +205,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() {
@@ -239,7 +248,7 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public boolean isPtr() {
-    return ((isClass()&&!isEnum())||isNull()||isTag()||isArray());
+    return (isClass()||isNull()||isTag()||isArray());
   }
 
   public boolean isIntegerType() {
@@ -251,7 +260,7 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public boolean isPrimitive() {
-    return ((type>=BYTE)&&(type<=DOUBLE));
+    return (((type>=BYTE)&&(type<=DOUBLE)) || isEnum());
   }
 
   public boolean isEnum() {
@@ -264,7 +273,7 @@ public class TypeDescriptor extends Descriptor {
   }
   
   public boolean isClass() {
-    return type==CLASS;
+    return (type==CLASS && !isEnum());
   }
 
   public boolean isTag() {
@@ -281,6 +290,7 @@ public class TypeDescriptor extends Descriptor {
     this.class_desc=null;
     this.arraycount=0;
     this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public TypeDescriptor(String st) {
@@ -289,6 +299,7 @@ public class TypeDescriptor extends Descriptor {
     this.class_desc=null;
     this.arraycount=0;
     this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public ClassDescriptor getClassDesc() {
@@ -301,6 +312,7 @@ public class TypeDescriptor extends Descriptor {
     this.class_desc=cd;
     this.arraycount=0;
     this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public TypeDescriptor(int t) {
@@ -308,6 +320,7 @@ public class TypeDescriptor extends Descriptor {
     this.type=t;
     this.arraycount=0;
     this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public String toString() {
@@ -347,11 +360,20 @@ 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;
+  }
+  
 }