3 #include "mutableset.h"
11 CSolver * allocCSolver() {
12 CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver));
13 tmp->constraints=allocDefVectorBoolean();
14 tmp->allBooleans=allocDefVectorBoolean();
15 tmp->allSets=allocDefVectorSet();
16 tmp->allElements=allocDefVectorElement();
17 tmp->allPredicates = allocDefVectorPredicate();
18 tmp->allTables = allocDefVectorTable();
19 tmp->allOrders = allocDefVectorOrder();
20 tmp->allFunctions = allocDefVectorFunction();
24 /** This function tears down the solver and the entire AST */
26 void deleteSolver(CSolver *This) {
27 deleteVectorBoolean(This->constraints);
29 uint size=getSizeVectorBoolean(This->allBooleans);
30 for(uint i=0;i<size;i++) {
31 deleteBoolean(getVectorBoolean(This->allBooleans, i));
33 deleteVectorBoolean(This->allBooleans);
35 size=getSizeVectorSet(This->allSets);
36 for(uint i=0;i<size;i++) {
37 deleteSet(getVectorSet(This->allSets, i));
39 deleteVectorSet(This->allSets);
41 size=getSizeVectorElement(This->allElements);
42 for(uint i=0;i<size;i++) {
43 deleteElement(getVectorElement(This->allElements, i));
45 deleteVectorElement(This->allElements);
47 size=getSizeVectorTable(This->allTables);
48 for(uint i=0;i<size;i++) {
49 deleteTable(getVectorTable(This->allTables, i));
51 deleteVectorTable(This->allTables);
53 size=getSizeVectorPredicate(This->allPredicates);
54 for(uint i=0;i<size;i++) {
55 deletePredicate(getVectorPredicate(This->allPredicates, i));
57 deleteVectorPredicate(This->allPredicates);
59 size=getSizeVectorOrder(This->allOrders);
60 for(uint i=0;i<size;i++) {
61 deleteOrder(getVectorOrder(This->allOrders, i));
63 deleteVectorOrder(This->allOrders);
65 size=getSizeVectorFunction(This->allFunctions);
66 for(uint i=0;i<size;i++) {
67 deleteFunction(getVectorFunction(This->allFunctions, i));
69 deleteVectorFunction(This->allFunctions);
73 Set * createSet(CSolver * This, VarType type, uint64_t * elements, uint numelements) {
74 Set * set=allocSet(type, elements, numelements);
75 pushVectorSet(This->allSets, set);
79 Set * createRangeSet(CSolver * This, VarType type, uint64_t lowrange, uint64_t highrange) {
80 Set * set=allocSetRange(type, lowrange, highrange);
81 pushVectorSet(This->allSets, set);
85 MutableSet * createMutableSet(CSolver * This, VarType type) {
86 MutableSet * set=allocMutableSet(type);
87 pushVectorSet(This->allSets, set);
91 void addItem(CSolver *solver, MutableSet * set, uint64_t element) {
92 addElementMSet(set, element);
95 uint64_t createUniqueItem(CSolver *solver, MutableSet * set) {
96 uint64_t element=set->low++;
97 addElementMSet(set, element);
101 Element * getElementVar(CSolver *This, Set * set) {
102 Element * element=allocElementSet(set);
103 pushVectorElement(This->allElements, element);
107 Boolean * getBooleanVar(CSolver *solver, VarType type) {
108 Boolean* boolean= allocBoolean(type);
109 pushVectorBoolean(solver->allBooleans, boolean);
113 Function * createFunctionOperator(CSolver *solver, ArithOp op, Set ** domain, uint numDomain, Set * range,OverFlowBehavior overflowbehavior) {
114 Function* function = allocFunctionOperator(op, domain, numDomain, range, overflowbehavior);
115 pushVectorFunction(solver->allFunctions, function);
119 Predicate * createPredicateOperator(CSolver *solver, CompOp op, Set ** domain, uint numDomain) {
120 Predicate* predicate= allocPredicate(op, domain,numDomain);
121 pushVectorPredicate(solver->allPredicates, predicate);
125 Table * createTable(CSolver *solver, Set **domains, uint numDomain, Set * range) {
126 Table* table= allocTable(domains,numDomain,range);
127 pushVectorTable(solver->allTables, table);
131 void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSize, uint64_t result) {
132 addNewTableEntry(table,inputs, inputSize,result);
135 Function * completeTable(CSolver *solver, Table * table) {
136 Function* function = allocFunctionTable(table);
137 pushVectorFunction(solver->allFunctions,function);
141 Element * applyFunction(CSolver *solver, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus) {
142 Element* element= allocElementFunction(function,array,numArrays,overflowstatus);
143 ADDNEWPARENTTOOBJECTARRAY(array, numArrays, element);
144 pushVectorElement(solver->allElements, element);
148 Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs, uint numInputs) {
149 Boolean* boolean= allocBooleanPredicate(predicate, inputs, numInputs);
150 ADDNEWPARENTTOOBJECTARRAY(inputs, numInputs, boolean);
151 pushVectorBoolean(solver->allBooleans, boolean);
155 Boolean * applyLogicalOperation(CSolver *solver, LogicOp op, Boolean ** array, uint asize) {
156 return allocBooleanLogicArray(solver, op, array, asize);
159 void addBoolean(CSolver *This, Boolean * constraint) {
160 pushVectorBoolean(This->constraints, constraint);
163 Order * createOrder(CSolver *solver, OrderType type, Set * set) {
164 Order* order = allocOrder(type, set);
165 pushVectorOrder(solver->allOrders, order);
169 Boolean * orderConstraint(CSolver *solver, Order * order, uint64_t first, uint64_t second) {
170 Boolean* constraint = allocBooleanOrder(order, first, second);
171 pushVectorBoolean(solver->allBooleans,constraint);