6 * represents a symbol in the language (var name, function name, etc).
9 public class TypeDescriptor extends Descriptor {
10 public static final int BYTE=1;
11 public static final int SHORT=2;
12 public static final int INT=3;
13 public static final int LONG=4;
14 public static final int CHAR=5;
15 public static final int BOOLEAN=6;
16 public static final int FLOAT=7;
17 public static final int DOUBLE=8;
18 public static final int VOID=9;
19 public static final int NULL=10;
20 public static final int TAG=11;
21 public static final int CLASS=12;
22 public static final int OFFSET=13;
27 ClassDescriptor class_desc;
29 public boolean equals(Object o) {
30 if (o instanceof TypeDescriptor) {
31 TypeDescriptor t=(TypeDescriptor)o;
34 if ((type==CLASS)&&(!t.getSymbol().equals(getSymbol())))
36 if (t.arraycount!=arraycount)
43 public boolean isString() {
48 if (!getSymbol().equals(TypeUtil.StringClass))
53 public int hashCode() {
54 int hashcode=type^arraycount;
56 hashcode^=getSymbol().hashCode();
60 public TypeDescriptor makeArray(State state) {
61 TypeDescriptor td=new TypeDescriptor(getSymbol());
62 td.arraycount=arraycount+1;
64 td.class_desc=class_desc;
65 state.addArrayType(td);
69 public boolean isArray() {
70 return (arraycount>0);
73 public int getArrayCount() {
77 /* Only use this method if you really know what you are doing. It
78 * doesn't have the effect you might expect. */
80 public void setArrayCount(int a) {
84 public TypeDescriptor dereference() {
85 TypeDescriptor td=new TypeDescriptor(getSymbol());
88 td.arraycount=arraycount-1;
90 td.class_desc=class_desc;
94 public String getSafeSymbol() {
96 return IR.Flat.BuildCode.arraytype;
98 return class_desc.getSafeSymbol();
107 else if (isBoolean()) //Booleans are ints in C
119 else throw new Error("Error Type: "+type);
122 public String getRepairSymbol() {
124 return IR.Flat.BuildCode.arraytype;
126 return class_desc.getSymbol();
135 else if (isBoolean()) //Booleans are ints in C
145 else throw new Error("Error Type: "+type);
148 public String getSafeDescriptor() {
149 //Can't safely use [ in C
151 return "_AR_"+this.dereference().getSafeDescriptor();
153 return class_desc.getSafeDescriptor();
160 else if (isBoolean())
172 else throw new Error();
175 public boolean isNumber() {
176 return (isIntegerType()||isFloat()||isDouble());
179 public boolean isByte() {
182 public boolean isNull() {
185 public boolean isShort() {
188 public boolean isInt() {
191 public boolean isLong() {
194 public boolean isChar() {
197 public boolean isBoolean() {
198 return type==BOOLEAN;
200 public boolean isFloat() {
203 public boolean isDouble() {
206 public boolean isVoid() {
210 public boolean isOffset() {
214 public boolean isPtr() {
215 return (isClass()||isNull()||isTag()||isArray());
218 public boolean isIntegerType() {
219 return (isInt()||isLong()||isShort()||isChar()||isByte());
222 public void setClassDescriptor(ClassDescriptor cd) {
226 public boolean isPrimitive() {
227 return ((type>=BYTE)&&(type<=DOUBLE));
230 public boolean isClass() {
234 public boolean isTag() {
238 public boolean isImmutable() {
239 return isPrimitive() || isString();
242 public TypeDescriptor(NameDescriptor name) {
243 super(name.toString());
245 this.class_desc=null;
249 public TypeDescriptor(String st) {
252 this.class_desc=null;
256 public ClassDescriptor getClassDesc() {
260 public TypeDescriptor(ClassDescriptor cd) {
261 super(cd.getSymbol());
267 public TypeDescriptor(int t) {
273 public String toString() {
277 return decodeInt(type);
280 public String toPrettyString() {
283 for(int i=0; i<arraycount; i++)
287 return decodeInt(type);
290 private static String decodeInt(int type) {
293 else if (type==BOOLEAN)
295 else if (type==SHORT)
303 else if (type==FLOAT)
305 else if (type==DOUBLE)
312 return TypeUtil.TagClass;
313 else if (type==OFFSET)
315 else throw new Error();