Finish semantic checks
[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     public void setClassDescriptor(ClassDescriptor cd) {
53         class_desc=cd;
54     }
55   
56     public boolean isVoid() {
57         return type==VOID;
58     }
59
60     public boolean isPrimitive() {
61         return ((type>=BYTE)&&(type<=DOUBLE));
62     }
63
64     public boolean isClass() {
65         return type==CLASS;
66     }
67
68     public TypeDescriptor(NameDescriptor name) {
69         super(name.toString());
70         this.type=CLASS;
71         this.class_desc=null;
72     }
73
74     public ClassDescriptor getClassDesc() {
75         return class_desc;
76     }
77
78     public TypeDescriptor(ClassDescriptor cd) {
79         super(cd.getSymbol());
80         this.type=CLASS;
81         this.class_desc=cd;
82     }
83
84     public TypeDescriptor(int t) {
85         super(decodeInt(t));
86         this.type=t;
87     }
88
89     public String toString() {
90         if (type==CLASS)
91             return name;
92         else 
93             return decodeInt(type);
94     }
95
96     private static String decodeInt(int type) {
97         if (type==BYTE)
98             return "byte";
99         else if (type==BOOLEAN)
100             return "boolean";
101         else if (type==SHORT)
102             return "short";
103         else if (type==INT)
104             return "int";
105         else if (type==LONG)
106             return "long";
107         else if (type==CHAR)
108             return "char";
109         else if (type==FLOAT)
110             return "float";
111         else if (type==DOUBLE)
112             return "double";
113         else if (type==VOID)
114             return "void";
115         else if (type==NULL)
116             return "null";
117         else throw new Error();
118     }
119 }