1 #include "polarityassignment.h"
4 void computePolarities(CSolver *This) {
5 SetIteratorBooleanEdge *iterator = This->getConstraints();
6 while (iterator->hasNext()) {
7 BooleanEdge boolean = iterator->next();
8 Boolean *b = boolean.getBoolean();
9 bool isNegated = boolean.isNegated();
10 computePolarity(b, isNegated ? P_FALSE : P_TRUE);
15 void updateEdgePolarity(BooleanEdge dst, BooleanEdge src) {
16 Boolean *bdst = dst.getBoolean();
17 Boolean *bsrc = src.getBoolean();
18 bool isNegated = dst.isNegated() ^ src.isNegated();
19 Polarity p = isNegated ? negatePolarity(bsrc->polarity) : bsrc->polarity;
20 updatePolarity(bdst, p);
23 void updateEdgePolarity(BooleanEdge dst, Polarity p) {
24 Boolean *bdst = dst.getBoolean();
25 bool isNegated = dst.isNegated();
27 p = negatePolarity(p);
28 updatePolarity(bdst, p);
31 bool updatePolarity(Boolean *This, Polarity polarity) {
32 Polarity oldpolarity = This->polarity;
33 Polarity newpolarity = (Polarity) (This->polarity | polarity);
34 This->polarity = newpolarity;
35 return newpolarity != oldpolarity;
38 void updateMustValue(Boolean *This, BooleanValue value) {
39 This->boolVal = (BooleanValue) (This->boolVal | value);
42 void computePolarity(Boolean *This, Polarity polarity) {
43 if (updatePolarity(This, polarity)) {
50 return computePredicatePolarity((BooleanPredicate *)This);
52 return computeLogicOpPolarity((BooleanLogic *)This);
59 void computePredicatePolarity(BooleanPredicate *This) {
60 if (This->undefStatus) {
61 computePolarity(This->undefStatus.getBoolean(), P_BOTHTRUEFALSE);
63 for (uint i = 0; i < This->inputs.getSize(); i++) {
64 Element *e = This->inputs.get(i);
69 void computeElement(Element *e) {
70 if (e->type == ELEMFUNCRETURN) {
71 ElementFunction *ef = (ElementFunction *) e;
73 if (ef->overflowstatus) {
74 computePolarity(ef->overflowstatus.getBoolean(), P_BOTHTRUEFALSE);
77 for (uint i = 0; i < ef->inputs.getSize(); i++) {
78 Element *echild = ef->inputs.get(i);
79 computeElement(echild);
84 void computeLogicOpPolarity(BooleanLogic *This) {
85 Polarity child = computeLogicOpPolarityChildren(This);
86 uint size = This->inputs.getSize();
87 for (uint i = 0; i < size; i++) {
88 BooleanEdge b = This->inputs.get(i);
89 computePolarity(b.getBoolean(), b.isNegated() ? negatePolarity(child) : child);
93 BooleanValue negateBooleanValue(BooleanValue This) {
99 return BV_MUSTBEFALSE;
101 return BV_MUSTBETRUE;
107 Polarity computeLogicOpPolarityChildren(BooleanLogic *This) {
110 return This->polarity;
113 return P_BOTHTRUEFALSE;
120 Polarity negatePolarity(Polarity This) {
123 case P_BOTHTRUEFALSE: