Additional enhancements to compute mustremove and cantremove sets for
[repair.git] / Repair / RepairCompiler / MCC / IR / CastExpr.java
1 package MCC.IR;
2
3 import java.util.*;
4
5 public class CastExpr extends Expr {
6     
7     TypeDescriptor type;
8     Expr expr;
9
10     public Set freeVars() {
11         return expr.freeVars();
12     }
13
14     public Expr getExpr() {
15         return expr;
16     }
17
18     public void findmatch(Descriptor d, Set s) {
19         expr.findmatch(d,s);
20     }
21
22     public CastExpr(TypeDescriptor type, Expr expr) {
23         this.type = type;
24         this.expr = expr;
25     }
26
27     public String name() {
28         String str="";
29         str="(("+type.toString()+")"+expr.name()+")";
30         return str;
31     }
32
33     public boolean equals(Map remap, Expr e) {
34         if (e==null)
35             return false;
36         else if (!(e instanceof CastExpr))
37             return false;
38         else return ((this.type==((CastExpr)e).type)&&expr.equals(remap,((CastExpr)e).expr));
39     }
40
41     public boolean usesDescriptor(Descriptor d) {
42         return expr.usesDescriptor(d);
43     }
44
45     public Set getRequiredDescriptors() {
46         return expr.getRequiredDescriptors();
47     }
48
49     public void generate(CodeWriter writer, VarDescriptor dest) {
50         VarDescriptor vd = VarDescriptor.makeNew("expr");
51         expr.generate(writer, vd);
52         writer.outputline("int " + dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
53     }
54
55     public void prettyPrint(PrettyPrinter pp) {
56         pp.output("cast(" + type.getSafeSymbol() + ", ");
57         expr.prettyPrint(pp);
58         pp.output(")");
59     }
60
61     public TypeDescriptor getType() {
62         return type;
63     }
64
65     public TypeDescriptor typecheck(SemanticAnalyzer sa) {
66         TypeDescriptor td = expr.typecheck(sa);
67
68         if (td == null) {
69             return null;
70         }
71
72         if (!type.isSubtypeOf(td)) {
73             sa.getErrorReporter().report(null, "Expression type '" + td.getSymbol() + "' is not a parent of the cast type '" + type.getSymbol() + "'");
74             return null;
75         }
76
77         this.td = type;
78         return type;
79     }
80
81 }
82
83
84
85
86
87
88
89