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 getInversedRelations() {
20 Set set = left.getInversedRelations();
22 set.addAll(right.getInversedRelations());
27 public Set getRequiredDescriptors() {
28 Set v = left.getRequiredDescriptors();
31 v.addAll(right.getRequiredDescriptors());
37 public void generate(CodeWriter writer, VarDescriptor dest) {
38 VarDescriptor ld = VarDescriptor.makeNew("leftop");
39 left.generate(writer, ld);
40 VarDescriptor rd = null;
43 rd = VarDescriptor.makeNew("rightop");
44 right.generate(writer, rd);
48 if (opcode != Opcode.NOT) { /* two operands */
50 writer.outputline("int " + dest.getSafeSymbol() + " = " +
51 ld.getSafeSymbol() + " " + opcode.toString() + " " + rd.getSafeSymbol() + ";");
53 writer.outputline("int " + dest.getSafeSymbol() + " = !" + ld.getSafeSymbol() + ";");
57 public void prettyPrint(PrettyPrinter pp) {
59 if (opcode == Opcode.NOT) {
63 pp.output(" " + opcode.toString() + " ");
65 right.prettyPrint(pp);
70 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
71 TypeDescriptor lt = left.typecheck(sa);
72 TypeDescriptor rt = right == null ? null : right.typecheck(sa);
76 } else if (right != null && rt == null) {
82 // #ATTN#: if we want node.next != literal(0) to represent a null check than we need to allow ptr arithmetic
83 // either that or we use a isvalid clause to check for null
86 if (lt != ReservedTypeDescriptor.INT) {
87 sa.getErrorReporter().report(null, "Left hand side of expression is of type '" + lt.getSymbol() + "' but must be type 'int'");
92 if (rt != ReservedTypeDescriptor.INT) {
93 sa.getErrorReporter().report(null, "Right hand side of expression is of type '" + rt.getSymbol() + "' but must be type 'int'");
103 this.td = ReservedTypeDescriptor.INT;