edits
authorBrian Demsky <bdemsky@uci.edu>
Fri, 25 Aug 2017 00:46:12 +0000 (17:46 -0700)
committerbdemsky <bdemsky@uci.edu>
Fri, 25 Aug 2017 00:46:23 +0000 (17:46 -0700)
src/AST/astnode.h
src/AST/boolean.cc
src/AST/boolean.h
src/AST/element.cc
src/AST/element.h
src/Backend/satfuncopencoder.cc
src/classlist.h
src/csolver.cc

index 9aaee86c3f680ca872700b664f0ef88dd48d247f..8cc126ab031c7aeb1fec0a869cf49127fe565635 100644 (file)
@@ -3,9 +3,11 @@
 #include "classlist.h"
 #include "ops.h"
 
 #include "classlist.h"
 #include "ops.h"
 
-struct ASTNode {
+class ASTNode {
+ public:
+  ASTNode(ASTNodeType _type) : type(_type) {}
        ASTNodeType type;
        ASTNodeType type;
+       MEMALLOC;
 };
 
 };
 
-#define GETASTNODETYPE(o) (((ASTNode *) o)->type)
 #endif
 #endif
index 256ab5af2b453e4b26d57a5e45d2ee561df779bf..b349c9a5468a67f35c20335a5a585516ce5fe779 100644 (file)
@@ -4,75 +4,40 @@
 #include "element.h"
 #include "order.h"
 
 #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);
 }
 }
index cdc05a6be55487fd5fcc5db483be2067fc920562..db1bd7df788be614f8292e93874ba952b0b23a48 100644 (file)
     This is a little sketchy, but apparently legit.
     https://www.python.org/dev/peps/pep-3123/ */
 
     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;
        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;
        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;
        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);
 Boolean *allocBooleanVar(VarType t);
 Boolean *allocBooleanOrder(Order *order, uint64_t first, uint64_t second);
 Boolean *allocBooleanPredicate(Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus);
index 91551e5fc2fa65b667b6b7f5071964ab9da3b5e6..3b0f6e40464a271415836cc3d5f5e9bac298b9d8 100644 (file)
@@ -5,39 +5,24 @@
 #include "function.h"
 #include "table.h"
 
 #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++)
        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};
        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) {
 }
 
 Set *getElementSet(Element *This) {
@@ -64,29 +49,16 @@ Set *getElementSet(Element *This) {
        return NULL;
 }
 
        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));
 }
 }
index 8640a47bec2b36c7a1cd6730162ebbeeec2119fd..df3cf62a0edd415658445714e962af2ad07fb9bd 100644 (file)
@@ -8,53 +8,48 @@
 #include "elementencoding.h"
 #include "boolean.h"
 
 #include "elementencoding.h"
 #include "boolean.h"
 
-#define GETELEMENTTYPE(o) GETASTNODETYPE(o)
+#define GETELEMENTTYPE(o) (o->type)
 #define GETELEMENTPARENTS(o) (&((Element *)o)->parents)
 #define GETELEMENTPARENTS(o) (&((Element *)o)->parents)
-struct Element {
-       ASTNode base;
+class Element : public ASTNode {
+ public:
+       Element(ASTNodeType type);
+       ~Element();
        VectorASTNode parents;
        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;
        Set *set;
        uint64_t value;
-       ElementEncoding encoding;
+       MEMALLOC;
 };
 
 };
 
-struct ElementSet {
-       Element base;
+class ElementSet : public Element {
+ public:
+       ElementSet(Set *s);
        Set *set;
        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;
        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);
 
 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) {
 }
 
 static inline FunctionEncoding *getElementFunctionEncoding(ElementFunction *func) {
index 8dd753258a0b8a185706eaf2687eb51615336898..8e66c9b16b06ab040abd616f04865c6506f1da25 100644 (file)
@@ -129,7 +129,7 @@ void encodeOperatorElementFunctionSATEncoder(SATEncoder *This, ElementFunction *
                                carray[i] = getElementValueConstraint(This, elem, vals[i]);
                        }
                        if (isInRange) {
                                carray[i] = getElementValueConstraint(This, elem, vals[i]);
                        }
                        if (isInRange) {
-                               carray[numDomains] = getElementValueConstraint(This, &func->base, result);
+                               carray[numDomains] = getElementValueConstraint(This, func, result);
                        }
 
                        Edge clause;
                        }
 
                        Edge clause;
index 7e904e88d638a6b4ef9907e1ea53e18bca34f0d0..8baae7a27304f84a7718d83683505a6a2eae0722 100644 (file)
@@ -21,16 +21,12 @@ typedef struct CSolver CSolver;
 struct SATEncoder;
 typedef struct SATEncoder SATEncoder;
 
 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;
 
 struct IncrementalSolver;
 typedef struct IncrementalSolver IncrementalSolver;
@@ -39,12 +35,10 @@ struct Set;
 typedef struct Set Set;
 typedef struct Set MutableSet;
 
 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;
 
 typedef struct FunctionOperator FunctionOperator;
 typedef struct FunctionTable FunctionTable;
index b4c8208a3738eaa5b28b35424125fb76eff82226..51d8c7fb0c991f0e9e31bddd690be33e91b67119 100644 (file)
@@ -48,7 +48,7 @@ void deleteSolver(CSolver *This) {
 
        size = getSizeVectorElement(This->allElements);
        for (uint i = 0; i < size; i++) {
 
        size = getSizeVectorElement(This->allElements);
        for (uint i = 0; i < size; i++) {
-               deleteElement(getVectorElement(This->allElements, i));
+               delete getVectorElement(This->allElements, i);
        }
        deleteVectorElement(This->allElements);
 
        }
        deleteVectorElement(This->allElements);
 
@@ -109,13 +109,13 @@ uint64_t createUniqueItem(CSolver *This, MutableSet *set) {
 }
 
 Element *getElementVar(CSolver *This, Set *set) {
 }
 
 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) {
        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;
 }
        pushVectorElement(This->allElements, element);
        return element;
 }
@@ -165,7 +165,7 @@ Function *completeTable(CSolver *This, Table *table, UndefinedBehavior behavior)
 }
 
 Element *applyFunction(CSolver *This, Function *function, Element **array, uint numArrays, Boolean *overflowstatus) {
 }
 
 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;
 }
        pushVectorElement(This->allElements, element);
        return element;
 }
@@ -174,13 +174,13 @@ Boolean *applyPredicate(CSolver *This, Predicate *predicate, Element **inputs, u
        return applyPredicateTable(This, predicate, inputs, numInputs, NULL);
 }
 Boolean *applyPredicateTable(CSolver *This, Predicate *predicate, Element **inputs, uint numInputs, Boolean *undefinedStatus) {
        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) {
        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) {
 }
 
 void addConstraint(CSolver *This, Boolean *constraint) {
@@ -194,7 +194,7 @@ Order *createOrder(CSolver *This, OrderType type, Set *set) {
 }
 
 Boolean *orderConstraint(CSolver *This, Order *order, uint64_t first, uint64_t second) {
 }
 
 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;
 }
        pushVectorBoolean(This->allBooleans,constraint);
        return constraint;
 }