5 public class CastExpr extends Expr {
10 public CastExpr(TypeDescriptor type, Expr expr) {
15 public String name() {
17 str="(("+type.toString()+")"+expr.name()+")";
21 public boolean equals(Map remap, Expr e) {
24 else if (!(e instanceof CastExpr))
26 else return ((this.type==((CastExpr)e).type)&&expr.equals(remap,((CastExpr)e).expr));
29 public boolean usesDescriptor(Descriptor d) {
30 return expr.usesDescriptor(d);
33 public Set getRequiredDescriptors() {
34 return expr.getRequiredDescriptors();
37 public void generate(CodeWriter writer, VarDescriptor dest) {
38 VarDescriptor vd = VarDescriptor.makeNew("expr");
39 expr.generate(writer, vd);
40 writer.outputline("int " + dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
43 public void prettyPrint(PrettyPrinter pp) {
44 pp.output("cast(" + type.getSafeSymbol() + ", ");
49 public TypeDescriptor getType() {
53 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
54 TypeDescriptor td = expr.typecheck(sa);
60 if (!type.isSubtypeOf(td)) {
61 sa.getErrorReporter().report(null, "Expression type '" + td.getSymbol() + "' is not a parent of the cast type '" + type.getSymbol() + "'");