6 * represents a symbol in the language (var name, function name, etc).
9 public class TypeDescriptor extends Descriptor {
10 public static final int BYTE=1;
11 public static final int SHORT=2;
12 public static final int INT=3;
13 public static final int LONG=4;
14 public static final int CHAR=5;
15 public static final int BOOLEAN=6;
16 public static final int FLOAT=7;
17 public static final int DOUBLE=8;
18 public static final int VOID=9;
19 public static final int NULL=10;
20 public static final int CLASS=11;
25 ClassDescriptor class_desc;
27 public boolean equals(Object o) {
28 if (o instanceof TypeDescriptor) {
29 TypeDescriptor t=(TypeDescriptor)o;
32 if ((type==CLASS)&&(t.class_desc!=class_desc))
34 if (t.arraycount!=arraycount)
41 public int hashCode() {
42 int hashcode=type^arraycount;
44 hashcode^=getSymbol().hashCode();
48 public TypeDescriptor makeArray(State state) {
49 TypeDescriptor td=new TypeDescriptor(getSymbol());
50 td.arraycount=arraycount+1;
52 td.class_desc=class_desc;
53 state.addArrayType(td);
57 public boolean isArray() {
58 return (arraycount>0);
61 public int getArrayCount() {
65 public TypeDescriptor dereference() {
66 TypeDescriptor td=new TypeDescriptor(getSymbol());
69 td.arraycount=arraycount-1;
71 td.class_desc=class_desc;
75 public String getSafeSymbol() {
77 return IR.Flat.BuildCode.arraytype;
79 return class_desc.getSafeSymbol();
88 else if (isBoolean()) //Booleans are ints in C
98 else throw new Error("Error Type: "+type);
101 public String getRepairSymbol() {
103 return IR.Flat.BuildCode.arraytype;
105 return class_desc.getSymbol();
114 else if (isBoolean()) //Booleans are ints in C
124 else throw new Error("Error Type: "+type);
127 public String getSafeDescriptor() {
128 //Can't safely use [ in C
130 return "_AR_"+this.dereference().getSafeDescriptor();
132 return class_desc.getSafeDescriptor();
139 else if (isBoolean())
149 else throw new Error();
152 public boolean isNumber() {
153 return (isIntegerType()||isFloat()||isDouble());
156 public boolean isByte() {
159 public boolean isNull() {
162 public boolean isShort() {
165 public boolean isInt() {
168 public boolean isLong() {
171 public boolean isChar() {
174 public boolean isBoolean() {
175 return type==BOOLEAN;
177 public boolean isFloat() {
180 public boolean isDouble() {
183 public boolean isVoid() {
187 public boolean isPtr() {
188 return (isClass()||isNull());
191 public boolean isIntegerType() {
192 return (isInt()||isLong()||isShort()||isChar()||isByte());
195 public void setClassDescriptor(ClassDescriptor cd) {
199 public boolean isPrimitive() {
200 return ((type>=BYTE)&&(type<=DOUBLE));
203 public boolean isClass() {
207 public TypeDescriptor(NameDescriptor name) {
208 super(name.toString());
210 this.class_desc=null;
214 private TypeDescriptor(String st) {
218 public ClassDescriptor getClassDesc() {
222 public TypeDescriptor(ClassDescriptor cd) {
223 super(cd.getSymbol());
229 public TypeDescriptor(int t) {
235 public String toString() {
239 return decodeInt(type);
242 private static String decodeInt(int type) {
245 else if (type==BOOLEAN)
247 else if (type==SHORT)
255 else if (type==FLOAT)
257 else if (type==DOUBLE)
263 else throw new Error();