7754240a6983a33633f29f812bd11a372a229dd5
[repair.git] / Repair / RepairCompiler / MCC / IR / TokenLiteralExpr.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class TokenLiteralExpr extends LiteralExpr {
6
7     String token;
8     Integer num;
9
10     static int count = 100;
11     static Hashtable tokens = new Hashtable(); 
12
13     public TokenLiteralExpr(String token) {               
14         this.token = token;
15         td = ReservedTypeDescriptor.INT;
16         
17         if (tokens.contains(token)) {
18             num = (Integer) tokens.get(token);
19         } else {
20             num = new Integer(count++);
21             tokens.put(token, num);
22         }           
23     }
24
25     public String getValue() {
26         return token;
27     }
28
29     public void generate(CodeWriter writer, VarDescriptor dest) {
30         writer.outputline("int " + dest.getSafeSymbol() + " = " + num.toString().toString() + ";");
31     }
32     
33     public void prettyPrint(PrettyPrinter pp) {
34         pp.output("{" + token + " = " + num + "}"); 
35     }
36
37     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
38         td = ReservedTypeDescriptor.INT;
39         return td;
40     }
41
42 }