checking in changes
[IRC.git] / Robust / src / IR / TypeDescriptor.java
1 package IR;
2
3 /**
4  * Descriptor 
5  *
6  * represents a symbol in the language (var name, function name, etc).
7  */
8
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;
21
22
23
24     int type;
25     NameDescriptor name_desc;
26     ClassDescriptor class_desc;
27
28     public void setClassDescriptor(ClassDescriptor cd) {
29         class_desc=cd;
30     }
31
32     public boolean isVoid() {
33         return type==VOID;
34     }
35
36     public boolean isPrimitive() {
37         return ((type>=BYTE)&&(type<=DOUBLE));
38     }
39
40     public boolean isClass() {
41         return type==CLASS;
42     }
43
44     public TypeDescriptor(NameDescriptor name) {
45         super(name.toString());
46         this.type=CLASS;
47         this.name_desc=name;
48         this.class_desc=null;
49     }
50
51     public TypeDescriptor(int t) {
52         super(decodeInt(t));
53         this.type=t;
54     }
55
56     public String toString() {
57         if (type==CLASS)
58             return name_desc.toString();
59         else 
60             return decodeInt(type);
61     }
62
63     private static String decodeInt(int type) {
64         if (type==BYTE)
65             return "byte";
66         else if (type==BOOLEAN)
67             return "boolean";
68         else if (type==SHORT)
69             return "short";
70         else if (type==INT)
71             return "int";
72         else if (type==LONG)
73             return "long";
74         else if (type==CHAR)
75             return "char";
76         else if (type==FLOAT)
77             return "float";
78         else if (type==DOUBLE)
79             return "double";
80         else if (type==VOID)
81             return "void";
82         else if (type==NULL)
83             return "null";
84         else throw new Error();
85     }
86 }