Further upgrades to semantic checker
[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 void setClassDescriptor(ClassDescriptor cd) {
28         class_desc=cd;
29     }
30
31     public boolean isVoid() {
32         return type==VOID;
33     }
34
35     public boolean isPrimitive() {
36         return ((type>=BYTE)&&(type<=DOUBLE));
37     }
38
39     public boolean isClass() {
40         return type==CLASS;
41     }
42
43     public TypeDescriptor(NameDescriptor name) {
44         super(name.toString());
45         this.type=CLASS;
46         this.class_desc=null;
47     }
48
49     public ClassDescriptor getClassDesc() {
50         return class_desc;
51     }
52
53     public TypeDescriptor(ClassDescriptor cd) {
54         super(cd.getSymbol());
55         this.type=CLASS;
56         this.class_desc=cd;
57     }
58
59     public TypeDescriptor(int t) {
60         super(decodeInt(t));
61         this.type=t;
62     }
63
64     public String toString() {
65         if (type==CLASS)
66             return name;
67         else 
68             return decodeInt(type);
69     }
70
71     private static String decodeInt(int type) {
72         if (type==BYTE)
73             return "byte";
74         else if (type==BOOLEAN)
75             return "boolean";
76         else if (type==SHORT)
77             return "short";
78         else if (type==INT)
79             return "int";
80         else if (type==LONG)
81             return "long";
82         else if (type==CHAR)
83             return "char";
84         else if (type==FLOAT)
85             return "float";
86         else if (type==DOUBLE)
87             return "double";
88         else if (type==VOID)
89             return "void";
90         else if (type==NULL)
91             return "null";
92         else throw new Error();
93     }
94 }