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 TAG=11;
21 public static final int CLASS=12;
22 public static final int OFFSET=13;
27 ClassDescriptor class_desc;
29 public boolean equals(Object o) {
30 if (o instanceof TypeDescriptor) {
31 TypeDescriptor t=(TypeDescriptor)o;
34 if ((type==CLASS)&&(!t.getSymbol().equals(getSymbol())))
36 if (t.arraycount!=arraycount)
43 public boolean isString() {
48 if (!getSymbol().equals(TypeUtil.StringClass))
53 public int hashCode() {
54 int hashcode=type^arraycount;
56 hashcode^=getSymbol().hashCode();
60 public TypeDescriptor makeArray(State state) {
61 TypeDescriptor td=new TypeDescriptor(getSymbol());
62 td.arraycount=arraycount+1;
64 td.class_desc=class_desc;
65 state.addArrayType(td);
69 public boolean isArray() {
70 return (arraycount>0);
73 public int getArrayCount() {
77 public TypeDescriptor dereference() {
78 TypeDescriptor td=new TypeDescriptor(getSymbol());
81 td.arraycount=arraycount-1;
83 td.class_desc=class_desc;
87 public String getSafeSymbol() {
89 return IR.Flat.BuildCode.arraytype;
91 return class_desc.getSafeSymbol();
100 else if (isBoolean()) //Booleans are ints in C
112 else throw new Error("Error Type: "+type);
115 public String getRepairSymbol() {
117 return IR.Flat.BuildCode.arraytype;
119 return class_desc.getSymbol();
128 else if (isBoolean()) //Booleans are ints in C
138 else throw new Error("Error Type: "+type);
141 public String getSafeDescriptor() {
142 //Can't safely use [ in C
144 return "_AR_"+this.dereference().getSafeDescriptor();
146 return class_desc.getSafeDescriptor();
153 else if (isBoolean())
165 else throw new Error();
168 public boolean isNumber() {
169 return (isIntegerType()||isFloat()||isDouble());
172 public boolean isByte() {
175 public boolean isNull() {
178 public boolean isShort() {
181 public boolean isInt() {
184 public boolean isLong() {
187 public boolean isChar() {
190 public boolean isBoolean() {
191 return type==BOOLEAN;
193 public boolean isFloat() {
196 public boolean isDouble() {
199 public boolean isVoid() {
203 public boolean isOffset() {
207 public boolean isPtr() {
208 return (isClass()||isNull()||isTag()||isArray());
211 public boolean isIntegerType() {
212 return (isInt()||isLong()||isShort()||isChar()||isByte());
215 public void setClassDescriptor(ClassDescriptor cd) {
219 public boolean isPrimitive() {
220 return ((type>=BYTE)&&(type<=DOUBLE));
223 public boolean isClass() {
227 public boolean isTag() {
231 public boolean isImmutable() {
232 return isPrimitive() || isString();
235 public TypeDescriptor(NameDescriptor name) {
236 super(name.toString());
238 this.class_desc=null;
242 public TypeDescriptor(String st) {
245 this.class_desc=null;
249 public ClassDescriptor getClassDesc() {
253 public TypeDescriptor(ClassDescriptor cd) {
254 super(cd.getSymbol());
260 public TypeDescriptor(int t) {
266 public String toString() {
270 return decodeInt(type);
273 public String toPrettyString() {
276 for(int i=0; i<arraycount; i++)
280 return decodeInt(type);
283 private static String decodeInt(int type) {
286 else if (type==BOOLEAN)
288 else if (type==SHORT)
296 else if (type==FLOAT)
298 else if (type==DOUBLE)
305 return TypeUtil.TagClass;
306 else if (type==OFFSET)
308 else throw new Error();