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