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 isClassNameRef = 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 (t.arraycount!=arraycount)
39 if (t.isClassNameRef != this.isClassNameRef)
46 public boolean isString() {
51 if (!getSymbol().equals(TypeUtil.StringClass))
56 public boolean isClassNameRef() {
57 return this.isClassNameRef;
60 public void setClassNameRef() {
61 this.isClassNameRef = true;
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;
122 else if (isClass()) {
123 return class_desc.getSafeSymbol();
132 else if (isBoolean()) //Booleans are ints in C
145 throw new Error("Error Type: "+type);
148 public String getRepairSymbol() {
150 return IR.Flat.BuildCode.arraytype;
151 else if (isClass()) {
152 return class_desc.getSymbol();
161 else if (isBoolean()) //Booleans are ints in C
171 else throw new Error("Error Type: "+type);
174 public String getSafeDescriptor() {
175 //Can't safely use [ in C
177 return "_AR_"+this.dereference().getSafeDescriptor();
179 return class_desc.getSafeDescriptor();
186 else if (isBoolean())
198 else throw new Error();
201 public boolean isNumber() {
202 return (isIntegerType()||isFloat()||isDouble());
205 public boolean isByte() {
208 public boolean isNull() {
211 public boolean isShort() {
214 public boolean isInt() {
217 public boolean isLong() {
220 public boolean isChar() {
223 public boolean isBoolean() {
224 return type==BOOLEAN;
226 public boolean isFloat() {
229 public boolean isDouble() {
232 public boolean isVoid() {
236 public boolean isOffset() {
240 public boolean isPtr() {
241 return ((isClass()&&!isEnum())||isNull()||isTag()||isArray());
244 public boolean isIntegerType() {
245 return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
248 public void setClassDescriptor(ClassDescriptor cd) {
252 public boolean isPrimitive() {
253 return ((type>=BYTE)&&(type<=DOUBLE));
256 public boolean isEnum() {
257 if(this.type != CLASS) {
259 } else if(this.class_desc != null){
260 return this.class_desc.isEnum();
265 public boolean isClass() {
269 public boolean isTag() {
273 public boolean isImmutable() {
274 return isPrimitive() || isString();
277 public TypeDescriptor(NameDescriptor name) {
278 super(name.toString());
280 this.class_desc=null;
282 this.isClassNameRef =false;
285 public TypeDescriptor(String st) {
288 this.class_desc=null;
290 this.isClassNameRef =false;
293 public ClassDescriptor getClassDesc() {
297 public TypeDescriptor(ClassDescriptor cd) {
298 super(cd.getSymbol());
302 this.isClassNameRef =false;
305 public TypeDescriptor(int t) {
309 this.isClassNameRef =false;
312 public String toString() {
316 return decodeInt(type);
319 public String toPrettyString() {
324 for(int i=0; i<arraycount; i++)
329 private static String decodeInt(int type) {
332 else if (type==BOOLEAN)
334 else if (type==SHORT)
342 else if (type==FLOAT)
344 else if (type==DOUBLE)
351 return TypeUtil.TagClass;
352 else if (type==OFFSET)
354 else throw new Error();