Compute Must Values Automatically
authorbdemsky <bdemsky@uci.edu>
Sun, 3 Sep 2017 03:46:12 +0000 (20:46 -0700)
committerbdemsky <bdemsky@uci.edu>
Sun, 3 Sep 2017 03:46:12 +0000 (20:46 -0700)
src/ASTAnalyses/polarityassignment.cc
src/ASTAnalyses/polarityassignment.h
src/csolver.cc

index 6b63436..f75c9ec 100644 (file)
@@ -9,12 +9,10 @@ void computePolarities(CSolver *This) {
                bool isNegated = boolean.isNegated();
                if (isNegated) {
                        updatePolarity(b, P_FALSE);
-                       updateMustValue(b, BV_MUSTBEFALSE);
                } else {
                        updatePolarity(b, P_TRUE);
-                       updateMustValue(b, BV_MUSTBETRUE);
                }
-               computePolarityAndBooleanValue(b);
+               computePolarity(b);
        }
        delete iterator;
 }
@@ -27,33 +25,32 @@ void updateMustValue(Boolean *This, BooleanValue value) {
        This->boolVal = (BooleanValue) (This->boolVal | value);
 }
 
-void computePolarityAndBooleanValue(Boolean *This) {
+void computePolarity(Boolean *This) {
        switch (This->type) {
        case BOOLEANVAR:
        case ORDERCONST:
                return;
        case PREDICATEOP:
-               return computePredicatePolarityAndBooleanValue((BooleanPredicate *)This);
+               return computePredicatePolarity((BooleanPredicate *)This);
        case LOGICOP:
-               return computeLogicOpPolarityAndBooleanValue((BooleanLogic *)This);
+               return computeLogicOpPolarity((BooleanLogic *)This);
        default:
                ASSERT(0);
        }
 }
 
-void computePredicatePolarityAndBooleanValue(BooleanPredicate *This) {
+void computePredicatePolarity(BooleanPredicate *This) {
        if (This->undefStatus) {
                updatePolarity(This->undefStatus.getBoolean(), P_BOTHTRUEFALSE);
-               computePolarityAndBooleanValue(This->undefStatus.getBoolean());
+               computePolarity(This->undefStatus.getBoolean());
        }
 }
 
-void computeLogicOpPolarityAndBooleanValue(BooleanLogic *This) {
-       computeLogicOpBooleanValue(This);
-       computeLogicOpPolarity(This);
+void computeLogicOpPolarity(BooleanLogic *This) {
+       computeLogicOpPolarityChildren(This);
        uint size = This->inputs.getSize();
        for (uint i = 0; i < size; i++) {
-               computePolarityAndBooleanValue(This->inputs.get(i).getBoolean());
+               computePolarity(This->inputs.get(i).getBoolean());
        }
 }
 
@@ -85,7 +82,7 @@ BooleanValue negateBooleanValue(BooleanValue This) {
        }
 }
 
-void computeLogicOpPolarity(BooleanLogic *This) {
+void computeLogicOpPolarityChildren(BooleanLogic *This) {
        Polarity parentpolarity = This->polarity;
        switch (This->op) {
        case SATC_AND: {
@@ -106,23 +103,3 @@ void computeLogicOpPolarity(BooleanLogic *This) {
                ASSERT(0);
        }
 }
-
-void computeLogicOpBooleanValue(BooleanLogic *This) {
-       BooleanValue parentbv = This->boolVal;
-       switch (This->op) {
-       case SATC_AND: {
-               if (parentbv == BV_MUSTBETRUE || parentbv == BV_UNSAT) {
-                       uint size = This->inputs.getSize();
-                       for (uint i = 0; i < size; i++) {
-                               BooleanEdge be=This->inputs.get(i);
-                               updateMustValue(be.getBoolean(), be.isNegated()?negateBooleanValue(parentbv):parentbv);
-                       }
-               }
-               return;
-       }
-       case SATC_IFF:
-               return;
-       default:
-               ASSERT(0);
-       }
-}
index 6621d77..6255875 100644 (file)
 void computePolarities(CSolver *This);
 void updatePolarity(Boolean *This, Polarity polarity);
 void updateMustValue(Boolean *This, BooleanValue value);
-void computePolarityAndBooleanValue(Boolean *boolean);
-void computePredicatePolarityAndBooleanValue(BooleanPredicate *This);
-void computeLogicOpPolarityAndBooleanValue(BooleanLogic *boolean);
+void computePolarity(Boolean *boolean);
+void computePredicatePolarity(BooleanPredicate *This);
+void computeLogicOpPolarity(BooleanLogic *boolean);
 Polarity negatePolarity(Polarity This);
 BooleanValue negateBooleanValue(BooleanValue This);
-void computeLogicOpPolarity(BooleanLogic *boolean);
-void computeLogicOpBooleanValue(BooleanLogic *boolean);
+void computeLogicOpPolarityChildren(BooleanLogic *boolean);
 
 #endif/* POLARITYASSIGNMENT_H */
index 3e240a4..ecc237e 100644 (file)
@@ -342,8 +342,12 @@ void CSolver::addConstraint(BooleanEdge constraint) {
                                return;
                        }
                }
-
                constraints.add(constraint);
+               Boolean *ptr=constraint.getBoolean();
+               if (constraint.isNegated())
+                       updateMustValue(ptr, BV_MUSTBEFALSE);
+               else
+                       updateMustValue(ptr, BV_MUSTBETRUE);
        }
 }