a:w
[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     ClassDescriptor class_desc;
26
27     public boolean isByte() {
28         return type==BYTE;
29     }
30     public boolean isShort() {
31         return type==SHORT;
32     }
33     public boolean isInt() {
34         return type==INT;
35     }
36     public boolean isLong() {
37         return type==LONG;
38     }
39     public boolean isChar() {
40         return type==CHAR;
41     }
42     public boolean isBoolean() {
43         return type==BOOLEAN;
44     }
45     public boolean isFloat() {
46         return type==FLOAT;
47     }
48     public boolean isDouble() {
49         return type==DOUBLE;
50     }
51
52
53     public void setClassDescriptor(ClassDescriptor cd) {
54         class_desc=cd;
55     }
56   
57     public boolean isVoid() {
58         return type==VOID;
59     }
60
61     public boolean isPrimitive() {
62         return ((type>=BYTE)&&(type<=DOUBLE));
63     }
64
65     public boolean isClass() {
66         return type==CLASS;
67     }
68
69     public TypeDescriptor(NameDescriptor name) {
70         super(name.toString());
71         this.type=CLASS;
72         this.class_desc=null;
73     }
74
75     public ClassDescriptor getClassDesc() {
76         return class_desc;
77     }
78
79     public TypeDescriptor(ClassDescriptor cd) {
80         super(cd.getSymbol());
81         this.type=CLASS;
82         this.class_desc=cd;
83     }
84
85     public TypeDescriptor(int t) {
86         super(decodeInt(t));
87         this.type=t;
88     }
89
90     public String toString() {
91         if (type==CLASS)
92             return name;
93         else 
94             return decodeInt(type);
95     }
96
97     private static String decodeInt(int type) {
98         if (type==BYTE)
99             return "byte";
100         else if (type==BOOLEAN)
101             return "boolean";
102         else if (type==SHORT)
103             return "short";
104         else if (type==INT)
105             return "int";
106         else if (type==LONG)
107             return "long";
108         else if (type==CHAR)
109             return "char";
110         else if (type==FLOAT)
111             return "float";
112         else if (type==DOUBLE)
113             return "double";
114         else if (type==VOID)
115             return "void";
116         else if (type==NULL)
117             return "null";
118         else throw new Error();
119     }
120 }