Bug fix in array initialization: handle the special case like {{null,null}}
[IRC.git] / Robust / src / IR / TypeDescriptor.java
index 4ee6857061b497325928a45e06945bd598f03d0c..cb67bb9308be3f332b37d19b7536910cc97f4d35 100644 (file)
@@ -25,6 +25,7 @@ public class TypeDescriptor extends Descriptor {
   int arraycount;
   private int type;
   ClassDescriptor class_desc;
+  boolean isClassNameRef = false;
 
   public boolean equals(Object o) {
     if (o instanceof TypeDescriptor) {
@@ -35,6 +36,8 @@ public class TypeDescriptor extends Descriptor {
        return false;
       if (t.arraycount!=arraycount)
        return false;
+      if (t.isClassNameRef != this.isClassNameRef)
+        return false;
       return true;
     }
     return false;
@@ -49,6 +52,14 @@ public class TypeDescriptor extends Descriptor {
       return false;
     return true;
   }
+  
+  public boolean isClassNameRef() {
+    return this.isClassNameRef;
+  }
+  
+  public void setClassNameRef() {
+    this.isClassNameRef = true;
+  }
 
   public int hashCode() {
     int hashcode=type^arraycount;
@@ -58,7 +69,7 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public boolean iswrapper() {
-    if (arraycount!=0||isClass())
+    if (arraycount!=0||!isClass())
       return false;
     return (name.equals("bytewrapper")||
            name.equals("booleanwrapper")||
@@ -68,7 +79,7 @@ public class TypeDescriptor extends Descriptor {
            name.equals("charwrapper")||
            name.equals("floatwrapper")||
            name.equals("doublewrapper")||
-           name.equals("objectwrapper"));
+           name.equals("Objectwrapper"));
   }
 
   public TypeDescriptor makeArray(State state) {
@@ -108,9 +119,9 @@ 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";
@@ -130,15 +141,16 @@ 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() {
     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";
@@ -226,11 +238,11 @@ public class TypeDescriptor extends Descriptor {
   }
 
   public boolean isPtr() {
-    return (isClass()||isNull()||isTag()||isArray());
+    return ((isClass()&&!isEnum())||isNull()||isTag()||isArray());
   }
 
   public boolean isIntegerType() {
-    return (isInt()||isLong()||isShort()||isChar()||isByte());
+    return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
   }
 
   public void setClassDescriptor(ClassDescriptor cd) {
@@ -241,6 +253,15 @@ public class TypeDescriptor extends Descriptor {
     return ((type>=BYTE)&&(type<=DOUBLE));
   }
 
+  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;
   }
@@ -258,6 +279,7 @@ public class TypeDescriptor extends Descriptor {
     this.type=CLASS;
     this.class_desc=null;
     this.arraycount=0;
+    this.isClassNameRef =false;
   }
 
   public TypeDescriptor(String st) {
@@ -265,6 +287,7 @@ public class TypeDescriptor extends Descriptor {
     this.type=CLASS;
     this.class_desc=null;
     this.arraycount=0;
+    this.isClassNameRef =false;
   }
 
   public ClassDescriptor getClassDesc() {
@@ -276,12 +299,14 @@ public class TypeDescriptor extends Descriptor {
     this.type=CLASS;
     this.class_desc=cd;
     this.arraycount=0;
+    this.isClassNameRef =false;
   }
 
   public TypeDescriptor(int t) {
     super(decodeInt(t));
     this.type=t;
     this.arraycount=0;
+    this.isClassNameRef =false;
   }
 
   public String toString() {
@@ -321,7 +346,7 @@ 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)