start of new file
[IRC.git] / Robust / src / IR / Tree / LiteralNode.java
1 package IR.Tree;
2 import IR.TypeDescriptor;
3 import IR.TypeUtil;
4
5
6 public class LiteralNode extends ExpressionNode {
7     public final static int INTEGER=1;
8     public final static int FLOAT=2;
9     public final static int BOOLEAN=3;
10     public final static int CHAR=4;
11     public final static int STRING=5;
12     public final static int NULL=6;
13
14     Object value;
15     TypeDescriptor type;
16     String typestr;
17
18     public LiteralNode(String type, Object o) {
19         typestr=type;
20         value=o;
21         type=null;
22     }
23
24     public String getTypeString() {
25         return typestr;
26     }
27
28     public TypeDescriptor getType() {
29         return type;
30     }
31
32     public void setType(TypeDescriptor td) {
33         type=td;
34     }
35
36     public Object getValue() {
37         return value;
38     }
39
40     public String printNode(int indent) {
41         if (typestr.equals("null"))
42             return "null";
43         if (typestr.equals("string")) {
44             return '"'+escapeString(value.toString())+'"';
45         }
46         return "/*"+typestr+ "*/"+value.toString();
47     }
48     private static String escapeString(String st) {
49         String new_st="";
50         for(int i=0;i<st.length();i++) {
51             char x=st.charAt(i);
52             if (x=='\n')
53                 new_st+="\\n";
54             else if (x=='"')
55                 new_st+="'"+'"'+"'";
56             else new_st+=x;
57         }
58         return new_st;
59     }
60     public int kind() {
61         return Kind.LiteralNode;
62     }
63 }