3 import java.util.HashSet;
5 import java.util.Vector;
10 * represents a symbol in the language (var name, function name, etc).
13 public class TypeDescriptor extends Descriptor {
14 public static final int BYTE=1;
15 public static final int SHORT=2;
16 public static final int INT=3;
17 public static final int LONG=4;
18 public static final int CHAR=5;
19 public static final int BOOLEAN=6;
20 public static final int FLOAT=7;
21 public static final int DOUBLE=8;
22 public static final int VOID=9;
23 public static final int NULL=10;
24 public static final int TAG=11;
25 public static final int CLASS=12;
26 public static final int OFFSET=13;
31 ClassDescriptor class_desc;
32 boolean isClassNameRef = false;
34 private Vector<AnnotationDescriptor> annotationSet;
36 public boolean equals(Object o) {
37 if (o instanceof TypeDescriptor) {
38 TypeDescriptor t=(TypeDescriptor)o;
41 if ((type==CLASS)&&(!t.getSymbol().equals(getSymbol())))
43 if (t.arraycount!=arraycount)
45 if (t.isClassNameRef != this.isClassNameRef)
52 public boolean isString() {
57 if (!getSymbol().equals(TypeUtil.StringClass))
62 public boolean isClassNameRef() {
63 return this.isClassNameRef;
66 public void setClassNameRef() {
67 this.isClassNameRef = true;
70 public int hashCode() {
71 int hashcode=type^arraycount;
73 hashcode^=getSymbol().hashCode();
77 public boolean iswrapper() {
78 if (arraycount!=0||!isClass())
80 return (name.equals("bytewrapper")||
81 name.equals("booleanwrapper")||
82 name.equals("shortwrapper")||
83 name.equals("intwrapper")||
84 name.equals("longwrapper")||
85 name.equals("charwrapper")||
86 name.equals("floatwrapper")||
87 name.equals("doublewrapper")||
88 name.equals("Objectwrapper"));
91 public TypeDescriptor makeArray(State state) {
92 TypeDescriptor td=new TypeDescriptor(getSymbol());
93 td.arraycount=arraycount+1;
95 td.class_desc=class_desc;
96 state.addArrayType(td);
100 public boolean isArray() {
101 return (arraycount>0);
104 public int getArrayCount() {
108 /* Only use this method if you really know what you are doing. It
109 * doesn't have the effect you might expect. */
111 public void setArrayCount(int a) {
115 public TypeDescriptor dereference() {
116 TypeDescriptor td=new TypeDescriptor(getSymbol());
119 td.arraycount=arraycount-1;
121 td.class_desc=class_desc;
125 public String getSafeSymbol() {
127 return IR.Flat.BuildCode.arraytype;
128 else if (isClass()) {
129 return class_desc.getSafeSymbol();
138 else if (isBoolean()) //Booleans are ints in C
151 throw new Error("Error Type: "+type);
154 public String getRepairSymbol() {
156 return IR.Flat.BuildCode.arraytype;
157 else if (isClass()) {
158 return class_desc.getSymbol();
167 else if (isBoolean()) //Booleans are ints in C
177 else throw new Error("Error Type: "+type);
180 public String getSafeDescriptor() {
181 //Can't safely use [ in C
183 return "_AR_"+this.dereference().getSafeDescriptor();
185 return class_desc.getSafeDescriptor();
192 else if (isBoolean())
204 else throw new Error();
207 public boolean isNumber() {
208 return (isIntegerType()||isFloat()||isDouble());
211 public boolean isByte() {
214 public boolean isNull() {
217 public boolean isShort() {
220 public boolean isInt() {
223 public boolean isLong() {
226 public boolean isChar() {
229 public boolean isBoolean() {
230 return type==BOOLEAN;
232 public boolean isFloat() {
235 public boolean isDouble() {
238 public boolean isVoid() {
242 public boolean isOffset() {
246 public boolean isPtr() {
247 return ((isClass()&&!isEnum())||isNull()||isTag()||isArray());
250 public boolean isIntegerType() {
251 return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
254 public void setClassDescriptor(ClassDescriptor cd) {
258 public boolean isPrimitive() {
259 return ((type>=BYTE)&&(type<=DOUBLE));
262 public boolean isEnum() {
263 if(this.type != CLASS) {
265 } else if(this.class_desc != null){
266 return this.class_desc.isEnum();
271 public boolean isClass() {
275 public boolean isTag() {
279 public boolean isImmutable() {
280 return isPrimitive() || isString();
283 public TypeDescriptor(NameDescriptor name) {
284 super(name.toString());
286 this.class_desc=null;
288 this.isClassNameRef =false;
289 this.annotationSet=new Vector<AnnotationDescriptor>();
292 public TypeDescriptor(String st) {
295 this.class_desc=null;
297 this.isClassNameRef =false;
298 this.annotationSet=new Vector<AnnotationDescriptor>();
301 public ClassDescriptor getClassDesc() {
305 public TypeDescriptor(ClassDescriptor cd) {
306 super(cd.getSymbol());
310 this.isClassNameRef =false;
311 this.annotationSet=new Vector<AnnotationDescriptor>();
314 public TypeDescriptor(int t) {
318 this.isClassNameRef =false;
319 this.annotationSet=new Vector<AnnotationDescriptor>();
322 public String toString() {
326 return decodeInt(type);
329 public String toPrettyString() {
334 for(int i=0; i<arraycount; i++)
339 private static String decodeInt(int type) {
342 else if (type==BOOLEAN)
344 else if (type==SHORT)
352 else if (type==FLOAT)
354 else if (type==DOUBLE)
361 return TypeUtil.TagClass;
362 else if (type==OFFSET)
364 else throw new Error();
367 public void addAnnotationMarker(AnnotationDescriptor an){
368 annotationSet.add(an);
371 public Vector<AnnotationDescriptor> getAnnotationMarkers(){
372 return annotationSet;