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^=class_desc.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 getSafeDescriptor() {
103 return class_desc.getSafeDescriptor();
110 else if (isBoolean())
120 else throw new Error();
123 public boolean isNumber() {
124 return (isIntegerType()||isFloat()||isDouble());
127 public boolean isByte() {
130 public boolean isNull() {
133 public boolean isShort() {
136 public boolean isInt() {
139 public boolean isLong() {
142 public boolean isChar() {
145 public boolean isBoolean() {
146 return type==BOOLEAN;
148 public boolean isFloat() {
151 public boolean isDouble() {
154 public boolean isVoid() {
158 public boolean isPtr() {
159 return (isClass()||isNull());
162 public boolean isIntegerType() {
163 return (isInt()||isLong()||isShort()||isChar()||isByte());
166 public void setClassDescriptor(ClassDescriptor cd) {
170 public boolean isPrimitive() {
171 return ((type>=BYTE)&&(type<=DOUBLE));
174 public boolean isClass() {
178 public TypeDescriptor(NameDescriptor name) {
179 super(name.toString());
181 this.class_desc=null;
185 private TypeDescriptor(String st) {
189 public ClassDescriptor getClassDesc() {
193 public TypeDescriptor(ClassDescriptor cd) {
194 super(cd.getSymbol());
200 public TypeDescriptor(int t) {
206 public String toString() {
210 return decodeInt(type);
213 private static String decodeInt(int type) {
216 else if (type==BOOLEAN)
218 else if (type==SHORT)
226 else if (type==FLOAT)
228 else if (type==DOUBLE)
234 else throw new Error();