Fixed some analysis problems...
[repair.git] / Repair / RepairCompiler / MCC / IR / AbstractRepair.java
index 033d8388f9d5beb90661d8d5059e116bd1a078ba..d7f9a023a8f940e809342cf7af77e876367827ba 100755 (executable)
@@ -1,4 +1,5 @@
 package MCC.IR;
+import MCC.State;
 
 class AbstractRepair {
     public final static int ADDTOSET=1;
@@ -28,7 +29,16 @@ class AbstractRepair {
            return "Unknown";
        }
     }
-    
+
+    public boolean isNewObject(boolean isdomain) {
+       if (getType()==ADDTOSET) {
+           return sources.allocSource((SetDescriptor)descriptor);
+       } else if (getType()==ADDTORELATION) {
+           RelationDescriptor rd=(RelationDescriptor)descriptor;
+           return sources.relallocSource(rd,isdomain);
+       } else throw new Error(type());
+    }
+
     public SetDescriptor getDomainSet() {
        if (torepair==null)
            return null;
@@ -69,7 +79,7 @@ class AbstractRepair {
                case ExprPredicate.COMPARISON:
                    {
                        RelationExpr re=((RelationExpr)((OpExpr)ep.expr).left);
-                       return ep.expr.getSet();
+                       return re.expr.getSet();
                    }
                default:
                    throw new Error("");
@@ -119,7 +129,7 @@ class AbstractRepair {
                case ExprPredicate.COMPARISON:
                    {
                        RelationExpr re=((RelationExpr)((OpExpr)ep.expr).left);
-                       return ep.expr.getSet();
+                       return re.expr.getSet();
                    }
                default:
                    throw new Error("");
@@ -129,9 +139,6 @@ class AbstractRepair {
        return null;
     }
 
-
-    
-
     public int getType() {
        return type;
     }
@@ -144,6 +151,30 @@ class AbstractRepair {
        return descriptor;
     }
 
+
+    /** This method tells whether the repair needs to remove objects *
+     *  from the relation, or whether the model definition rules make
+     *  the remove unnecessary.*/
+
+    public boolean needsRemoves(State state) {
+       assert type==MODIFYRELATION;
+       SetDescriptor sd=getPredicate().getPredicate().inverted()?getRangeSet():getDomainSet();
+       return !ConstraintDependence.rulesensurefunction(state,(RelationDescriptor)getDescriptor(), sd, getPredicate().getPredicate().inverted(), true);
+    }
+
+    /** This method tells whether the repair needs to force the
+     *  relation to be function-like.  */
+    
+    public boolean mayNeedFunctionEnforcement(State state) {
+       assert type==MODIFYRELATION;
+       SetDescriptor sd=getPredicate().getPredicate().inverted()?getRangeSet():getDomainSet(); 
+       if (ConstraintDependence.rulesensurefunction(state,(RelationDescriptor)getDescriptor(), sd, getPredicate().getPredicate().inverted(), false))
+           return false;
+       if (ConstraintDependence.constraintsensurefunction(state,(RelationDescriptor)getDescriptor(), sd, getPredicate().getPredicate().inverted(),false))
+           return false;
+       return true;
+    }
+    
     public AbstractRepair(DNFPredicate dp,int typ, Descriptor d, Sources s) {
        torepair=dp;
        type=typ;