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))
39 public TypeDescriptor makeArray() {
40 TypeDescriptor td=new TypeDescriptor(getSymbol());
41 td.arraycount=arraycount+1;
43 td.class_desc=class_desc;
47 public boolean isArray() {
51 public TypeDescriptor dereference() {
52 TypeDescriptor td=new TypeDescriptor(getSymbol());
55 td.arraycount=arraycount-1;
57 td.class_desc=class_desc;
61 public String getSafeSymbol() {
63 return class_desc.getSafeSymbol();
72 else if (isBoolean()) //Booleans are ints in C
82 else throw new Error("Error Type: "+type);
85 public String getSafeDescriptor() {
87 return class_desc.getSafeDescriptor();
104 else throw new Error();
107 public boolean isNumber() {
108 return (isIntegerType()||isFloat()||isDouble());
111 public boolean isByte() {
114 public boolean isNull() {
117 public boolean isShort() {
120 public boolean isInt() {
123 public boolean isLong() {
126 public boolean isChar() {
129 public boolean isBoolean() {
130 return type==BOOLEAN;
132 public boolean isFloat() {
135 public boolean isDouble() {
138 public boolean isVoid() {
142 public boolean isPtr() {
143 return (isClass()||isNull());
146 public boolean isIntegerType() {
147 return (isInt()||isLong()||isShort()||isChar()||isByte());
150 public void setClassDescriptor(ClassDescriptor cd) {
154 public boolean isPrimitive() {
155 return ((type>=BYTE)&&(type<=DOUBLE));
158 public boolean isClass() {
162 public TypeDescriptor(NameDescriptor name) {
163 super(name.toString());
165 this.class_desc=null;
169 private TypeDescriptor(String st) {
173 public ClassDescriptor getClassDesc() {
177 public TypeDescriptor(ClassDescriptor cd) {
178 super(cd.getSymbol());
184 public TypeDescriptor(int t) {
190 public String toString() {
194 return decodeInt(type);
197 private static String decodeInt(int type) {
200 else if (type==BOOLEAN)
202 else if (type==SHORT)
210 else if (type==FLOAT)
212 else if (type==DOUBLE)
218 else throw new Error();