5 public class CastExpr extends Expr {
10 public CastExpr(TypeDescriptor type, Expr expr) {
15 public Set getRequiredDescriptors() {
16 return expr.getRequiredDescriptors();
19 public void generate(CodeWriter writer, VarDescriptor dest) {
20 VarDescriptor vd = VarDescriptor.makeNew("expr");
21 expr.generate(writer, vd);
22 writer.outputline("int " + dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
25 public void prettyPrint(PrettyPrinter pp) {
26 pp.output("cast(" + type.getSafeSymbol() + ", ");
31 public TypeDescriptor getType() {
35 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
36 TypeDescriptor td = expr.typecheck(sa);
42 if (!type.isSubtypeOf(td)) {
43 sa.getErrorReporter().report(null, "Expression type '" + td.getSymbol() + "' is not a parent of the cast type '" + type.getSymbol() + "'");