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;
29 public boolean equals(Object o) {
30 if (o instanceof TypeDescriptor) {
31 TypeDescriptor t=(TypeDescriptor)o;
34 if ((type==CLASS)&&(!t.getSymbol().equals(getSymbol())))
36 if (t.arraycount!=arraycount)
43 public boolean isString() {
48 if (!getSymbol().equals(TypeUtil.StringClass))
53 public int hashCode() {
54 int hashcode=type^arraycount;
56 hashcode^=getSymbol().hashCode();
60 public boolean iswrapper() {
61 if (arraycount!=0||isClass())
63 return (name.equals("bytewrapper")||
64 name.equals("booleanwrapper")||
65 name.equals("shortwrapper")||
66 name.equals("intwrapper")||
67 name.equals("longwrapper")||
68 name.equals("charwrapper")||
69 name.equals("floatwrapper")||
70 name.equals("doublewrapper")||
71 name.equals("objectwrapper"));
74 public TypeDescriptor makeArray(State state) {
75 TypeDescriptor td=new TypeDescriptor(getSymbol());
76 td.arraycount=arraycount+1;
78 td.class_desc=class_desc;
79 state.addArrayType(td);
83 public boolean isArray() {
84 return (arraycount>0);
87 public int getArrayCount() {
91 /* Only use this method if you really know what you are doing. It
92 * doesn't have the effect you might expect. */
94 public void setArrayCount(int a) {
98 public TypeDescriptor dereference() {
99 TypeDescriptor td=new TypeDescriptor(getSymbol());
102 td.arraycount=arraycount-1;
104 td.class_desc=class_desc;
108 public String getSafeSymbol() {
110 return IR.Flat.BuildCode.arraytype;
112 return class_desc.getSafeSymbol();
121 else if (isBoolean()) //Booleans are ints in C
133 else throw new Error("Error Type: "+type);
136 public String getRepairSymbol() {
138 return IR.Flat.BuildCode.arraytype;
140 return class_desc.getSymbol();
149 else if (isBoolean()) //Booleans are ints in C
159 else throw new Error("Error Type: "+type);
162 public String getSafeDescriptor() {
163 //Can't safely use [ in C
165 return "_AR_"+this.dereference().getSafeDescriptor();
167 return class_desc.getSafeDescriptor();
174 else if (isBoolean())
186 else throw new Error();
189 public boolean isNumber() {
190 return (isIntegerType()||isFloat()||isDouble());
193 public boolean isByte() {
196 public boolean isNull() {
199 public boolean isShort() {
202 public boolean isInt() {
205 public boolean isLong() {
208 public boolean isChar() {
211 public boolean isBoolean() {
212 return type==BOOLEAN;
214 public boolean isFloat() {
217 public boolean isDouble() {
220 public boolean isVoid() {
224 public boolean isOffset() {
228 public boolean isPtr() {
229 return (isClass()||isNull()||isTag()||isArray());
232 public boolean isIntegerType() {
233 return (isInt()||isLong()||isShort()||isChar()||isByte());
236 public void setClassDescriptor(ClassDescriptor cd) {
240 public boolean isPrimitive() {
241 return ((type>=BYTE)&&(type<=DOUBLE));
244 public boolean isClass() {
248 public boolean isTag() {
252 public boolean isImmutable() {
253 return isPrimitive() || isString();
256 public TypeDescriptor(NameDescriptor name) {
257 super(name.toString());
259 this.class_desc=null;
263 public TypeDescriptor(String st) {
266 this.class_desc=null;
270 public ClassDescriptor getClassDesc() {
274 public TypeDescriptor(ClassDescriptor cd) {
275 super(cd.getSymbol());
281 public TypeDescriptor(int t) {
287 public String toString() {
291 return decodeInt(type);
294 public String toPrettyString() {
299 for(int i=0; i<arraycount; i++)
304 private static String decodeInt(int type) {
307 else if (type==BOOLEAN)
309 else if (type==SHORT)
317 else if (type==FLOAT)
319 else if (type==DOUBLE)
326 return TypeUtil.TagClass;
327 else if (type==OFFSET)
329 else throw new Error();