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();
140 else if (isBoolean()) //Booleans are ints in C
153 throw new Error("Error Type: "+type);
156 public String getRepairSymbol() {
158 return IR.Flat.BuildCode.arraytype;
159 else if (isClass()) {
160 return class_desc.getSymbol();
171 else if (isBoolean()) //Booleans are ints in C
181 else throw new Error("Error Type: "+type);
184 public String getSafeDescriptor() {
185 //Can't safely use [ in C
187 return "_AR_"+this.dereference().getSafeDescriptor();
188 else if (isClass()||isEnum())
189 return class_desc.getSafeDescriptor();
196 else if (isBoolean())
208 else throw new Error(toString());
211 public boolean isNumber() {
212 return (isIntegerType()||isFloat()||isDouble());
215 public boolean isByte() {
218 public boolean isNull() {
221 public boolean isShort() {
224 public boolean isInt() {
227 public boolean isLong() {
230 public boolean isChar() {
233 public boolean isBoolean() {
234 return type==BOOLEAN;
236 public boolean isFloat() {
239 public boolean isDouble() {
242 public boolean isVoid() {
246 public boolean isOffset() {
250 public boolean isPtr() {
251 return (isClass()||isNull()||isTag()||isArray());
254 public boolean isIntegerType() {
255 return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
258 public void setClassDescriptor(ClassDescriptor cd) {
262 public boolean isPrimitive() {
263 return (((type>=BYTE)&&(type<=DOUBLE)) || isEnum());
266 public boolean isEnum() {
267 if(this.type != CLASS) {
269 } else if(this.class_desc != null){
270 return this.class_desc.isEnum();
275 public boolean isClass() {
276 return (type==CLASS && !isEnum());
279 public boolean isTag() {
283 public boolean isImmutable() {
284 return isPrimitive() || isString();
287 public TypeDescriptor(NameDescriptor name) {
288 super(name.toString());
290 this.class_desc=null;
292 this.isClassNameRef =false;
293 this.annotationSet=new Vector<AnnotationDescriptor>();
296 public TypeDescriptor(String st) {
299 this.class_desc=null;
301 this.isClassNameRef =false;
302 this.annotationSet=new Vector<AnnotationDescriptor>();
305 public ClassDescriptor getClassDesc() {
309 public TypeDescriptor(ClassDescriptor cd) {
310 super(cd.getSymbol());
314 this.isClassNameRef =false;
315 this.annotationSet=new Vector<AnnotationDescriptor>();
318 public TypeDescriptor(int t) {
322 this.isClassNameRef =false;
323 this.annotationSet=new Vector<AnnotationDescriptor>();
326 public String toString() {
330 return decodeInt(type);
333 public String toPrettyString() {
338 for(int i=0; i<arraycount; i++)
343 private static String decodeInt(int type) {
346 else if (type==BOOLEAN)
348 else if (type==SHORT)
356 else if (type==FLOAT)
358 else if (type==DOUBLE)
365 return TypeUtil.TagClass;
366 else if (type==OFFSET)
368 else throw new Error();
371 public void addAnnotationMarker(AnnotationDescriptor an){
372 annotationSet.add(an);
375 public Vector<AnnotationDescriptor> getAnnotationMarkers(){
376 return annotationSet;