5 public class CastExpr extends Expr {
10 public boolean isValue(TypeDescriptor td) {
11 if (td==null) /* Don't know type */
13 if (!td.isSubtypeOf(type)) /* Not subtype of us */
15 return expr.isValue(td);
18 public Set freeVars() {
19 return expr.freeVars();
22 public Expr getExpr() {
26 public boolean isInvariant(Set vars) {
30 public Set findInvariants(Set vars) {
31 return expr.findInvariants(vars);
34 public void findmatch(Descriptor d, Set s) {
38 public CastExpr(TypeDescriptor type, Expr expr) {
43 public String name() {
45 str="(("+type.toString()+")"+expr.name()+")";
49 public boolean equals(Map remap, Expr e) {
52 else if (!(e instanceof CastExpr))
54 else return ((this.type==((CastExpr)e).type)&&expr.equals(remap,((CastExpr)e).expr));
57 public Set useDescriptor(Descriptor d) {
58 return expr.useDescriptor(d);
61 public boolean usesDescriptor(Descriptor d) {
62 return expr.usesDescriptor(d);
65 public Set getRequiredDescriptors() {
66 return expr.getRequiredDescriptors();
69 public void generate(CodeWriter writer, VarDescriptor dest) {
70 VarDescriptor vd = VarDescriptor.makeNew("expr");
71 expr.generate(writer, vd);
72 writer.outputline("int " + dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
75 public void prettyPrint(PrettyPrinter pp) {
76 pp.output("cast(" + type.getSafeSymbol() + ", ");
81 public TypeDescriptor getType() {
85 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
86 TypeDescriptor td = expr.typecheck(sa);
92 if (!type.isSubtypeOf(td)) {
93 sa.getErrorReporter().report(null, "Expression type '" + td.getSymbol() + "' is not a parent of the cast type '" + type.getSymbol() + "'");