changes to MGC class library
[IRC.git] / Robust / src / IR / TypeDescriptor.java
index cb67bb9308be3f332b37d19b7536910cc97f4d35..431d964dc0d1d76572f17fb2b2951506890ce7ef 100644 (file)
@@ -1,5 +1,9 @@
 package IR;
 
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Vector;
+
 /**
  * Descriptor
  *
@@ -27,15 +31,18 @@ public class TypeDescriptor extends Descriptor {
   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;
@@ -52,11 +59,11 @@ public class TypeDescriptor extends Descriptor {
       return false;
     return true;
   }
-  
+
   public boolean isClassNameRef() {
     return this.isClassNameRef;
   }
-  
+
   public void setClassNameRef() {
     this.isClassNameRef = true;
   }
@@ -72,14 +79,14 @@ public class TypeDescriptor extends Descriptor {
     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"));
+            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) {
@@ -127,6 +134,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
@@ -141,7 +150,9 @@ public class TypeDescriptor extends Descriptor {
       return "float";
     else if (isOffset())
       return "short";
-    else 
+    else if (isNull())
+      return "null";
+    else
       throw new Error("Error Type: "+type);
   }
 
@@ -156,6 +167,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
@@ -175,7 +188,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";
@@ -195,7 +208,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() {
@@ -238,7 +251,7 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public boolean isPtr() {
-    return ((isClass()&&!isEnum())||isNull()||isTag()||isArray());
+    return (isClass()||isNull()||isTag()||isArray());
   }
 
   public boolean isIntegerType() {
@@ -250,20 +263,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){
+    } 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() {
@@ -271,7 +284,7 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public boolean isImmutable() {
-    return isPrimitive() || isString();
+    return isPrimitive();
   }
 
   public TypeDescriptor(NameDescriptor name) {
@@ -280,6 +293,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) {
@@ -288,6 +302,7 @@ public class TypeDescriptor extends Descriptor {
     this.class_desc=null;
     this.arraycount=0;
     this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public ClassDescriptor getClassDesc() {
@@ -300,6 +315,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) {
@@ -307,6 +323,7 @@ public class TypeDescriptor extends Descriptor {
     this.type=t;
     this.arraycount=0;
     this.isClassNameRef =false;
+    this.annotationSet=new Vector<AnnotationDescriptor>();
   }
 
   public String toString() {
@@ -323,7 +340,7 @@ public class TypeDescriptor extends Descriptor {
     }
     for(int i=0; i<arraycount; i++)
       str+="[]";
-    return str;    
+    return str;
   }
 
   private static String decodeInt(int type) {
@@ -353,4 +370,21 @@ public class TypeDescriptor extends Descriptor {
       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;
+  }
+
 }