changes to runtime/etc to build in repair checking code
[IRC.git] / Robust / src / IR / TypeDescriptor.java
index c1bbc74c8f2427885587aaa171011f849a045d0c..f1793389208b3c82674f8932091e655464579e0c 100644 (file)
@@ -20,12 +20,62 @@ 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^=getSymbol().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 (isClass())
+       if (isArray()) 
+           return IR.Flat.BuildCode.arraytype;
+       else if (isClass())
            return class_desc.getSafeSymbol();
        else if (isByte())
            return "char";
@@ -45,11 +95,40 @@ public class TypeDescriptor extends Descriptor {
            return "double";
        else if (isFloat())
            return "float";
-       else throw new Error();
+       else throw new Error("Error Type: "+type);
+    }
+
+    public String getRepairSymbol() {
+       if (isArray())
+           return IR.Flat.BuildCode.arraytype;
+       else if (isClass())
+           return class_desc.getSymbol();
+       else if (isByte())
+           return "byte";
+       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())
+       //Can't safely use [ in C
+       if (isArray()) 
+           return "_AR_"+this.dereference().getSafeDescriptor();
+       else if (isClass())
            return class_desc.getSafeDescriptor();
        else if (isByte())
            return "C";
@@ -129,6 +208,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() {
@@ -139,11 +223,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() {