3 import java.util.HashSet;
9 * represents a symbol in the language (var name, function name, etc).
12 public class TypeDescriptor extends Descriptor {
13 public static final int BYTE=1;
14 public static final int SHORT=2;
15 public static final int INT=3;
16 public static final int LONG=4;
17 public static final int CHAR=5;
18 public static final int BOOLEAN=6;
19 public static final int FLOAT=7;
20 public static final int DOUBLE=8;
21 public static final int VOID=9;
22 public static final int NULL=10;
23 public static final int TAG=11;
24 public static final int CLASS=12;
25 public static final int OFFSET=13;
30 ClassDescriptor class_desc;
31 boolean isClassNameRef = false;
33 private HashSet<AnnotationDescriptor> annotationSet;
35 public boolean equals(Object o) {
36 if (o instanceof TypeDescriptor) {
37 TypeDescriptor t=(TypeDescriptor)o;
40 if ((type==CLASS)&&(!t.getSymbol().equals(getSymbol())))
42 if (t.arraycount!=arraycount)
44 if (t.isClassNameRef != this.isClassNameRef)
51 public boolean isString() {
56 if (!getSymbol().equals(TypeUtil.StringClass))
61 public boolean isClassNameRef() {
62 return this.isClassNameRef;
65 public void setClassNameRef() {
66 this.isClassNameRef = true;
69 public int hashCode() {
70 int hashcode=type^arraycount;
72 hashcode^=getSymbol().hashCode();
76 public boolean iswrapper() {
77 if (arraycount!=0||!isClass())
79 return (name.equals("bytewrapper")||
80 name.equals("booleanwrapper")||
81 name.equals("shortwrapper")||
82 name.equals("intwrapper")||
83 name.equals("longwrapper")||
84 name.equals("charwrapper")||
85 name.equals("floatwrapper")||
86 name.equals("doublewrapper")||
87 name.equals("Objectwrapper"));
90 public TypeDescriptor makeArray(State state) {
91 TypeDescriptor td=new TypeDescriptor(getSymbol());
92 td.arraycount=arraycount+1;
94 td.class_desc=class_desc;
95 state.addArrayType(td);
99 public boolean isArray() {
100 return (arraycount>0);
103 public int getArrayCount() {
107 /* Only use this method if you really know what you are doing. It
108 * doesn't have the effect you might expect. */
110 public void setArrayCount(int a) {
114 public TypeDescriptor dereference() {
115 TypeDescriptor td=new TypeDescriptor(getSymbol());
118 td.arraycount=arraycount-1;
120 td.class_desc=class_desc;
124 public String getSafeSymbol() {
126 return IR.Flat.BuildCode.arraytype;
127 else if (isClass()) {
128 return class_desc.getSafeSymbol();
137 else if (isBoolean()) //Booleans are ints in C
150 throw new Error("Error Type: "+type);
153 public String getRepairSymbol() {
155 return IR.Flat.BuildCode.arraytype;
156 else if (isClass()) {
157 return class_desc.getSymbol();
166 else if (isBoolean()) //Booleans are ints in C
176 else throw new Error("Error Type: "+type);
179 public String getSafeDescriptor() {
180 //Can't safely use [ in C
182 return "_AR_"+this.dereference().getSafeDescriptor();
184 return class_desc.getSafeDescriptor();
191 else if (isBoolean())
203 else throw new Error();
206 public boolean isNumber() {
207 return (isIntegerType()||isFloat()||isDouble());
210 public boolean isByte() {
213 public boolean isNull() {
216 public boolean isShort() {
219 public boolean isInt() {
222 public boolean isLong() {
225 public boolean isChar() {
228 public boolean isBoolean() {
229 return type==BOOLEAN;
231 public boolean isFloat() {
234 public boolean isDouble() {
237 public boolean isVoid() {
241 public boolean isOffset() {
245 public boolean isPtr() {
246 return ((isClass()&&!isEnum())||isNull()||isTag()||isArray());
249 public boolean isIntegerType() {
250 return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
253 public void setClassDescriptor(ClassDescriptor cd) {
257 public boolean isPrimitive() {
258 return ((type>=BYTE)&&(type<=DOUBLE));
261 public boolean isEnum() {
262 if(this.type != CLASS) {
264 } else if(this.class_desc != null){
265 return this.class_desc.isEnum();
270 public boolean isClass() {
274 public boolean isTag() {
278 public boolean isImmutable() {
279 return isPrimitive() || isString();
282 public TypeDescriptor(NameDescriptor name) {
283 super(name.toString());
285 this.class_desc=null;
287 this.isClassNameRef =false;
288 this.annotationSet=new HashSet<AnnotationDescriptor>();
291 public TypeDescriptor(String st) {
294 this.class_desc=null;
296 this.isClassNameRef =false;
297 this.annotationSet=new HashSet<AnnotationDescriptor>();
300 public ClassDescriptor getClassDesc() {
304 public TypeDescriptor(ClassDescriptor cd) {
305 super(cd.getSymbol());
309 this.isClassNameRef =false;
310 this.annotationSet=new HashSet<AnnotationDescriptor>();
313 public TypeDescriptor(int t) {
317 this.isClassNameRef =false;
318 this.annotationSet=new HashSet<AnnotationDescriptor>();
321 public String toString() {
325 return decodeInt(type);
328 public String toPrettyString() {
333 for(int i=0; i<arraycount; i++)
338 private static String decodeInt(int type) {
341 else if (type==BOOLEAN)
343 else if (type==SHORT)
351 else if (type==FLOAT)
353 else if (type==DOUBLE)
360 return TypeUtil.TagClass;
361 else if (type==OFFSET)
363 else throw new Error();
366 public void addAnnotationMarker(AnnotationDescriptor an){
367 annotationSet.add(an);
370 public Set getAnnotationMarkerSet(){
371 return annotationSet;