2 import IR.TypeDescriptor;
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;
18 public LiteralNode(String type, Object o) {
24 public String getTypeString() {
28 public TypeDescriptor getType() {
32 public void setType(TypeDescriptor td) {
36 public Object getValue() {
40 public String printNode(int indent) {
41 if (typestr.equals("null"))
43 if (typestr.equals("string")) {
44 return '"'+escapeString(value.toString())+'"';
46 return "/*"+typestr+ "*/"+value.toString();
48 private static String escapeString(String st) {
50 for(int i=0; i<st.length(); i++) {
61 return Kind.LiteralNode;
64 public Long evaluate() {
66 if(this.type.isChar() || this.type.isInt()) {
67 eval = Long.parseLong(this.value.toString());