add test case
[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 FLOAT=6;
16     public static final int DOUBLE=7;
17     public static final int VOID=8;
18     public static final int CLASS=9;
19
20
21     int type;
22     NameDescriptor name_desc;
23     
24     public TypeDescriptor(NameDescriptor name) {
25         super(name.toString());
26         this.type=CLASS;
27         this.name_desc=name;
28     }
29
30     public TypeDescriptor(int t) {
31         super(decodeInt(t));
32         this.type=t;
33     }
34
35     public String toString() {
36         if (type==CLASS)
37             return name_desc.toString();
38         else 
39             return decodeInt(type);
40     }
41
42     private static String decodeInt(int type) {
43         if (type==BYTE)
44             return "byte";
45         else if (type==SHORT)
46             return "short";
47         else if (type==INT)
48             return "int";
49         else if (type==LONG)
50             return "long";
51         else if (type==CHAR)
52             return "char";
53         else if (type==FLOAT)
54             return "float";
55         else if (type==DOUBLE)
56             return "double";
57         else if (type==VOID)
58             return "void";
59         else throw new Error();
60     }
61 }