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;
72 hashcode+=annotationSet.hashCode();
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();
139 else if (isBoolean()) //Booleans are ints in C
152 throw new Error("Error Type: "+type);
155 public String getRepairSymbol() {
157 return IR.Flat.BuildCode.arraytype;
158 else if (isClass()) {
159 return class_desc.getSymbol();
168 else if (isBoolean()) //Booleans are ints in C
178 else throw new Error("Error Type: "+type);
181 public String getSafeDescriptor() {
182 //Can't safely use [ in C
184 return "_AR_"+this.dereference().getSafeDescriptor();
186 return class_desc.getSafeDescriptor();
193 else if (isBoolean())
205 else throw new Error();
208 public boolean isNumber() {
209 return (isIntegerType()||isFloat()||isDouble());
212 public boolean isByte() {
215 public boolean isNull() {
218 public boolean isShort() {
221 public boolean isInt() {
224 public boolean isLong() {
227 public boolean isChar() {
230 public boolean isBoolean() {
231 return type==BOOLEAN;
233 public boolean isFloat() {
236 public boolean isDouble() {
239 public boolean isVoid() {
243 public boolean isOffset() {
247 public boolean isPtr() {
248 return ((isClass()&&!isEnum())||isNull()||isTag()||isArray());
251 public boolean isIntegerType() {
252 return (isInt()||isLong()||isShort()||isChar()||isByte()||isEnum());
255 public void setClassDescriptor(ClassDescriptor cd) {
259 public boolean isPrimitive() {
260 return ((type>=BYTE)&&(type<=DOUBLE));
263 public boolean isEnum() {
264 if(this.type != CLASS) {
266 } else if(this.class_desc != null){
267 return this.class_desc.isEnum();
272 public boolean isClass() {
276 public boolean isTag() {
280 public boolean isImmutable() {
281 return isPrimitive() || isString();
284 public TypeDescriptor(NameDescriptor name) {
285 super(name.toString());
287 this.class_desc=null;
289 this.isClassNameRef =false;
290 this.annotationSet=new Vector<AnnotationDescriptor>();
293 public TypeDescriptor(String st) {
296 this.class_desc=null;
298 this.isClassNameRef =false;
299 this.annotationSet=new Vector<AnnotationDescriptor>();
302 public ClassDescriptor getClassDesc() {
306 public TypeDescriptor(ClassDescriptor cd) {
307 super(cd.getSymbol());
311 this.isClassNameRef =false;
312 this.annotationSet=new Vector<AnnotationDescriptor>();
315 public TypeDescriptor(int t) {
319 this.isClassNameRef =false;
320 this.annotationSet=new Vector<AnnotationDescriptor>();
323 public String toString() {
327 return decodeInt(type);
330 public String toPrettyString() {
335 for(int i=0; i<arraycount; i++)
340 private static String decodeInt(int type) {
343 else if (type==BOOLEAN)
345 else if (type==SHORT)
353 else if (type==FLOAT)
355 else if (type==DOUBLE)
362 return TypeUtil.TagClass;
363 else if (type==OFFSET)
365 else throw new Error();
368 public void addAnnotationMarker(AnnotationDescriptor an){
369 annotationSet.add(an);
372 public Vector<AnnotationDescriptor> getAnnotationMarkers(){
373 return annotationSet;