Bugs with generating ands and ors...ahh.
[repair.git] / Repair / RepairCompiler / MCC / IR / OpExpr.java
index 4714735bd32e8c284a6538e9f53360433b76e102..23644364db60649b6a49b0e227405be1b741fa91 100755 (executable)
@@ -8,6 +8,54 @@ public class OpExpr extends Expr {
     Expr right;
     Opcode opcode;
 
+    public Expr getUpper() {
+       Expr lupper=left.getUpper();
+       if (lupper==null)
+           return null;
+       if (right!=null) {
+           Expr rupper=right.getUpper();
+           if (rupper==null)
+               return null;
+           OpExpr oe=new OpExpr(this.opcode,lupper,rupper);
+           oe.td = ReservedTypeDescriptor.INT;
+           return oe;
+       } else return lupper;
+    }
+
+    public Expr getLower() {
+       Expr llower=left.getLower();
+       if (llower==null)
+           return null;
+       if (right!=null) {
+           Expr rlower=right.getLower();
+           if (rlower==null)
+               return null;
+           OpExpr oe=new OpExpr(this.opcode,llower,rlower);
+           oe.td = ReservedTypeDescriptor.INT;
+           return oe;
+       } else return llower;
+    }
+
+    public boolean isSafe() {
+       if (right==null)
+           return left.isSafe();
+       return left.isSafe()&&right.isSafe();
+    }
+
+    public Set getfunctions() {
+       Set leftfunctions=left.getfunctions();
+       Set rightfunctions=right.getfunctions();
+       if (leftfunctions!=null&&rightfunctions!=null) {
+           HashSet functions=new HashSet();
+           functions.addAll(leftfunctions);
+           functions.addAll(rightfunctions);
+           return functions;
+       }
+       if (leftfunctions!=null)
+           return leftfunctions;
+       return rightfunctions;
+    }
+
     public void findmatch(Descriptor d, Set  s) {
        left.findmatch(d,s);
        if (right!=null)
@@ -136,9 +184,6 @@ public class OpExpr extends Expr {
        return opcode;
     }
 
-
-
-
     public boolean equals(Map remap, Expr e) {
        if (e==null||!(e instanceof OpExpr))
            return false;
@@ -169,15 +214,17 @@ public class OpExpr extends Expr {
     }
 
     public boolean usesDescriptor(Descriptor d) {
-       if (opcode==Opcode.GT||opcode==Opcode.GE||opcode==Opcode.LT||
-           opcode==Opcode.LE||opcode==Opcode.EQ||opcode==Opcode.NE)
-           return left.usesDescriptor(d)||(right!=null&&right.usesDescriptor(d));
-           //      return right.usesDescriptor(d);
-       else
-           return left.usesDescriptor(d)||(right!=null&&right.usesDescriptor(d));
+       return left.usesDescriptor(d)||(right!=null&&right.usesDescriptor(d));
     }
-    
 
+    public Set useDescriptor(Descriptor d) {
+       HashSet newset=new HashSet();
+       newset.addAll(left.useDescriptor(d));
+       if (right!=null)
+           newset.addAll(right.useDescriptor(d));
+       return newset;
+    }
+    
     public int[] getRepairs(boolean negated, Termination t) {
        if (left instanceof RelationExpr)
            return new int[] {AbstractRepair.MODIFYRELATION};
@@ -288,7 +335,7 @@ public class OpExpr extends Expr {
            if ((opcode==Opcode.OR)||
                (opcode==Opcode.AND)) {
                writer.outputline("int "+lm.getSafeSymbol()+"=maybe;");
-               writer.outputline("int maybe=0;");
+               writer.outputline("maybe=0;");
            }
 
             rd = VarDescriptor.makeNew("rightop");
@@ -306,12 +353,12 @@ public class OpExpr extends Expr {
         } else if (opcode == Opcode.AND) {
            writer.outputline("int "+rm.getSafeSymbol()+"=maybe;");
            writer.outputline("maybe = (" + ld.getSafeSymbol() + " && " + rm.getSafeSymbol() + ") || (" + rd.getSafeSymbol() + " && " + lm.getSafeSymbol() + ") || (" + lm.getSafeSymbol() + " && " + rm.getSafeSymbol() + ");");
-           writer.outputline(dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " && " + rd.getSafeSymbol() + ";");
+           writer.outputline("int "+dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " && " + rd.getSafeSymbol() + ";");
        } else if (opcode == Opcode.OR) {
            writer.outputline("int "+rm.getSafeSymbol()+"=maybe;");
            writer.outputline("maybe = (!" + ld.getSafeSymbol() + " && " + rm.getSafeSymbol() + ") || (!" + rd.getSafeSymbol() +
                              " && " + lm.getSafeSymbol() + ") || (" + lm.getSafeSymbol() + " && " + rm.getSafeSymbol() + ");");
-           writer.outputline(dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " || " + rd.getSafeSymbol() +
+           writer.outputline("int "+dest.getSafeSymbol() + " = " + ld.getSafeSymbol() + " || " + rd.getSafeSymbol() +
                              ";");
        } else if (opcode != Opcode.NOT) { /* two operands */
             assert rd != null;