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 SetDescriptor getSet() {
22 public Set freeVars() {
23 return expr.freeVars();
26 public Expr getExpr() {
30 public boolean isInvariant(Set vars) {
34 public Set findInvariants(Set vars) {
35 return expr.findInvariants(vars);
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 void findmatch(Descriptor d, Set s) {
61 public Set useDescriptor(Descriptor d) {
62 return expr.useDescriptor(d);
65 public boolean usesDescriptor(Descriptor d) {
66 return expr.usesDescriptor(d);
69 public Set getRequiredDescriptors() {
70 return expr.getRequiredDescriptors();
73 public void generate(CodeWriter writer, VarDescriptor dest) {
74 VarDescriptor vd = VarDescriptor.makeNew("expr");
75 expr.generate(writer, vd);
76 writer.outputline("int " + dest.getSafeSymbol() + " = (int) " + vd.getSafeSymbol() + ";");
79 public void prettyPrint(PrettyPrinter pp) {
80 pp.output("cast(" + type.getSafeSymbol() + ", ");
85 public TypeDescriptor getType() {
89 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
90 TypeDescriptor td = expr.typecheck(sa);
96 if (!type.isSubtypeOf(td)) {
97 sa.getErrorReporter().report(null, "Expression type '" + td.getSymbol() + "' is not a parent of the cast type '" + type.getSymbol() + "'");