Get rid of silly macros
authorbdemsky <bdemsky@uci.edu>
Tue, 29 Aug 2017 00:00:46 +0000 (17:00 -0700)
committerbdemsky <bdemsky@uci.edu>
Tue, 29 Aug 2017 00:00:46 +0000 (17:00 -0700)
12 files changed:
src/AST/boolean.cc
src/AST/boolean.h
src/AST/element.cc
src/AST/element.h
src/AST/function.h
src/AST/predicate.h
src/ASTAnalyses/polarityassignment.cc
src/Backend/satelemencoder.cc
src/Backend/satencoder.cc
src/Backend/satfunctableencoder.cc
src/Encoders/naiveencoder.cc
src/csolver.cc

index db79c255247c3371b9c0c1b68b607b0f02014d42..6f2f4753bf2009bee5b31c6564710704750bdd7d 100644 (file)
@@ -33,7 +33,7 @@ BooleanPredicate::BooleanPredicate(Predicate *_predicate, Element **_inputs, uin
        inputs(_inputs, _numInputs),
        undefStatus(_undefinedStatus) {
        for (uint i = 0; i < _numInputs; i++) {
-               GETELEMENTPARENTS(_inputs[i])->push(this);
+               _inputs[i]->parents.push(this);
        }
 }
 
index fb81e2f91c7c9e369cb718de26204fd448861cea..755969f21608e8fcd57dcc74a2dc8aa0f432fc6b 100644 (file)
@@ -8,15 +8,6 @@
 #include "functionencoding.h"
 #include "constraint.h"
 
-/**
-    This is a little sketchy, but apparently legit.
-    https://www.python.org/dev/peps/pep-3123/ */
-
-#define GETBOOLEANTYPE(o) (o->type)
-#define GETBOOLEANPARENTS(o) (&(o->parents))
-#define GETBOOLEANPOLARITY(b) (b->polarity)
-#define GETBOOLEANVALUE(b) (b->boolVal)
-
 class Boolean : public ASTNode {
 public:
        Boolean(ASTNodeType _type);
index 20cddf3073a363579544583e676272431c9cbffc..e47d195eff65058896da811c77e90ef79c713c1f 100644 (file)
@@ -23,7 +23,7 @@ ElementFunction::ElementFunction(Function *_function, Element **array, uint numA
        overflowstatus(_overflowstatus),
        functionencoding(this) {
        for (uint i = 0; i < numArrays; i++)
-               GETELEMENTPARENTS(array[i])->push(this);
+               array[i]->parents.push(this);
 }
 
 ElementConst::ElementConst(uint64_t _value, VarType _type, Set *_set) :
@@ -33,14 +33,14 @@ ElementConst::ElementConst(uint64_t _value, VarType _type, Set *_set) :
 }
 
 Set *getElementSet(Element *This) {
-       switch (GETELEMENTTYPE(This)) {
+       switch (This->type) {
        case ELEMSET:
                return ((ElementSet *)This)->set;
        case ELEMCONST:
                return ((ElementConst *)This)->set;
        case ELEMFUNCRETURN: {
                Function *func = ((ElementFunction *)This)->function;
-               switch (GETFUNCTIONTYPE(func)) {
+               switch (func->type) {
                case TABLEFUNC:
                        return ((FunctionTable *)func)->table->range;
                case OPERATORFUNC:
index d0cec9fbaaa5d262b61c4c419b40b904b61bde7c..9f772adf4d99cfed7e7b697e7200490b3905aec2 100644 (file)
@@ -8,8 +8,6 @@
 #include "elementencoding.h"
 #include "boolean.h"
 
-#define GETELEMENTTYPE(o) (o->type)
-#define GETELEMENTPARENTS(o) (&((Element *)o)->parents)
 class Element : public ASTNode {
 public:
        Element(ASTNodeType type);
index 0ed79cec7a09058f06be76ffd58c9582711df20f..1ade1368c924aab0fe22a69835bf0e71858e1cdc 100644 (file)
@@ -5,8 +5,6 @@
 #include "ops.h"
 #include "structs.h"
 
-#define GETFUNCTIONTYPE(o) (((Function *)o)->type)
-
 class Function {
 public:
        Function(FunctionType _type) : type(_type) {}
index 85ca7f1e798bc528359840d1b6d5e537406c2cbe..dc5128b2ca48a45eb9ccda66566ec50724db4bd5 100644 (file)
@@ -6,8 +6,6 @@
 #include "structs.h"
 #include "common.h"
 
-#define GETPREDICATETYPE(o) (((Predicate *)(o))->type)
-
 class Predicate {
 public:
        Predicate(PredicateType _type) : type(_type) {}
index 705f5d9bc8d44b14a2bc3fe50316461cbbdb56e2..ea60ca873741f79b8e2f9a8b849909e719747e2f 100644 (file)
@@ -21,7 +21,7 @@ void updateMustValue(Boolean *This, BooleanValue value) {
 }
 
 void computePolarityAndBooleanValue(Boolean *This) {
-       switch (GETBOOLEANTYPE(This)) {
+       switch (This->type) {
        case BOOLEANVAR:
        case ORDERCONST:
                return;
@@ -79,7 +79,7 @@ BooleanValue negateBooleanValue(BooleanValue This) {
 }
 
 void computeLogicOpPolarity(BooleanLogic *This) {
-       Polarity parentpolarity = GETBOOLEANPOLARITY(This);
+       Polarity parentpolarity = This->polarity;
        switch (This->op) {
        case L_AND:
        case L_OR: {
@@ -113,7 +113,7 @@ void computeLogicOpPolarity(BooleanLogic *This) {
 }
 
 void computeLogicOpBooleanValue(BooleanLogic *This) {
-       BooleanValue parentbv = GETBOOLEANVALUE(This);
+       BooleanValue parentbv = This->boolVal;
        switch (This->op) {
        case L_AND: {
                if (parentbv == BV_MUSTBETRUE || parentbv == BV_UNSAT) {
index 2cb423db731342199fbd4728049040005a52a7e0..ed761e3b62eabc8a28eb32cc85899bd20db1f1d5 100644 (file)
@@ -27,7 +27,7 @@ Edge SATEncoder::getElementValueConstraint(Element *elem, uint64_t value) {
 }
 
 Edge SATEncoder::getElementValueBinaryIndexConstraint(Element *elem, uint64_t value) {
-       ASTNodeType type = GETELEMENTTYPE(elem);
+       ASTNodeType type = elem->type;
        ASSERT(type == ELEMSET || type == ELEMFUNCRETURN || type == ELEMCONST);
        ElementEncoding *elemEnc = getElementEncoding(elem);
        for (uint i = 0; i < elemEnc->encArraySize; i++) {
@@ -39,7 +39,7 @@ Edge SATEncoder::getElementValueBinaryIndexConstraint(Element *elem, uint64_t va
 }
 
 Edge SATEncoder::getElementValueOneHotConstraint(Element *elem, uint64_t value) {
-       ASTNodeType type = GETELEMENTTYPE(elem);
+       ASTNodeType type = elem->type;
        ASSERT(type == ELEMSET || type == ELEMFUNCRETURN || type == ELEMCONST);
        ElementEncoding *elemEnc = getElementEncoding(elem);
        for (uint i = 0; i < elemEnc->encArraySize; i++) {
@@ -51,7 +51,7 @@ Edge SATEncoder::getElementValueOneHotConstraint(Element *elem, uint64_t value)
 }
 
 Edge SATEncoder::getElementValueUnaryConstraint(Element *elem, uint64_t value) {
-       ASTNodeType type = GETELEMENTTYPE(elem);
+       ASTNodeType type = elem->type;
        ASSERT(type == ELEMSET || type == ELEMFUNCRETURN || type == ELEMCONST);
        ElementEncoding *elemEnc = getElementEncoding(elem);
        for (uint i = 0; i < elemEnc->encArraySize; i++) {
@@ -70,7 +70,7 @@ Edge SATEncoder::getElementValueUnaryConstraint(Element *elem, uint64_t value) {
 }
 
 Edge SATEncoder::getElementValueBinaryValueConstraint(Element *element, uint64_t value) {
-       ASTNodeType type = GETELEMENTTYPE(element);
+       ASTNodeType type = element->type;
        ASSERT(type == ELEMSET || type == ELEMFUNCRETURN);
        ElementEncoding *elemEnc = getElementEncoding(element);
        if (elemEnc->low <= elemEnc->high) {
index b1eeb50a893e2b45d79b1efa4423b872e66d94e9..0bd338320f82bf1eed7bacbac4859d1a3033b630 100644 (file)
@@ -45,7 +45,7 @@ void SATEncoder::encodeAllSATEncoder(CSolver *csolver) {
 }
 
 Edge SATEncoder::encodeConstraintSATEncoder(Boolean *constraint) {
-       switch (GETBOOLEANTYPE(constraint)) {
+       switch (constraint->type) {
        case ORDERCONST:
                return encodeOrderSATEncoder((BooleanOrder *) constraint);
        case BOOLEANVAR:
@@ -55,7 +55,7 @@ Edge SATEncoder::encodeConstraintSATEncoder(Boolean *constraint) {
        case PREDICATEOP:
                return encodePredicateSATEncoder((BooleanPredicate *) constraint);
        default:
-               model_print("Unhandled case in encodeConstraintSATEncoder %u", GETBOOLEANTYPE(constraint));
+               model_print("Unhandled case in encodeConstraintSATEncoder %u", constraint->type);
                exit(-1);
        }
 }
@@ -99,7 +99,7 @@ Edge SATEncoder::encodeLogicSATEncoder(BooleanLogic *constraint) {
 }
 
 Edge SATEncoder::encodePredicateSATEncoder(BooleanPredicate *constraint) {
-       switch (GETPREDICATETYPE(constraint->predicate) ) {
+       switch (constraint->predicate->type) {
        case TABLEPRED:
                return encodeTablePredicateSATEncoder(constraint);
        case OPERATORPRED:
@@ -125,7 +125,7 @@ Edge SATEncoder::encodeTablePredicateSATEncoder(BooleanPredicate *constraint) {
 }
 
 void SATEncoder::encodeElementSATEncoder(Element *element) {
-       switch ( GETELEMENTTYPE(element) ) {
+       switch ( element->type) {
        case ELEMFUNCRETURN:
                generateElementEncoding(element);
                encodeElementFunctionSATEncoder((ElementFunction *) element);
@@ -141,7 +141,7 @@ void SATEncoder::encodeElementSATEncoder(Element *element) {
 }
 
 void SATEncoder::encodeElementFunctionSATEncoder(ElementFunction *function) {
-       switch (GETFUNCTIONTYPE(function->function)) {
+       switch (function->function->type) {
        case TABLEFUNC:
                encodeTableElementFunctionSATEncoder(function);
                break;
index fcb53aaec421ee816e1ae989fa14281f1cc2395b..633d7163e7a0f1bb2dcd21b7d4ac37430f8272fb 100644 (file)
@@ -11,7 +11,7 @@
 #include "common.h"
 
 Edge SATEncoder::encodeEnumEntriesTablePredicateSATEncoder(BooleanPredicate *constraint) {
-       ASSERT(GETPREDICATETYPE(constraint->predicate) == TABLEPRED);
+       ASSERT(constraint->predicate->type == TABLEPRED);
        UndefinedBehavior undefStatus = ((PredicateTable *)constraint->predicate)->undefinedbehavior;
        ASSERT(undefStatus == IGNOREBEHAVIOR || undefStatus == FLAGFORCEUNDEFINED);
        Table *table = ((PredicateTable *)constraint->predicate)->table;
@@ -71,7 +71,7 @@ Edge SATEncoder::encodeEnumTablePredicateSATEncoder(BooleanPredicate *constraint
 #ifdef TRACE_DEBUG
        model_print("Enumeration Table Predicate ...\n");
 #endif
-       ASSERT(GETPREDICATETYPE(constraint->predicate) == TABLEPRED);
+       ASSERT(constraint->predicate->type == TABLEPRED);
        //First encode children
        Array<Element *> *inputs = &constraint->inputs;
        uint inputNum = inputs->getSize();
@@ -220,7 +220,7 @@ void SATEncoder::encodeEnumTableElemFunctionSATEncoder(ElementFunction *elemFunc
 #ifdef TRACE_DEBUG
        model_print("Enumeration Table functions ...\n");
 #endif
-       ASSERT(GETFUNCTIONTYPE(elemFunc->function) == TABLEFUNC);
+       ASSERT(elemFunc->function->type == TABLEFUNC);
        //First encode children
        Array<Element *> *elements = &elemFunc->inputs;
        for (uint i = 0; i < elements->getSize(); i++) {
index efcb92f4b67f93ff5490aa7e0f61cc1b1d57a8c6..ef677adf77671389a279bc736537f195a83cd36e 100644 (file)
@@ -23,7 +23,7 @@ void naiveEncodingDecision(CSolver *This) {
 }
 
 void naiveEncodingConstraint(Boolean *This) {
-       switch (GETBOOLEANTYPE(This)) {
+       switch (This->type) {
        case BOOLEANVAR: {
                return;
        }
@@ -68,7 +68,7 @@ void naiveEncodingElement(Element *This) {
                encoding->encodingArrayInitialization();
        }
 
-       if (GETELEMENTTYPE(This) == ELEMFUNCRETURN) {
+       if (This->type == ELEMFUNCRETURN) {
                ElementFunction *function = (ElementFunction *) This;
                for (uint i = 0; i < function->inputs.getSize(); i++) {
                        Element *element = function->inputs.get(i);
index 521848a2a46e9833b96c74fb61ee78be778c4dbf..3131f3a1d1677e743a0760dccda9b3e65e2e5289 100644 (file)
@@ -223,7 +223,7 @@ int CSolver::startEncoding() {
 }
 
 uint64_t CSolver::getElementValue(Element *element) {
-       switch (GETELEMENTTYPE(element)) {
+       switch (element->type) {
        case ELEMSET:
        case ELEMCONST:
        case ELEMFUNCRETURN:
@@ -235,7 +235,7 @@ uint64_t CSolver::getElementValue(Element *element) {
 }
 
 bool CSolver::getBooleanValue(Boolean *boolean) {
-       switch (GETBOOLEANTYPE(boolean)) {
+       switch (boolean->type) {
        case BOOLEANVAR:
                return getBooleanVariableValueSATTranslator(this, boolean);
        default: