#include "classlist.h"
#include "ops.h"
-struct ASTNode {
+class ASTNode {
+ public:
+ ASTNode(ASTNodeType _type) : type(_type) {}
ASTNodeType type;
+ MEMALLOC;
};
-#define GETASTNODETYPE(o) (((ASTNode *) o)->type)
#endif
#include "element.h"
#include "order.h"
-Boolean *allocBooleanVar(VarType t) {
- BooleanVar *This = (BooleanVar *) ourmalloc(sizeof (BooleanVar));
- GETBOOLEANTYPE(This) = BOOLEANVAR;
- GETBOOLEANVALUE(This) = BV_UNDEFINED;
- GETBOOLEANPOLARITY(This) = P_UNDEFINED;
- This->vtype = t;
- This->var = E_NULL;
- initDefVectorBoolean(GETBOOLEANPARENTS(This));
- return &This->base;
+Boolean::Boolean(ASTNodeType _type) : ASTNode(_type), polarity(P_UNDEFINED), boolVal(BV_UNDEFINED) {
+ initDefVectorBoolean(GETBOOLEANPARENTS(this));
}
-Boolean *allocBooleanOrder(Order *order, uint64_t first, uint64_t second) {
- BooleanOrder *This = (BooleanOrder *) ourmalloc(sizeof (BooleanOrder));
- GETBOOLEANTYPE(This) = ORDERCONST;
- GETBOOLEANVALUE(This) = BV_UNDEFINED;
- GETBOOLEANPOLARITY(This) = P_UNDEFINED;
- This->order = order;
- This->first = first;
- This->second = second;
- pushVectorBooleanOrder(&order->constraints, This);
- initDefVectorBoolean(GETBOOLEANPARENTS(This));
- return &This->base;
+BooleanVar::BooleanVar(VarType t) : Boolean(BOOLEANVAR), vtype(t), var(E_NULL) {
}
-Boolean *allocBooleanPredicate(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus) {
- BooleanPredicate *This = (BooleanPredicate *) ourmalloc(sizeof(BooleanPredicate));
- GETBOOLEANTYPE(This) = PREDICATEOP;
- GETBOOLEANVALUE(This) = BV_UNDEFINED;
- GETBOOLEANPOLARITY(This) = P_UNDEFINED;
- This->predicate = predicate;
- initArrayInitElement(&This->inputs, inputs, numInputs);
- initDefVectorBoolean(GETBOOLEANPARENTS(This));
+BooleanOrder::BooleanOrder(Order *_order, uint64_t _first, uint64_t _second) : Boolean(ORDERCONST), order(_order), first(_first), second(_second) {
+ pushVectorBooleanOrder(&order->constraints, this);
+}
+
+BooleanPredicate::BooleanPredicate(Predicate *_predicate, Element **_inputs, uint _numInputs, Boolean *_undefinedStatus) : Boolean(PREDICATEOP), predicate(_predicate), undefStatus(_undefinedStatus) {
+ initArrayInitElement(&inputs, _inputs, _numInputs);
- for (uint i = 0; i < numInputs; i++) {
- pushVectorASTNode(GETELEMENTPARENTS(inputs[i]), (ASTNode *)This);
+ for (uint i = 0; i < _numInputs; i++) {
+ pushVectorASTNode(GETELEMENTPARENTS(_inputs[i]), this);
}
- initPredicateEncoding(&This->encoding, (Boolean *) This);
- This->undefStatus = undefinedStatus;
- return &This->base;
+ initPredicateEncoding(&encoding, this);
}
-Boolean *allocBooleanLogicArray(CSolver *solver, LogicOp op, Boolean **array, uint asize) {
- BooleanLogic *This = (BooleanLogic *) ourmalloc(sizeof(BooleanLogic));
- GETBOOLEANTYPE(This) = LOGICOP;
- GETBOOLEANVALUE(This) = BV_UNDEFINED;
- GETBOOLEANPOLARITY(This) = P_UNDEFINED;
- This->op = op;
- initDefVectorBoolean(GETBOOLEANPARENTS(This));
- initArrayInitBoolean(&This->inputs, array, asize);
- pushVectorBoolean(solver->allBooleans, (Boolean *) This);
- return &This->base;
+BooleanLogic::BooleanLogic(CSolver *solver, LogicOp _op, Boolean **array, uint asize) : Boolean(LOGICOP), op(_op) {
+ initArrayInitBoolean(&inputs, array, asize);
+ pushVectorBoolean(solver->allBooleans, (Boolean *) this);
}
-void deleteBoolean(Boolean *This) {
- switch (GETBOOLEANTYPE(This)) {
- case PREDICATEOP: {
- BooleanPredicate *bp = (BooleanPredicate *)This;
- deleteInlineArrayElement(&bp->inputs );
- deleteFunctionEncoding(&bp->encoding);
- break;
- }
- case LOGICOP: {
- BooleanLogic *bl = (BooleanLogic *) This;
- deleteInlineArrayBoolean(&bl->inputs);
- break;
- }
- default:
- break;
- }
- deleteVectorArrayBoolean(GETBOOLEANPARENTS(This));
- ourfree(This);
+Boolean::~Boolean() {
+ deleteVectorArrayBoolean(GETBOOLEANPARENTS(this));
+}
+
+BooleanPredicate::~BooleanPredicate() {
+ deleteInlineArrayElement(&inputs );
+ deleteFunctionEncoding(&encoding);
+}
+
+BooleanLogic::~BooleanLogic() {
+ deleteInlineArrayBoolean(&inputs);
}
This is a little sketchy, but apparently legit.
https://www.python.org/dev/peps/pep-3123/ */
-#define GETBOOLEANTYPE(o) GETASTNODETYPE(o)
-#define GETBOOLEANPARENTS(o) (&((Boolean *)(o))->parents)
-#define GETBOOLEANPOLARITY(b) (((Boolean *)b)->polarity)
-#define GETBOOLEANVALUE(b) (((Boolean *)b)->boolVal)
+#define GETBOOLEANTYPE(o) (o->type)
+#define GETBOOLEANPARENTS(o) (&(o->parents))
+#define GETBOOLEANPOLARITY(b) (b->polarity)
+#define GETBOOLEANVALUE(b) (b->boolVal)
-struct Boolean {
- ASTNode base;
+class Boolean : public ASTNode {
+ public:
+ Boolean(ASTNodeType _type);
Polarity polarity;
BooleanValue boolVal;
VectorBoolean parents;
+ ~Boolean();
+ MEMALLOC;
};
-struct BooleanOrder {
- Boolean base;
- Order *order;
- uint64_t first;
- uint64_t second;
-};
-
-struct BooleanVar {
- Boolean base;
+class BooleanVar : public Boolean {
+ public:
+ BooleanVar(VarType t);
VarType vtype;
Edge var;
+ MEMALLOC;
};
-struct BooleanLogic {
- Boolean base;
- LogicOp op;
- ArrayBoolean inputs;
+class BooleanOrder : public Boolean {
+ public:
+ BooleanOrder(Order *_order, uint64_t _first, uint64_t _second);
+ Order *order;
+ uint64_t first;
+ uint64_t second;
+ MEMALLOC;
};
-struct BooleanPredicate {
- Boolean base;
+class BooleanPredicate : public Boolean {
+ public:
+ BooleanPredicate(Predicate *_predicate, Element **_inputs, uint _numInputs, Boolean *_undefinedStatus);
+ ~BooleanPredicate();
Predicate *predicate;
FunctionEncoding encoding;
ArrayElement inputs;
Boolean *undefStatus;
+ MEMALLOC;
+};
+
+
+class BooleanLogic : public Boolean {
+ public:
+ BooleanLogic(CSolver *solver, LogicOp _op, Boolean **array, uint asize);
+ ~BooleanLogic();
+ LogicOp op;
+ ArrayBoolean inputs;
+ MEMALLOC;
};
+
+
Boolean *allocBooleanVar(VarType t);
Boolean *allocBooleanOrder(Order *order, uint64_t first, uint64_t second);
Boolean *allocBooleanPredicate(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus);
#include "function.h"
#include "table.h"
-Element *allocElementSet(Set *s) {
- ElementSet *This = (ElementSet *)ourmalloc(sizeof(ElementSet));
- GETELEMENTTYPE(This) = ELEMSET;
- This->set = s;
- initDefVectorASTNode(GETELEMENTPARENTS(This));
- initElementEncoding(&This->encoding, (Element *) This);
- return &This->base;
+Element::Element(ASTNodeType _type) : ASTNode(_type) {
+ initDefVectorASTNode(GETELEMENTPARENTS(this));
+ initElementEncoding(&encoding, (Element *) this);
}
-Element *allocElementFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus) {
- ElementFunction *This = (ElementFunction *) ourmalloc(sizeof(ElementFunction));
- GETELEMENTTYPE(This) = ELEMFUNCRETURN;
- This->function = function;
- ASSERT(GETBOOLEANTYPE(overflowstatus) == BOOLEANVAR);
- This->overflowstatus = overflowstatus;
- initArrayInitElement(&This->inputs, array, numArrays);
- initDefVectorASTNode(GETELEMENTPARENTS(This));
+ElementSet::ElementSet(Set *s) : Element(ELEMSET), set(s) {
+}
+
+ElementFunction::ElementFunction(Function *_function, Element **array, uint numArrays, Boolean *_overflowstatus) : Element(ELEMFUNCRETURN), function(_function), overflowstatus(_overflowstatus) {
+ initArrayInitElement(&inputs, array, numArrays);
for (uint i = 0; i < numArrays; i++)
- pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) This);
- initElementEncoding(&This->rangeencoding, (Element *) This);
- initFunctionEncoding(&This->functionencoding, (Element *) This);
- return &This->base;
+ pushVectorASTNode(GETELEMENTPARENTS(array[i]), this);
+ initFunctionEncoding(&functionencoding, this);
}
-Element *allocElementConst(uint64_t value, VarType type) {
- ElementConst *This = (ElementConst *)ourmalloc(sizeof(ElementConst));
- GETELEMENTTYPE(This) = ELEMCONST;
- This->value = value;
+ElementConst::ElementConst(uint64_t _value, VarType _type) : Element(ELEMCONST), value(_value) {
uint64_t array[]={value};
- This->set = allocSet(type, array, 1);
- initDefVectorASTNode(GETELEMENTPARENTS(This));
- initElementEncoding(&This->encoding, (Element *) This);
- return &This->base;
+ set = allocSet(_type, array, 1);
}
Set *getElementSet(Element *This) {
return NULL;
}
-void deleteElement(Element *This) {
- switch (GETELEMENTTYPE(This)) {
- case ELEMFUNCRETURN: {
- ElementFunction *ef = (ElementFunction *) This;
- deleteInlineArrayElement(&ef->inputs);
- deleteElementEncoding(&ef->rangeencoding);
- deleteFunctionEncoding(&ef->functionencoding);
- break;
- }
- case ELEMSET: {
- ElementSet *es = (ElementSet *) This;
- deleteElementEncoding(&es->encoding);
- break;
- }
- case ELEMCONST: {
- ElementConst *ec = (ElementConst *) This;
- deleteSet(ec->set);//Client did not create, so we free it
- deleteElementEncoding(&ec->encoding);
- break;
- }
- default:
- ASSERT(0);
- }
- deleteVectorArrayASTNode(GETELEMENTPARENTS(This));
- ourfree(This);
+ElementFunction::~ElementFunction() {
+ deleteInlineArrayElement(&inputs);
+ deleteFunctionEncoding(&functionencoding);
+}
+
+ElementConst::~ElementConst() {
+ deleteSet(set);
+}
+
+Element::~Element() {
+ deleteElementEncoding(&encoding);
+ deleteVectorArrayASTNode(GETELEMENTPARENTS(this));
}
#include "elementencoding.h"
#include "boolean.h"
-#define GETELEMENTTYPE(o) GETASTNODETYPE(o)
+#define GETELEMENTTYPE(o) (o->type)
#define GETELEMENTPARENTS(o) (&((Element *)o)->parents)
-struct Element {
- ASTNode base;
+class Element : public ASTNode {
+ public:
+ Element(ASTNodeType type);
+ ~Element();
VectorASTNode parents;
+ ElementEncoding encoding;
+ MEMALLOC;
};
-struct ElementConst {
- Element base;
+class ElementConst : public Element {
+ public:
+ ElementConst(uint64_t value, VarType type);
+ ~ElementConst();
Set *set;
uint64_t value;
- ElementEncoding encoding;
+ MEMALLOC;
};
-struct ElementSet {
- Element base;
+class ElementSet : public Element {
+ public:
+ ElementSet(Set *s);
Set *set;
- ElementEncoding encoding;
+ MEMALLOC;
};
-struct ElementFunction {
- Element base;
+class ElementFunction : public Element {
+ public:
+ ElementFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus);
+ ~ElementFunction();
Function *function;
ArrayElement inputs;
Boolean *overflowstatus;
FunctionEncoding functionencoding;
- ElementEncoding rangeencoding;
+ MEMALLOC;
};
-Element *allocElementConst(uint64_t value, VarType type);
-Element *allocElementSet(Set *s);
-Element *allocElementFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus);
-void deleteElement(Element *This);
Set *getElementSet(Element *This);
-static inline ElementEncoding *getElementEncoding(Element *This) {
- switch (GETELEMENTTYPE(This)) {
- case ELEMSET:
- return &((ElementSet *)This)->encoding;
- case ELEMFUNCRETURN:
- return &((ElementFunction *)This)->rangeencoding;
- case ELEMCONST:
- return &((ElementConst *)This)->encoding;
- default:
- ASSERT(0);
- }
- return NULL;
+static inline ElementEncoding *getElementEncoding(Element *e) {
+ return &e->encoding;
}
static inline FunctionEncoding *getElementFunctionEncoding(ElementFunction *func) {
carray[i] = getElementValueConstraint(This, elem, vals[i]);
}
if (isInRange) {
- carray[numDomains] = getElementValueConstraint(This, &func->base, result);
+ carray[numDomains] = getElementValueConstraint(This, func, result);
}
Edge clause;
struct SATEncoder;
typedef struct SATEncoder SATEncoder;
-typedef struct BooleanOrder BooleanOrder;
-typedef struct BooleanVar BooleanVar;
-typedef struct BooleanLogic BooleanLogic;
-typedef struct BooleanPredicate BooleanPredicate;
-
-struct ASTNode;
-typedef struct ASTNode ASTNode;
-
-struct Boolean;
-typedef struct Boolean Boolean;
+class Boolean;
+class BooleanOrder;
+class BooleanVar;
+class BooleanLogic;
+class BooleanPredicate;
+class ASTNode;
struct IncrementalSolver;
typedef struct IncrementalSolver IncrementalSolver;
typedef struct Set Set;
typedef struct Set MutableSet;
-typedef struct ElementFunction ElementFunction;
-typedef struct ElementSet ElementSet;
-typedef struct ElementConst ElementConst;
-
-struct Element;
-typedef struct Element Element;
+class ElementFunction;
+class ElementSet;
+class ElementConst;
+class Element;
typedef struct FunctionOperator FunctionOperator;
typedef struct FunctionTable FunctionTable;
size = getSizeVectorElement(This->allElements);
for (uint i = 0; i < size; i++) {
- deleteElement(getVectorElement(This->allElements, i));
+ delete getVectorElement(This->allElements, i);
}
deleteVectorElement(This->allElements);
}
Element *getElementVar(CSolver *This, Set *set) {
- Element *element = allocElementSet(set);
+ Element *element = new ElementSet(set);
pushVectorElement(This->allElements, element);
return element;
}
Element *getElementConst(CSolver *This, VarType type, uint64_t value) {
- Element *element = allocElementConst(value, type);
+ Element *element = new ElementConst(value, type);
pushVectorElement(This->allElements, element);
return element;
}
}
Element *applyFunction(CSolver *This, Function *function, Element **array, uint numArrays, Boolean *overflowstatus) {
- Element *element = allocElementFunction(function,array,numArrays,overflowstatus);
+ Element *element = new ElementFunction(function,array,numArrays,overflowstatus);
pushVectorElement(This->allElements, element);
return element;
}
return applyPredicateTable(This, predicate, inputs, numInputs, NULL);
}
Boolean *applyPredicateTable(CSolver *This, Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus) {
- Boolean *boolean = allocBooleanPredicate(predicate, inputs, numInputs, undefinedStatus);
+ Boolean *boolean = new BooleanPredicate(predicate, inputs, numInputs, undefinedStatus);
pushVectorBoolean(This->allBooleans, boolean);
return boolean;
}
Boolean *applyLogicalOperation(CSolver *This, LogicOp op, Boolean **array, uint asize) {
- return allocBooleanLogicArray(This, op, array, asize);
+ return new BooleanLogic(This, op, array, asize);
}
void addConstraint(CSolver *This, Boolean *constraint) {
}
Boolean *orderConstraint(CSolver *This, Order *order, uint64_t first, uint64_t second) {
- Boolean *constraint = allocBooleanOrder(order, first, second);
+ Boolean *constraint = new BooleanOrder(order, first, second);
pushVectorBoolean(This->allBooleans,constraint);
return constraint;
}