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 DNFRule constructDNF() {
20 if (opcode==Opcode.AND) {
21 DNFRule leftd=left.constructDNF();
22 DNFRule rightd=right.constructDNF();
23 return leftd.and(rightd);
24 } else if (opcode==Opcode.OR) {
25 DNFRule leftd=left.constructDNF();
26 DNFRule rightd=right.constructDNF();
27 return leftd.or(rightd);
28 } else if (opcode==Opcode.NOT) {
29 DNFRule leftd=left.constructDNF();
31 } else throw new Error();
36 public Set getInversedRelations() {
37 Set set = left.getInversedRelations();
39 set.addAll(right.getInversedRelations());
44 public Set getRequiredDescriptors() {
45 Set v = left.getRequiredDescriptors();
48 v.addAll(right.getRequiredDescriptors());
54 public void generate(CodeWriter writer, VarDescriptor dest) {
55 VarDescriptor ld = VarDescriptor.makeNew("leftop");
56 left.generate(writer, ld);
57 VarDescriptor rd = null;
60 rd = VarDescriptor.makeNew("rightop");
61 right.generate(writer, rd);
65 if (opcode != Opcode.NOT) { /* two operands */
67 writer.outputline("int " + dest.getSafeSymbol() + " = " +
68 ld.getSafeSymbol() + " " + opcode.toString() + " " + rd.getSafeSymbol() + ";");
70 writer.outputline("int " + dest.getSafeSymbol() + " = !" + ld.getSafeSymbol() + ";");
74 public void prettyPrint(PrettyPrinter pp) {
76 if (opcode == Opcode.NOT) {
80 pp.output(" " + opcode.toString() + " ");
82 right.prettyPrint(pp);
87 public TypeDescriptor typecheck(SemanticAnalyzer sa) {
88 TypeDescriptor lt = left.typecheck(sa);
89 TypeDescriptor rt = right == null ? null : right.typecheck(sa);
93 } else if (right != null && rt == null) {
99 // #ATTN#: if we want node.next != literal(0) to represent a null check than we need to allow ptr arithmetic
100 // either that or we use a isvalid clause to check for null
103 if (lt != ReservedTypeDescriptor.INT) {
104 sa.getErrorReporter().report(null, "Left hand side of expression is of type '" + lt.getSymbol() + "' but must be type 'int'");
109 if (rt != ReservedTypeDescriptor.INT) {
110 sa.getErrorReporter().report(null, "Right hand side of expression is of type '" + rt.getSymbol() + "' but must be type 'int'");
120 this.td = ReservedTypeDescriptor.INT;