More bug fixes...and debug flags
[repair.git] / Repair / RepairCompiler / MCC / IR / OpExpr.java
index 8693aa3965a77d8ff08cc692b9c5b18f96040143..3fe5297050b4c68c6efc1bd1d1c9ff21f3734fae 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)
@@ -15,6 +63,8 @@ public class OpExpr extends Expr {
     }
 
     public static boolean isInt(Expr e) {
+       if (e==null)
+           return false;
        if ((e instanceof IntegerLiteralExpr)||
            ((e instanceof OpExpr)&&(((OpExpr)e).opcode==Opcode.NOP)&&(((OpExpr)e).getLeftExpr() instanceof IntegerLiteralExpr)))
            return true;
@@ -35,8 +85,8 @@ public class OpExpr extends Expr {
            (isInt(left)&&(opcode==Opcode.RND))) {
            this.opcode=Opcode.NOP;
            this.right=null;
-           int lint=getInt(left);
-           int rint=getInt(right);
+           int lint=isInt(left)?getInt(left):0;
+           int rint=isInt(right)?getInt(right):0;
            int value=0;
            if (opcode==Opcode.ADD) {
                value=lint+rint;
@@ -134,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;
@@ -167,16 +214,18 @@ 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 int[] getRepairs(boolean negated) {
+    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};
        if (left instanceof SizeofExpr) {
@@ -197,35 +246,51 @@ public class OpExpr extends Expr {
                    op=Opcode.GT;
            }
 
+           int maxsize=t.maxsize.getsize(getDescriptor());
+           int size=getInt(right);
 
 
            boolean isRelation=((SizeofExpr)left).setexpr instanceof ImageSetExpr;
            if (isRelation) {
                if (op==Opcode.EQ) {
-                   if (((IntegerLiteralExpr)right).getValue()==0)
+                   if (size==0)
                        return new int[] {AbstractRepair.REMOVEFROMRELATION};
-                   else
+                   else {
+                       if ((maxsize!=-1)&&maxsize<=size)
+                           return new int[] {AbstractRepair.ADDTORELATION};
                        return new int[] {AbstractRepair.ADDTORELATION,
                                          AbstractRepair.REMOVEFROMRELATION};
+                   }
                } else if (op==Opcode.GE||op==Opcode.GT) {
                    return new int[]{AbstractRepair.ADDTORELATION}; 
                } else if (op==Opcode.LE||op==Opcode.LT) {
+                   if ((op==Opcode.LT&&maxsize!=-1&&maxsize<size)||(op==Opcode.LE&&maxsize!=-1&&maxsize<=size))
+                       return new int[0];
                    return new int[]{AbstractRepair.REMOVEFROMRELATION};
                } else if (op==Opcode.NE) {
+                   if (maxsize<size&&maxsize!=-1)
+                       return new int[0];
                    return new int[]{AbstractRepair.ADDTORELATION};
                } else throw new Error();
            } else {
                if (op==Opcode.EQ) {
-                   if (((IntegerLiteralExpr)right).getValue()==0)
+                   if (size==0)
                        return new int[] {AbstractRepair.REMOVEFROMSET};                        
-                   else
+                   else {
+                       if (maxsize<=size&&maxsize!=-1)
+                           return new int[] {AbstractRepair.ADDTOSET};
                        return new int[] {AbstractRepair.ADDTOSET,
                                              AbstractRepair.REMOVEFROMSET};
+                   }
                } else if (op==Opcode.GE||op==Opcode.GT) {
                    return new int[] {AbstractRepair.ADDTOSET}; 
                } else if (op==Opcode.LE||op==Opcode.LT) {
+                   if ((op==Opcode.LT&&maxsize<size&&maxsize!=-1)||(op==Opcode.LE&&maxsize<=size&&maxsize!=-1))
+                       return new int[0];
                    return new int[] {AbstractRepair.REMOVEFROMSET};
                } else if (op==Opcode.NE) {
+                   if (maxsize<size&&maxsize!=-1)
+                       return new int[0];
                    return new int[] {AbstractRepair.ADDTOSET};
                } else throw new Error();
            }