From: bdemsky Date: Tue, 29 Aug 2017 00:00:46 +0000 (-0700) Subject: Get rid of silly macros X-Git-Url: http://plrg.eecs.uci.edu/git/?p=satune.git;a=commitdiff_plain;h=b03787cd7584eea5b44ae5303576295e52b01289 Get rid of silly macros --- diff --git a/src/AST/boolean.cc b/src/AST/boolean.cc index db79c25..6f2f475 100644 --- a/src/AST/boolean.cc +++ b/src/AST/boolean.cc @@ -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); } } diff --git a/src/AST/boolean.h b/src/AST/boolean.h index fb81e2f..755969f 100644 --- a/src/AST/boolean.h +++ b/src/AST/boolean.h @@ -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); diff --git a/src/AST/element.cc b/src/AST/element.cc index 20cddf3..e47d195 100644 --- a/src/AST/element.cc +++ b/src/AST/element.cc @@ -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: diff --git a/src/AST/element.h b/src/AST/element.h index d0cec9f..9f772ad 100644 --- a/src/AST/element.h +++ b/src/AST/element.h @@ -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); diff --git a/src/AST/function.h b/src/AST/function.h index 0ed79ce..1ade136 100644 --- a/src/AST/function.h +++ b/src/AST/function.h @@ -5,8 +5,6 @@ #include "ops.h" #include "structs.h" -#define GETFUNCTIONTYPE(o) (((Function *)o)->type) - class Function { public: Function(FunctionType _type) : type(_type) {} diff --git a/src/AST/predicate.h b/src/AST/predicate.h index 85ca7f1..dc5128b 100644 --- a/src/AST/predicate.h +++ b/src/AST/predicate.h @@ -6,8 +6,6 @@ #include "structs.h" #include "common.h" -#define GETPREDICATETYPE(o) (((Predicate *)(o))->type) - class Predicate { public: Predicate(PredicateType _type) : type(_type) {} diff --git a/src/ASTAnalyses/polarityassignment.cc b/src/ASTAnalyses/polarityassignment.cc index 705f5d9..ea60ca8 100644 --- a/src/ASTAnalyses/polarityassignment.cc +++ b/src/ASTAnalyses/polarityassignment.cc @@ -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) { diff --git a/src/Backend/satelemencoder.cc b/src/Backend/satelemencoder.cc index 2cb423d..ed761e3 100644 --- a/src/Backend/satelemencoder.cc +++ b/src/Backend/satelemencoder.cc @@ -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) { diff --git a/src/Backend/satencoder.cc b/src/Backend/satencoder.cc index b1eeb50..0bd3383 100644 --- a/src/Backend/satencoder.cc +++ b/src/Backend/satencoder.cc @@ -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; diff --git a/src/Backend/satfunctableencoder.cc b/src/Backend/satfunctableencoder.cc index fcb53aa..633d716 100644 --- a/src/Backend/satfunctableencoder.cc +++ b/src/Backend/satfunctableencoder.cc @@ -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 *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 *elements = &elemFunc->inputs; for (uint i = 0; i < elements->getSize(); i++) { diff --git a/src/Encoders/naiveencoder.cc b/src/Encoders/naiveencoder.cc index efcb92f..ef677ad 100644 --- a/src/Encoders/naiveencoder.cc +++ b/src/Encoders/naiveencoder.cc @@ -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); diff --git a/src/csolver.cc b/src/csolver.cc index 521848a..3131f3a 100644 --- a/src/csolver.cc +++ b/src/csolver.cc @@ -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: