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;
26 ClassDescriptor class_desc;
28 public boolean equals(Object o) {
29 if (o instanceof TypeDescriptor) {
30 TypeDescriptor t=(TypeDescriptor)o;
33 if ((type==CLASS)&&(t.class_desc!=class_desc))
35 if (t.arraycount!=arraycount)
42 public int hashCode() {
43 int hashcode=type^arraycount;
45 hashcode^=getSymbol().hashCode();
49 public TypeDescriptor makeArray(State state) {
50 TypeDescriptor td=new TypeDescriptor(getSymbol());
51 td.arraycount=arraycount+1;
53 td.class_desc=class_desc;
54 state.addArrayType(td);
58 public boolean isArray() {
59 return (arraycount>0);
62 public int getArrayCount() {
66 public TypeDescriptor dereference() {
67 TypeDescriptor td=new TypeDescriptor(getSymbol());
70 td.arraycount=arraycount-1;
72 td.class_desc=class_desc;
76 public String getSafeSymbol() {
78 return IR.Flat.BuildCode.arraytype;
80 return class_desc.getSafeSymbol();
89 else if (isBoolean()) //Booleans are ints in C
99 else throw new Error("Error Type: "+type);
102 public String getRepairSymbol() {
104 return IR.Flat.BuildCode.arraytype;
106 return class_desc.getSymbol();
115 else if (isBoolean()) //Booleans are ints in C
125 else throw new Error("Error Type: "+type);
128 public String getSafeDescriptor() {
129 //Can't safely use [ in C
131 return "_AR_"+this.dereference().getSafeDescriptor();
133 return class_desc.getSafeDescriptor();
140 else if (isBoolean())
152 else throw new Error();
155 public boolean isNumber() {
156 return (isIntegerType()||isFloat()||isDouble());
159 public boolean isByte() {
162 public boolean isNull() {
165 public boolean isShort() {
168 public boolean isInt() {
171 public boolean isLong() {
174 public boolean isChar() {
177 public boolean isBoolean() {
178 return type==BOOLEAN;
180 public boolean isFloat() {
183 public boolean isDouble() {
186 public boolean isVoid() {
190 public boolean isPtr() {
191 return (isClass()||isNull()||isTag());
194 public boolean isIntegerType() {
195 return (isInt()||isLong()||isShort()||isChar()||isByte());
198 public void setClassDescriptor(ClassDescriptor cd) {
202 public boolean isPrimitive() {
203 return ((type>=BYTE)&&(type<=DOUBLE));
206 public boolean isClass() {
210 public boolean isTag() {
214 public TypeDescriptor(NameDescriptor name) {
215 super(name.toString());
217 this.class_desc=null;
221 public TypeDescriptor(String st) {
224 this.class_desc=null;
228 public ClassDescriptor getClassDesc() {
232 public TypeDescriptor(ClassDescriptor cd) {
233 super(cd.getSymbol());
239 public TypeDescriptor(int t) {
245 public String toString() {
249 return decodeInt(type);
252 private static String decodeInt(int type) {
255 else if (type==BOOLEAN)
257 else if (type==SHORT)
265 else if (type==FLOAT)
267 else if (type==DOUBLE)
274 return TypeUtil.TagClass;
275 else throw new Error();