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;
28 boolean isStatic = false;
30 public boolean equals(Object o) {
31 if (o instanceof TypeDescriptor) {
32 TypeDescriptor t=(TypeDescriptor)o;
35 if ((type==CLASS)&&(!t.getSymbol().equals(getSymbol())))
37 if (isStatic != t.isStatic)
39 if (t.arraycount!=arraycount)
46 public boolean isString() {
51 if (!getSymbol().equals(TypeUtil.StringClass))
56 public boolean isStatic() {
60 public void setStatic() {
64 public int hashCode() {
65 int hashcode=type^arraycount;
67 hashcode^=getSymbol().hashCode();
71 public boolean iswrapper() {
72 if (arraycount!=0||!isClass())
74 return (name.equals("bytewrapper")||
75 name.equals("booleanwrapper")||
76 name.equals("shortwrapper")||
77 name.equals("intwrapper")||
78 name.equals("longwrapper")||
79 name.equals("charwrapper")||
80 name.equals("floatwrapper")||
81 name.equals("doublewrapper")||
82 name.equals("Objectwrapper"));
85 public TypeDescriptor makeArray(State state) {
86 TypeDescriptor td=new TypeDescriptor(getSymbol());
87 td.arraycount=arraycount+1;
89 td.class_desc=class_desc;
90 state.addArrayType(td);
94 public boolean isArray() {
95 return (arraycount>0);
98 public int getArrayCount() {
102 /* Only use this method if you really know what you are doing. It
103 * doesn't have the effect you might expect. */
105 public void setArrayCount(int a) {
109 public TypeDescriptor dereference() {
110 TypeDescriptor td=new TypeDescriptor(getSymbol());
113 td.arraycount=arraycount-1;
115 td.class_desc=class_desc;
119 public String getSafeSymbol() {
121 return IR.Flat.BuildCode.arraytype;
123 return class_desc.getSafeSymbol();
132 else if (isBoolean()) //Booleans are ints in C
144 else throw new Error("Error Type: "+type);
147 public String getRepairSymbol() {
149 return IR.Flat.BuildCode.arraytype;
151 return class_desc.getSymbol();
160 else if (isBoolean()) //Booleans are ints in C
170 else throw new Error("Error Type: "+type);
173 public String getSafeDescriptor() {
174 //Can't safely use [ in C
176 return "_AR_"+this.dereference().getSafeDescriptor();
178 return class_desc.getSafeDescriptor();
185 else if (isBoolean())
197 else throw new Error();
200 public boolean isNumber() {
201 return (isIntegerType()||isFloat()||isDouble());
204 public boolean isByte() {
207 public boolean isNull() {
210 public boolean isShort() {
213 public boolean isInt() {
216 public boolean isLong() {
219 public boolean isChar() {
222 public boolean isBoolean() {
223 return type==BOOLEAN;
225 public boolean isFloat() {
228 public boolean isDouble() {
231 public boolean isVoid() {
235 public boolean isOffset() {
239 public boolean isPtr() {
240 return (isClass()||isNull()||isTag()||isArray());
243 public boolean isIntegerType() {
244 return (isInt()||isLong()||isShort()||isChar()||isByte());
247 public void setClassDescriptor(ClassDescriptor cd) {
251 public boolean isPrimitive() {
252 return ((type>=BYTE)&&(type<=DOUBLE));
255 public boolean isClass() {
259 public boolean isTag() {
263 public boolean isImmutable() {
264 return isPrimitive() || isString();
267 public TypeDescriptor(NameDescriptor name) {
268 super(name.toString());
270 this.class_desc=null;
272 this.isStatic =false;
275 public TypeDescriptor(String st) {
278 this.class_desc=null;
280 this.isStatic =false;
283 public ClassDescriptor getClassDesc() {
287 public TypeDescriptor(ClassDescriptor cd) {
288 super(cd.getSymbol());
292 this.isStatic =false;
295 public TypeDescriptor(int t) {
299 this.isStatic =false;
302 public String toString() {
306 return decodeInt(type);
309 public String toPrettyString() {
314 for(int i=0; i<arraycount; i++)
319 private static String decodeInt(int type) {
322 else if (type==BOOLEAN)
324 else if (type==SHORT)
332 else if (type==FLOAT)
334 else if (type==DOUBLE)
341 return TypeUtil.TagClass;
342 else if (type==OFFSET)
344 else throw new Error();