5 public class CastExpr extends Expr {
10 public Set freeVars() {
11 return expr.freeVars();
14 public Expr getExpr() {
18 public void findmatch(Descriptor d, Set s) {
22 public CastExpr(TypeDescriptor type, Expr expr) {
27 public String name() {
29 str="(("+type.toString()+")"+expr.name()+")";
33 public boolean equals(Map remap, Expr e) {
36 else if (!(e instanceof CastExpr))
38 else return ((this.type==((CastExpr)e).type)&&expr.equals(remap,((CastExpr)e).expr));
41 public boolean usesDescriptor(Descriptor d) {
42 return expr.usesDescriptor(d);
45 public Set getRequiredDescriptors() {
46 return expr.getRequiredDescriptors();
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() + ";");
55 public void prettyPrint(PrettyPrinter pp) {
56 pp.output("cast(" + type.getSafeSymbol() + ", ");
61 public TypeDescriptor getType() {
65 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
66 TypeDescriptor td = expr.typecheck(sa);
72 if (!type.isSubtypeOf(td)) {
73 sa.getErrorReporter().report(null, "Expression type '" + td.getSymbol() + "' is not a parent of the cast type '" + type.getSymbol() + "'");