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