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 CLASS=11;
25 ClassDescriptor class_desc;
27 public boolean equals(Object o) {
28 if (o instanceof TypeDescriptor) {
29 TypeDescriptor t=(TypeDescriptor)o;
32 if ((type==CLASS)&&(t.class_desc!=class_desc))
34 if (t.arraycount!=arraycount)
41 public int hashCode() {
42 int hashcode=type^arraycount;
44 hashcode^=class_desc.hashCode();
48 public TypeDescriptor makeArray(State state) {
49 TypeDescriptor td=new TypeDescriptor(getSymbol());
50 td.arraycount=arraycount+1;
52 td.class_desc=class_desc;
53 state.addArrayType(td);
57 public boolean isArray() {
61 public TypeDescriptor dereference() {
62 TypeDescriptor td=new TypeDescriptor(getSymbol());
65 td.arraycount=arraycount-1;
67 td.class_desc=class_desc;
71 public String getSafeSymbol() {
73 return class_desc.getSafeSymbol();
82 else if (isBoolean()) //Booleans are ints in C
92 else throw new Error("Error Type: "+type);
95 public String getSafeDescriptor() {
97 return class_desc.getSafeDescriptor();
104 else if (isBoolean())
114 else throw new Error();
117 public boolean isNumber() {
118 return (isIntegerType()||isFloat()||isDouble());
121 public boolean isByte() {
124 public boolean isNull() {
127 public boolean isShort() {
130 public boolean isInt() {
133 public boolean isLong() {
136 public boolean isChar() {
139 public boolean isBoolean() {
140 return type==BOOLEAN;
142 public boolean isFloat() {
145 public boolean isDouble() {
148 public boolean isVoid() {
152 public boolean isPtr() {
153 return (isClass()||isNull());
156 public boolean isIntegerType() {
157 return (isInt()||isLong()||isShort()||isChar()||isByte());
160 public void setClassDescriptor(ClassDescriptor cd) {
164 public boolean isPrimitive() {
165 return ((type>=BYTE)&&(type<=DOUBLE));
168 public boolean isClass() {
172 public TypeDescriptor(NameDescriptor name) {
173 super(name.toString());
175 this.class_desc=null;
179 private TypeDescriptor(String st) {
183 public ClassDescriptor getClassDesc() {
187 public TypeDescriptor(ClassDescriptor cd) {
188 super(cd.getSymbol());
194 public TypeDescriptor(int t) {
200 public String toString() {
204 return decodeInt(type);
207 private static String decodeInt(int type) {
210 else if (type==BOOLEAN)
212 else if (type==SHORT)
220 else if (type==FLOAT)
222 else if (type==DOUBLE)
228 else throw new Error();