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, boolean addflag) {
86 TypeDescriptor td=new TypeDescriptor(getSymbol());
87 td.arraycount=arraycount+1;
89 td.class_desc=class_desc;
91 state.addArrayType(td);
96 public boolean isArray() {
97 return (arraycount>0);
100 public int getArrayCount() {
104 /* Only use this method if you really know what you are doing. It
105 * doesn't have the effect you might expect. */
107 public void setArrayCount(int a) {
111 public TypeDescriptor dereference() {
112 TypeDescriptor td=new TypeDescriptor(getSymbol());
115 td.arraycount=arraycount-1;
117 td.class_desc=class_desc;
121 public String getSafeSymbol() {
123 return IR.Flat.BuildCode.arraytype;
124 else if (isClass()) {
125 return class_desc.getSafeSymbol();
134 else if (isBoolean()) //Booleans are ints in C
146 else throw new Error("Error Type: "+type);
149 public String getRepairSymbol() {
151 return IR.Flat.BuildCode.arraytype;
152 else if (isClass()) {
153 return class_desc.getSymbol();
162 else if (isBoolean()) //Booleans are ints in C
172 else throw new Error("Error Type: "+type);
175 public String getSafeDescriptor() {
176 //Can't safely use [ in C
178 return "_AR_"+this.dereference().getSafeDescriptor();
180 return class_desc.getSafeDescriptor();
187 else if (isBoolean())
199 else throw new Error();
202 public boolean isNumber() {
203 return (isIntegerType()||isFloat()||isDouble());
206 public boolean isByte() {
209 public boolean isNull() {
212 public boolean isShort() {
215 public boolean isInt() {
218 public boolean isLong() {
221 public boolean isChar() {
224 public boolean isBoolean() {
225 return type==BOOLEAN;
227 public boolean isFloat() {
230 public boolean isDouble() {
233 public boolean isVoid() {
237 public boolean isOffset() {
241 public boolean isPtr() {
242 return ((isClass()&&!isEnum())||isNull()||isTag()||isArray());
245 public boolean isIntegerType() {
246 return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
249 public void setClassDescriptor(ClassDescriptor cd) {
253 public boolean isPrimitive() {
254 return ((type>=BYTE)&&(type<=DOUBLE));
257 public boolean isEnum() {
258 if(this.type != CLASS) {
260 } else if(this.class_desc != null){
261 return this.class_desc.isEnum();
266 public boolean isClass() {
270 public boolean isTag() {
274 public boolean isImmutable() {
275 return isPrimitive() || isString();
278 public TypeDescriptor(NameDescriptor name) {
279 super(name.toString());
281 this.class_desc=null;
283 this.isClassNameRef =false;
286 public TypeDescriptor(String st) {
289 this.class_desc=null;
291 this.isClassNameRef =false;
294 public ClassDescriptor getClassDesc() {
298 public TypeDescriptor(ClassDescriptor cd) {
299 super(cd.getSymbol());
303 this.isClassNameRef =false;
306 public TypeDescriptor(int t) {
310 this.isClassNameRef =false;
313 public String toString() {
317 return decodeInt(type);
320 public String toPrettyString() {
325 for(int i=0; i<arraycount; i++)
330 private static String decodeInt(int type) {
333 else if (type==BOOLEAN)
335 else if (type==SHORT)
343 else if (type==FLOAT)
345 else if (type==DOUBLE)
352 return TypeUtil.TagClass;
353 else if (type==OFFSET)
355 else throw new Error();