#include "function.h"
+#include "table.h"
+#include "set.h"
+
+
+Function* allocFunctionOperator( ArithOp op, Set ** domain, uint numDomain, Set * range,OverFlowBehavior overflowbehavior){
+ FunctionOperator* This = (FunctionOperator*) ourmalloc(sizeof(FunctionOperator));
+ GETFUNCTIONTYPE(This)=OPERATORFUNC;
+ This->domains = allocVectorArraySet(numDomain, domain);
+ This->op=op;
+ This->overflowbehavior = overflowbehavior;
+ This->range=range;
+ return &This->base;
+}
+
+Function* allocFunctionTable (Table* table){
+ FunctionTable* This = (FunctionTable*) ourmalloc(sizeof(FunctionTable));
+ GETFUNCTIONTYPE(This)=TABLEFUNC;
+ This->table = table;
+ return &This->base;
+}
+
+void deleteFunction(Function* This){
+ switch(GETFUNCTIONTYPE(This)){
+ case TABLEFUNC:
+ ourfree((FunctionTable*)This);
+ break;
+ case OPERATORFUNC:
+ ourfree((FunctionOperator*) This);
+ break;
+ default:
+ ASSERT(0);
+ }
+}
#include "ops.h"
#include "structs.h"
-struct Function {
- ArithOp op;
- VectorSet* domains;
- Set * range;
- OverFlowBehavior overflowbehavior;
- Table* table;
+#define GETFUNCTIONTYPE(o) (((Function*)o)->type)
+
+struct Function{
+ FunctionType type;
+};
+
+struct FunctionOperator {
+ Function base;
+ ArithOp op;
+ VectorSet* domains;
+ Set * range;
+ OverFlowBehavior overflowbehavior;
};
+
+struct FunctionTable{
+ Function base;
+ Table* table;
+};
+
+Function* allocFunctionOperator( ArithOp op, Set ** domain, uint numDomain, Set * range,OverFlowBehavior overflowbehavior);
+Function* allocFunctionTable (Table* table);
+void deleteFunction(Function* This);
+
#endif
enum BooleanType {ORDERCONST, BOOLEANVAR, LOGICOP, COMPARE};
typedef enum BooleanType BooleanType;
+
+enum FunctionType {TABLEFUNC, OPERATORFUNC};
+typedef enum FunctionType FunctionType;
#endif
#include "order.h"
#include "structs.h"
#include "set.h"
+#include "boolean.h"
Order* allocOrder(OrderType type, Set * set){
ASSERT(exist1 && exist2);
*/
}
+
+void deleteOrder(Order* order){
+ uint size = getSizeVectorBoolean( order->constraints );
+ for(uint i=0; i<size; i++){
+ deleteBoolean( getVectorBoolean(order->constraints, i) );
+ }
+ deleteSet( order->set);
+ ourfree(order);
+}
\ No newline at end of file
Order* allocOrder(OrderType type, Set * set);
Boolean* getOrderConstraint(Order* order,uint64_t first, uint64_t second);
+void deleteOrder(Order* order);
+
#endif
predicate->op=op;
return predicate;
}
+
+void deletePredicate(Predicate* predicate){
+ deleteVectorSet(predicate->domains);
+ ourfree(predicate);
+}
+
Predicate* allocPredicate(CompOp op, Set ** domain, uint numDomain);
+void deletePredicate(Predicate* predicate);
#endif
#include "common.h"
#include "structs.h"
#include "tableentry.h"
+#include "set.h"
Table * allocTable(Set **domains, uint numDomain, Set * range){
pushVectorTableEntry(table->entries, allocTableEntry(inputs, inputSize, result));
}
+void deleteTable(Table* table){
+ uint size = getSizeVectorSet(table->domains);
+ for(uint i=0; i<size; i++){
+ deleteSet(getVectorSet(table->domains,i));
+ }
+ ourfree(table->domains);
+ ourfree(table->range);
+ size = getSizeVectorTableEntry(table->entries);
+ for(uint i=0; i<size; i++){
+ deleteTableEntry(getVectorTableEntry(table->entries, i));
+ }
+ ourfree(table);
+}
+
Table * allocTable(Set **domains, uint numDomain, Set * range);
void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t result);
-
+void deleteTable(Table* table);
#endif
te->inputs[i]=inputs[i];
}
return te;
+}
+
+void deleteTableEntry(TableEntry* tableEntry){
+ ourfree(tableEntry);
}
\ No newline at end of file
};
TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result);
+void deleteTableEntry(TableEntry* tableEntry);
#endif /* TABLEENTRY_H */
VectorDef(TableEntry, TableEntry *, 4);
VectorDef(Predicate, Predicate *, 4);
VectorDef(Table, Table *, 4);
+VectorDef(Order, Order *, 4);
+VectorDef(Function, Function *, 4);
inline unsigned int Ptr_hash_function(void * hash) {
return (unsigned int)((uint64_t)hash >> 4);
return This;
}
-void deleteFunctionEncoding(FunctionEncoding *This) {
- ourfree(This);
+void deleteFunctionEncoding(FunctionEncoding *fe) {
+ ourfree(fe);
}
#include "element.h"
#include "set.h"
#include "common.h"
-#include "struct.h"
+#include "structs.h"
#include <strings.h>
void baseBinaryIndexElementAssign(ElementEncoding *This) {
struct Element;
typedef struct Element Element;
+typedef struct FunctionOperator FunctionOperator;
+typedef struct FunctionTable FunctionTable;
+
struct Function;
typedef struct Function Function;
#include "predicate.h"
#include "order.h"
#include "table.h"
+#include "function.h"
CSolver * allocCSolver() {
CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver));
tmp->allElements=allocDefVectorElement();
tmp->allPredicates = allocDefVectorPredicate();
tmp->allTables = allocDefVectorTable();
+ tmp->allOrders = allocDefVectorOrder();
+ tmp->allFunctions = allocDefVectorFunction();
return tmp;
}
for(uint i=0;i<size;i++) {
deleteElement(getVectorElement(This->allElements, i));
}
- //FIXME: Freeing alltables and allpredicates
- deleteVectorElement(This->allElements);
+ size=getSizeVectorTable(This->allTables);
+ for(uint i=0;i<size;i++) {
+ deleteTable(getVectorTable(This->allTables, i));
+ }
+ size=getSizeVectorPredicate(This->allPredicates);
+ for(uint i=0;i<size;i++) {
+ deletePredicate(getVectorPredicate(This->allPredicates, i));
+ }
+ size=getSizeVectorOrder(This->allOrders);
+ for(uint i=0;i<size;i++) {
+ deleteOrder(getVectorOrder(This->allOrders, i));
+ }
+ deleteVectorOrder(This->allOrders);
+ size=getSizeVectorFunction(This->allFunctions);
+ for(uint i=0;i<size;i++) {
+ deleteFunction(getVectorFunction(This->allFunctions, i));
+ }
+ deleteVectorFunction(This->allFunctions);
ourfree(This);
}
return boolean;
}
-Function * createFunctionOperator(CSolver *solver, ArithOp op, Set ** domain, uint numDomain, Set * range,
- OverFlowBehavior overflowbehavior) {
- return NULL;
+Function * createFunctionOperator(CSolver *solver, ArithOp op, Set ** domain, uint numDomain, Set * range,OverFlowBehavior overflowbehavior) {
+ Function* function = allocFunctionOperator(op, domain, numDomain, range, overflowbehavior);
+ pushVectorFunction(solver->allFunctions, function);
+ return function;
}
Predicate * createPredicateOperator(CSolver *solver, CompOp op, Set ** domain, uint numDomain) {
}
Function * completeTable(CSolver *solver, Table * table) {
- return NULL;
+ Function* function = allocFunctionTable(table);
+ pushVectorFunction(solver->allFunctions,function);
+ return function;
}
-Element * applyFunction(CSolver *solver, Function * function, Element ** array, Boolean * overflowstatus) {
+Element * applyFunction(CSolver *solver, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus) {
return NULL;
}
-Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs) {
+Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs, uint numInputs) {
return NULL;
}
}
Order * createOrder(CSolver *solver, OrderType type, Set * set) {
- return allocOrder(type, set);
+ Order* order = allocOrder(type, set);
+ pushVectorOrder(solver->allOrders, order);
+ return order;
}
Boolean * orderConstraint(CSolver *solver, Order * order, uint64_t first, uint64_t second) {
/** This is a vector of all element structs that we have allocated. */
VectorElement * allElements;
+
+ /** This is a vector of all predicate structs that we have allocated. */
VectorPredicate * allPredicates;
+
+ /** This is a vector of all table structs that we have allocated. */
VectorTable * allTables;
+
+ /** This is a vector of all order structs that we have allocated. */
+ VectorOrder * allOrders;
+
+ /** This is a vector of all function structs that we have allocated. */
+ VectorFunction* allFunctions;
};
/** Create a new solver instance. */
/** This function applies a function to the Elements in its input. */
-Element * applyFunction(CSolver *, Function * function, Element ** array, Boolean * overflowstatus);
+Element * applyFunction(CSolver *, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus);
/** This function applies a predicate to the Elements in its input. */
-Boolean * applyPredicate(CSolver *, Predicate * predicate, Element ** inputs);
+Boolean * applyPredicate(CSolver *, Predicate * predicate, Element ** inputs, uint numInputs);
/** This function applies a logical operation to the Booleans in its input. */