5 public class OpExpr extends Expr {
11 public OpExpr(Opcode opcode, Expr left, Expr right) {
16 assert (right == null && opcode == Opcode.NOT) || (right != null);
19 public Set getRequiredDescriptors() {
20 Set v = left.getRequiredDescriptors();
23 v.addAll(right.getRequiredDescriptors());
29 public void generate(CodeWriter writer, VarDescriptor dest) {
30 VarDescriptor ld = VarDescriptor.makeNew("leftop");
31 left.generate(writer, ld);
32 VarDescriptor rd = null;
35 rd = VarDescriptor.makeNew("rightop");
36 right.generate(writer, rd);
40 if (opcode != Opcode.NOT) { /* two operands */
42 writer.outputline("int " + dest.getSafeSymbol() + " = " +
43 ld.getSafeSymbol() + " " + opcode.toString() + " " + rd.getSafeSymbol() + ";");
45 writer.outputline("int " + dest.getSafeSymbol() + " = !" + ld.getSafeSymbol() + ";");
49 public void prettyPrint(PrettyPrinter pp) {
51 if (opcode == Opcode.NOT) {
55 pp.output(" " + opcode.toString() + " ");
57 right.prettyPrint(pp);
62 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
63 TypeDescriptor lt = left.typecheck(sa);
64 TypeDescriptor rt = right == null ? null : right.typecheck(sa);
68 } else if (right != null && rt == null) {
74 // #ATTN#: if we want node.next != literal(0) to represent a null check than we need to allow ptr arithmetic
75 // either that or we use a isvalid clause to check for null
78 if (lt != ReservedTypeDescriptor.INT) {
79 sa.getErrorReporter().report(null, "Left hand side of expression is of type '" + lt.getSymbol() + "' but must be type 'int'");
84 if (rt != ReservedTypeDescriptor.INT) {
85 sa.getErrorReporter().report(null, "Right hand side of expression is of type '" + rt.getSymbol() + "' but must be type 'int'");
95 this.td = ReservedTypeDescriptor.INT;