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
154 throw new Error("Error Type: "+type);
157 public String getRepairSymbol() {
159 return IR.Flat.BuildCode.arraytype;
160 else if (isClass()) {
161 return class_desc.getSymbol();
172 else if (isBoolean()) //Booleans are ints in C
182 else throw new Error("Error Type: "+type);
185 public String getSafeDescriptor() {
186 //Can't safely use [ in C
188 return "_AR_"+this.dereference().getSafeDescriptor();
189 else if (isClass()||isEnum())
190 return class_desc.getSafeDescriptor();
197 else if (isBoolean())
209 else throw new Error(toString());
212 public boolean isNumber() {
213 return (isIntegerType()||isFloat()||isDouble());
216 public boolean isByte() {
219 public boolean isNull() {
222 public boolean isShort() {
225 public boolean isInt() {
228 public boolean isLong() {
231 public boolean isChar() {
234 public boolean isBoolean() {
235 return type==BOOLEAN;
237 public boolean isFloat() {
240 public boolean isDouble() {
243 public boolean isVoid() {
247 public boolean isOffset() {
251 public boolean isPtr() {
252 return (isClass()||isNull()||isTag()||isArray());
255 public boolean isIntegerType() {
256 return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
259 public void setClassDescriptor(ClassDescriptor cd) {
263 public boolean isPrimitive() {
264 return (((type>=BYTE)&&(type<=DOUBLE)) || isEnum());
267 public boolean isEnum() {
268 if(this.type != CLASS) {
270 } else if(this.class_desc != null){
271 return this.class_desc.isEnum();
276 public boolean isClass() {
277 return (type==CLASS && !isEnum());
280 public boolean isTag() {
284 public boolean isImmutable() {
285 return isPrimitive() || isString();
288 public TypeDescriptor(NameDescriptor name) {
289 super(name.toString());
291 this.class_desc=null;
293 this.isClassNameRef =false;
294 this.annotationSet=new Vector<AnnotationDescriptor>();
297 public TypeDescriptor(String st) {
300 this.class_desc=null;
302 this.isClassNameRef =false;
303 this.annotationSet=new Vector<AnnotationDescriptor>();
306 public ClassDescriptor getClassDesc() {
310 public TypeDescriptor(ClassDescriptor cd) {
311 super(cd.getSymbol());
315 this.isClassNameRef =false;
316 this.annotationSet=new Vector<AnnotationDescriptor>();
319 public TypeDescriptor(int t) {
323 this.isClassNameRef =false;
324 this.annotationSet=new Vector<AnnotationDescriptor>();
327 public String toString() {
331 return decodeInt(type);
334 public String toPrettyString() {
339 for(int i=0; i<arraycount; i++)
344 private static String decodeInt(int type) {
347 else if (type==BOOLEAN)
349 else if (type==SHORT)
357 else if (type==FLOAT)
359 else if (type==DOUBLE)
366 return TypeUtil.TagClass;
367 else if (type==OFFSET)
369 else throw new Error();
372 public void addAnnotationMarker(AnnotationDescriptor an){
373 annotationSet.add(an);
376 public Vector<AnnotationDescriptor> getAnnotationMarkers(){
377 return annotationSet;
380 public void setExtension(TypeExtension te){
384 public TypeExtension getExtension(){
385 return typeExtension;