Fixed lots of bugs with increment operations and +=/etc...
[IRC.git] / Robust / src / IR / TypeDescriptor.java
index 27f57ebcdc6e23eea45bdeb68aafea53d702511b..78270a0b2af4be737a1b405f6495a3ae2e80c33e 100644 (file)
@@ -20,13 +20,116 @@ public class TypeDescriptor extends Descriptor {
     public static final int CLASS=11;
 
 
-
+    int arraycount;
     int type;
     ClassDescriptor class_desc;
 
+    public boolean equals(Object o) {
+       if (o instanceof TypeDescriptor) {
+           TypeDescriptor t=(TypeDescriptor)o;
+           if (t.type!=type)
+               return false;
+           if ((type==CLASS)&&(t.class_desc!=class_desc))
+               return false;
+           if (t.arraycount!=arraycount)
+               return false;
+           return true;
+       }
+       return false;
+    }
+
+    public int hashCode() {
+       int hashcode=type^arraycount;
+       if (type==CLASS)
+           hashcode^=class_desc.hashCode();
+       return hashcode;
+    }
+
+    public TypeDescriptor makeArray(State state) {
+       TypeDescriptor td=new TypeDescriptor(getSymbol());
+       td.arraycount=arraycount+1;
+       td.type=type;
+       td.class_desc=class_desc;
+       state.addArrayType(td);
+       return td;
+    }
+
+    public boolean isArray() {
+       return (arraycount>0);
+    }
+
+    public int getArrayCount() {
+       return arraycount;
+    }
+
+    public TypeDescriptor dereference() {
+       TypeDescriptor td=new TypeDescriptor(getSymbol());
+       if (arraycount==0)
+           throw new Error();
+       td.arraycount=arraycount-1;
+       td.type=type;
+       td.class_desc=class_desc;
+       return td;
+    }
+
+    public String getSafeSymbol() {
+       if (isArray()) 
+           return IR.Flat.BuildCode.arraytype;
+       else if (isClass())
+           return class_desc.getSafeSymbol();
+       else if (isByte())
+           return "char";
+       else if (isChar())
+           return "short";
+       else if (isShort())
+           return "short";
+       else if (isInt())
+           return "int";
+       else if (isBoolean()) //Booleans are ints in C
+           return "int";
+       else if (isLong())
+           return "long long";
+       else if (isVoid())
+           return "void";
+       else if (isDouble())
+           return "double";
+       else if (isFloat())
+           return "float";
+       else throw new Error("Error Type: "+type);
+    }
+
+    public String getSafeDescriptor() {
+       if (isClass())
+           return class_desc.getSafeDescriptor();
+       else if (isByte())
+           return "C";
+       else if (isChar())
+           return "C";
+       else if (isShort())
+           return "S";
+       else if (isBoolean())
+           return "Z";
+       else if (isInt())
+           return "I";
+       else if (isLong())
+           return "J";
+       else if (isDouble())
+           return "D";
+       else if (isFloat())
+           return "F";
+       else throw new Error(); 
+    }
+
+    public boolean isNumber() {
+       return (isIntegerType()||isFloat()||isDouble());
+    }
+
     public boolean isByte() {
        return type==BYTE;
     }
+    public boolean isNull() {
+       return type==NULL;
+    }
     public boolean isShort() {
        return type==SHORT;
     }
@@ -48,16 +151,22 @@ public class TypeDescriptor extends Descriptor {
     public boolean isDouble() {
        return type==DOUBLE;
     }
+    public boolean isVoid() {
+       return type==VOID;
+    }
 
+    public boolean isPtr() {
+       return (isClass()||isNull());
+    }
+
+    public boolean isIntegerType() {
+       return (isInt()||isLong()||isShort()||isChar()||isByte());
+    }
 
     public void setClassDescriptor(ClassDescriptor cd) {
        class_desc=cd;
     }
   
-    public boolean isVoid() {
-       return type==VOID;
-    }
-
     public boolean isPrimitive() {
        return ((type>=BYTE)&&(type<=DOUBLE));
     }
@@ -70,6 +179,11 @@ public class TypeDescriptor extends Descriptor {
        super(name.toString());
        this.type=CLASS;
        this.class_desc=null;
+       this.arraycount=0;
+    }
+
+    private TypeDescriptor(String st) {
+       super(st);
     }
 
     public ClassDescriptor getClassDesc() {
@@ -80,11 +194,13 @@ public class TypeDescriptor extends Descriptor {
        super(cd.getSymbol());
        this.type=CLASS;
        this.class_desc=cd;
+       this.arraycount=0;
     }
 
     public TypeDescriptor(int t) {
        super(decodeInt(t));
        this.type=t;
+       this.arraycount=0;
     }
 
     public String toString() {