5 public class CastExpr extends Expr {
10 public CastExpr(TypeDescriptor type, Expr expr) {
15 public abstract boolean equals(Map remap, Expr e) {
18 else if (!e instanceof CastExpr)
20 else return ((this.type==((CastExpr)e).type)&&equals(remap,expr,((CastExpr)e).expr));
23 public Set getRequiredDescriptors() {
24 return expr.getRequiredDescriptors();
27 public void generate(CodeWriter writer, VarDescriptor dest) {
28 VarDescriptor vd = VarDescriptor.makeNew("expr");
29 expr.generate(writer, vd);
30 writer.outputline("int " + dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
33 public void prettyPrint(PrettyPrinter pp) {
34 pp.output("cast(" + type.getSafeSymbol() + ", ");
39 public TypeDescriptor getType() {
43 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
44 TypeDescriptor td = expr.typecheck(sa);
50 if (!type.isSubtypeOf(td)) {
51 sa.getErrorReporter().report(null, "Expression type '" + td.getSymbol() + "' is not a parent of the cast type '" + type.getSymbol() + "'");