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.getSymbol().equals(getSymbol())))
35 if (t.arraycount!=arraycount)
42 public boolean isString() {
47 if (!getSymbol().equals(TypeUtil.StringClass))
52 public int hashCode() {
53 int hashcode=type^arraycount;
55 hashcode^=getSymbol().hashCode();
59 public TypeDescriptor makeArray(State state) {
60 TypeDescriptor td=new TypeDescriptor(getSymbol());
61 td.arraycount=arraycount+1;
63 td.class_desc=class_desc;
64 state.addArrayType(td);
68 public boolean isArray() {
69 return (arraycount>0);
72 public int getArrayCount() {
76 public TypeDescriptor dereference() {
77 TypeDescriptor td=new TypeDescriptor(getSymbol());
80 td.arraycount=arraycount-1;
82 td.class_desc=class_desc;
86 public String getSafeSymbol() {
88 return IR.Flat.BuildCode.arraytype;
90 return class_desc.getSafeSymbol();
99 else if (isBoolean()) //Booleans are ints in C
109 else throw new Error("Error Type: "+type);
112 public String getRepairSymbol() {
114 return IR.Flat.BuildCode.arraytype;
116 return class_desc.getSymbol();
125 else if (isBoolean()) //Booleans are ints in C
135 else throw new Error("Error Type: "+type);
138 public String getSafeDescriptor() {
139 //Can't safely use [ in C
141 return "_AR_"+this.dereference().getSafeDescriptor();
143 return class_desc.getSafeDescriptor();
150 else if (isBoolean())
162 else throw new Error();
165 public boolean isNumber() {
166 return (isIntegerType()||isFloat()||isDouble());
169 public boolean isByte() {
172 public boolean isNull() {
175 public boolean isShort() {
178 public boolean isInt() {
181 public boolean isLong() {
184 public boolean isChar() {
187 public boolean isBoolean() {
188 return type==BOOLEAN;
190 public boolean isFloat() {
193 public boolean isDouble() {
196 public boolean isVoid() {
200 public boolean isPtr() {
201 return (isClass()||isNull()||isTag()||isArray());
204 public boolean isIntegerType() {
205 return (isInt()||isLong()||isShort()||isChar()||isByte());
208 public void setClassDescriptor(ClassDescriptor cd) {
212 public boolean isPrimitive() {
213 return ((type>=BYTE)&&(type<=DOUBLE));
216 public boolean isClass() {
220 public boolean isTag() {
224 public TypeDescriptor(NameDescriptor name) {
225 super(name.toString());
227 this.class_desc=null;
231 public TypeDescriptor(String st) {
234 this.class_desc=null;
238 public ClassDescriptor getClassDesc() {
242 public TypeDescriptor(ClassDescriptor cd) {
243 super(cd.getSymbol());
249 public TypeDescriptor(int t) {
255 public String toString() {
259 return decodeInt(type);
262 public String toPrettyString() {
265 for(int i=0; i<arraycount; i++)
269 return decodeInt(type);
272 private static String decodeInt(int type) {
275 else if (type==BOOLEAN)
277 else if (type==SHORT)
285 else if (type==FLOAT)
287 else if (type==DOUBLE)
294 return TypeUtil.TagClass;
295 else throw new Error();