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;
35 private TypeExtension typeExtension;
37 public boolean equals(Object o) {
38 if (o instanceof TypeDescriptor) {
39 TypeDescriptor t=(TypeDescriptor)o;
42 if ((type==CLASS)&&(!t.getSymbol().equals(getSymbol())))
44 if (t.arraycount!=arraycount)
46 if (t.isClassNameRef != this.isClassNameRef)
53 public boolean isString() {
58 if (!getSymbol().equals(TypeUtil.StringClass))
63 public boolean isClassNameRef() {
64 return this.isClassNameRef;
67 public void setClassNameRef() {
68 this.isClassNameRef = true;
71 public int hashCode() {
72 int hashcode=type^arraycount;
74 hashcode^=getSymbol().hashCode();
78 public boolean iswrapper() {
79 if (arraycount!=0||!isClass())
81 return (name.equals("bytewrapper")||
82 name.equals("booleanwrapper")||
83 name.equals("shortwrapper")||
84 name.equals("intwrapper")||
85 name.equals("longwrapper")||
86 name.equals("charwrapper")||
87 name.equals("floatwrapper")||
88 name.equals("doublewrapper")||
89 name.equals("Objectwrapper"));
92 public TypeDescriptor makeArray(State state) {
93 TypeDescriptor td=new TypeDescriptor(getSymbol());
94 td.arraycount=arraycount+1;
96 td.class_desc=class_desc;
97 state.addArrayType(td);
101 public boolean isArray() {
102 return (arraycount>0);
105 public int getArrayCount() {
109 /* Only use this method if you really know what you are doing. It
110 * doesn't have the effect you might expect. */
112 public void setArrayCount(int a) {
116 public TypeDescriptor dereference() {
117 TypeDescriptor td=new TypeDescriptor(getSymbol());
120 td.arraycount=arraycount-1;
122 td.class_desc=class_desc;
126 public String getSafeSymbol() {
128 return IR.Flat.BuildCode.arraytype;
129 else if (isClass()) {
130 return class_desc.getSafeSymbol();
141 else if (isBoolean()) //Booleans are ints in C
156 throw new Error("Error Type: "+type);
159 public String getRepairSymbol() {
161 return IR.Flat.BuildCode.arraytype;
162 else if (isClass()) {
163 return class_desc.getSymbol();
174 else if (isBoolean()) //Booleans are ints in C
184 else throw new Error("Error Type: "+type);
187 public String getSafeDescriptor() {
188 //Can't safely use [ in C
190 return "_AR_"+this.dereference().getSafeDescriptor();
191 else if (isClass()||isEnum())
192 return class_desc.getSafeDescriptor();
199 else if (isBoolean())
211 else throw new Error(toString());
214 public boolean isNumber() {
215 return (isIntegerType()||isFloat()||isDouble());
218 public boolean isByte() {
221 public boolean isNull() {
224 public boolean isShort() {
227 public boolean isInt() {
230 public boolean isLong() {
233 public boolean isChar() {
236 public boolean isBoolean() {
237 return type==BOOLEAN;
239 public boolean isFloat() {
242 public boolean isDouble() {
245 public boolean isVoid() {
249 public boolean isOffset() {
253 public boolean isPtr() {
254 return (isClass()||isNull()||isTag()||isArray());
257 public boolean isIntegerType() {
258 return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
261 public void setClassDescriptor(ClassDescriptor cd) {
265 public boolean isPrimitive() {
266 return (((type>=BYTE)&&(type<=DOUBLE)) || isEnum());
269 public boolean isEnum() {
270 if(this.type != CLASS) {
272 } else if(this.class_desc != null) {
273 return this.class_desc.isEnum();
278 public boolean isClass() {
279 return (type==CLASS && !isEnum());
282 public boolean isTag() {
286 public boolean isImmutable() {
287 return isPrimitive();
290 public TypeDescriptor(NameDescriptor name) {
291 super(name.toString());
293 this.class_desc=null;
295 this.isClassNameRef =false;
296 this.annotationSet=new Vector<AnnotationDescriptor>();
299 public TypeDescriptor(String st) {
302 this.class_desc=null;
304 this.isClassNameRef =false;
305 this.annotationSet=new Vector<AnnotationDescriptor>();
308 public ClassDescriptor getClassDesc() {
312 public TypeDescriptor(ClassDescriptor cd) {
313 super(cd.getSymbol());
317 this.isClassNameRef =false;
318 this.annotationSet=new Vector<AnnotationDescriptor>();
321 public TypeDescriptor(int t) {
325 this.isClassNameRef =false;
326 this.annotationSet=new Vector<AnnotationDescriptor>();
329 public String toString() {
333 return decodeInt(type);
336 public String toPrettyString() {
341 for(int i=0; i<arraycount; i++)
346 private static String decodeInt(int type) {
349 else if (type==BOOLEAN)
351 else if (type==SHORT)
359 else if (type==FLOAT)
361 else if (type==DOUBLE)
368 return TypeUtil.TagClass;
369 else if (type==OFFSET)
371 else throw new Error();
374 public void addAnnotationMarker(AnnotationDescriptor an) {
375 annotationSet.add(an);
378 public Vector<AnnotationDescriptor> getAnnotationMarkers() {
379 return annotationSet;
382 public void setExtension(TypeExtension te) {
386 public TypeExtension getExtension() {
387 return typeExtension;