#include "csolver.h"
void computePolarities(CSolver *This) {
+ if(This->isUnSAT()){
+ return;
+ }
SetIteratorBooleanEdge *iterator = This->getConstraints();
while (iterator->hasNext()) {
BooleanEdge boolean = iterator->next();
delete iterator;
}
+void updateEdgePolarity(BooleanEdge dst, BooleanEdge src) {
+ Boolean *bdst = dst.getBoolean();
+ Boolean *bsrc = src.getBoolean();
+ bool isNegated = dst.isNegated() ^ src.isNegated();
+ Polarity p = isNegated ? negatePolarity(bsrc->polarity) : bsrc->polarity;
+ updatePolarity(bdst, p);
+}
+
+void updateEdgePolarity(BooleanEdge dst, Polarity p) {
+ Boolean *bdst = dst.getBoolean();
+ bool isNegated = dst.isNegated();
+ if (isNegated)
+ p = negatePolarity(p);
+ updatePolarity(bdst, p);
+}
+
bool updatePolarity(Boolean *This, Polarity polarity) {
Polarity oldpolarity = This->polarity;
Polarity newpolarity = (Polarity) (This->polarity | polarity);
switch (This->type) {
case BOOLEANVAR:
case ORDERCONST:
+ case BOOLCONST:
return;
case PREDICATEOP:
return computePredicatePolarity((BooleanPredicate *)This);
if (This->undefStatus) {
computePolarity(This->undefStatus.getBoolean(), P_BOTHTRUEFALSE);
}
+ for (uint i = 0; i < This->inputs.getSize(); i++) {
+ Element *e = This->inputs.get(i);
+ computeElement(e);
+ }
+}
+
+void computeElement(Element *e) {
+ if (e->type == ELEMFUNCRETURN) {
+ ElementFunction *ef = (ElementFunction *) e;
+
+ if (ef->overflowstatus) {
+ computePolarity(ef->overflowstatus.getBoolean(), P_BOTHTRUEFALSE);
+ }
+
+ for (uint i = 0; i < ef->inputs.getSize(); i++) {
+ Element *echild = ef->inputs.get(i);
+ computeElement(echild);
+ }
+ }
}
void computeLogicOpPolarity(BooleanLogic *This) {
}
}
-Polarity negatePolarity(Polarity This) {
- switch (This) {
- case P_UNDEFINED:
- case P_BOTHTRUEFALSE:
- return This;
- case P_TRUE:
- return P_FALSE;
- case P_FALSE:
- return P_TRUE;
- default:
- ASSERT(0);
- }
-}
-
BooleanValue negateBooleanValue(BooleanValue This) {
switch (This) {
case BV_UNDEFINED:
ASSERT(0);
}
}
+
+Polarity negatePolarity(Polarity This) {
+ switch (This) {
+ case P_UNDEFINED:
+ case P_BOTHTRUEFALSE:
+ return This;
+ case P_TRUE:
+ return P_FALSE;
+ case P_FALSE:
+ return P_TRUE;
+ default:
+ ASSERT(0);
+ }
+}