Fix warnings, merge, and check my code in
authorbdemsky <bdemsky@uci.edu>
Tue, 20 Jun 2017 01:51:52 +0000 (18:51 -0700)
committerbdemsky <bdemsky@uci.edu>
Tue, 20 Jun 2017 01:51:52 +0000 (18:51 -0700)
17 files changed:
src/AST/function.c
src/AST/function.h
src/AST/ops.h
src/AST/order.c
src/AST/order.h
src/AST/predicate.c
src/AST/predicate.h
src/AST/table.c
src/AST/table.h
src/AST/tableentry.c
src/AST/tableentry.h
src/Collections/structs.h
src/Encoders/functionencoding.c
src/Encoders/naiveelementencoder.c
src/classlist.h
src/csolver.c
src/csolver.h

index d4b693e..c816363 100644 (file)
@@ -1 +1,34 @@
 #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);
+       }
+}
index 65a4b29..3f2a1a9 100644 (file)
@@ -5,11 +5,27 @@
 #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
index 3b3e3c3..b330d1b 100644 (file)
@@ -25,4 +25,7 @@ typedef enum OverFlowBehavior OverFlowBehavior;
 
 enum BooleanType {ORDERCONST, BOOLEANVAR, LOGICOP, COMPARE};
 typedef enum BooleanType BooleanType;
+
+enum FunctionType {TABLEFUNC, OPERATORFUNC};
+typedef enum FunctionType FunctionType;
 #endif
index c18e039..1d7b1cf 100644 (file)
@@ -1,6 +1,7 @@
 #include "order.h"
 #include "structs.h"
 #include "set.h"
+#include "boolean.h"
 
 
 Order* allocOrder(OrderType type, Set * set){
@@ -35,3 +36,12 @@ Boolean* getOrderConstraint(Order* order, uint64_t first, uint64_t second){
     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
index 727098b..0a589a5 100644 (file)
@@ -12,4 +12,6 @@ struct Order {
 
 Order* allocOrder(OrderType type, Set * set);
 Boolean* getOrderConstraint(Order* order,uint64_t first, uint64_t second);
+void deleteOrder(Order* order);
+
 #endif
index 09adb1b..d2a572d 100644 (file)
@@ -10,3 +10,9 @@ Predicate* allocPredicate(CompOp op, Set ** domain, uint numDomain){
     predicate->op=op;
     return predicate;
 }
+
+void deletePredicate(Predicate* predicate){
+    deleteVectorSet(predicate->domains);
+    ourfree(predicate);
+}
+
index 5d23764..513e386 100644 (file)
@@ -12,4 +12,5 @@ struct Predicate {
 
 
 Predicate* allocPredicate(CompOp op, Set ** domain, uint numDomain);
+void deletePredicate(Predicate* predicate);
 #endif
index 9798d13..1f95f43 100644 (file)
@@ -2,6 +2,7 @@
 #include "common.h"
 #include "structs.h"
 #include "tableentry.h"
+#include "set.h"
 
 
 Table * allocTable(Set **domains, uint numDomain, Set * range){
@@ -19,3 +20,17 @@ void addNewTableEntry(Table* table, uint64_t* inputs, uint inputSize, uint64_t r
     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);
+}
+
index 8027f88..21e3223 100644 (file)
@@ -12,5 +12,5 @@ struct 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
index 216a2b5..b99d183 100644 (file)
@@ -7,4 +7,8 @@ TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result){
        te->inputs[i]=inputs[i];
     }
     return te;
+}
+
+void deleteTableEntry(TableEntry* tableEntry){
+    ourfree(tableEntry);
 }
\ No newline at end of file
index f81932c..44ec39b 100644 (file)
@@ -22,6 +22,7 @@ struct TableEntry{
 };
 
 TableEntry* allocTableEntry(uint64_t* inputs, uint inputSize, uint64_t result);
+void deleteTableEntry(TableEntry* tableEntry);
 
 #endif /* TABLEENTRY_H */
 
index 3e08e97..bd473d5 100644 (file)
@@ -14,6 +14,8 @@ VectorDef(Element, Element *, 4);
 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);
index c9c0e19..d0f8c3d 100644 (file)
@@ -14,6 +14,6 @@ FunctionEncoding * allocPredicateEncoding(FunctionEncodingType type, Boolean *pr
        return This;
 }
 
-void deleteFunctionEncoding(FunctionEncoding *This) {
-       ourfree(This);
+void deleteFunctionEncoding(FunctionEncoding *fe) {
+       ourfree(fe);
 }
index 4d52235..bb6e91a 100644 (file)
@@ -3,7 +3,7 @@
 #include "element.h"
 #include "set.h"
 #include "common.h"
-#include "struct.h"
+#include "structs.h"
 #include <strings.h>
 
 void baseBinaryIndexElementAssign(ElementEncoding *This) {
index 6335297..237d529 100644 (file)
@@ -43,6 +43,9 @@ typedef struct Set MutableSet;
 struct Element;
 typedef struct Element Element;
 
+typedef struct FunctionOperator FunctionOperator;
+typedef struct FunctionTable FunctionTable;
+
 struct Function;
 typedef struct Function Function;
 
index 7179222..7a9d1e0 100644 (file)
@@ -6,6 +6,7 @@
 #include "predicate.h"
 #include "order.h"
 #include "table.h"
+#include "function.h"
 
 CSolver * allocCSolver() {
        CSolver * tmp=(CSolver *) ourmalloc(sizeof(CSolver));
@@ -15,6 +16,8 @@ CSolver * allocCSolver() {
        tmp->allElements=allocDefVectorElement();
        tmp->allPredicates = allocDefVectorPredicate();
        tmp->allTables = allocDefVectorTable();
+       tmp->allOrders = allocDefVectorOrder();
+       tmp->allFunctions = allocDefVectorFunction();
        return tmp;
 }
 
@@ -41,8 +44,24 @@ void deleteSolver(CSolver *This) {
        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);
 }
 
@@ -86,9 +105,10 @@ Boolean * getBooleanVar(CSolver *solver, VarType type) {
        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) {
@@ -108,14 +128,16 @@ void addTableEntry(CSolver *solver, Table* table, uint64_t* inputs, uint inputSi
 }
 
 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;
 }
 
@@ -128,7 +150,9 @@ void addBoolean(CSolver *This, Boolean * constraint) {
 }
 
 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) {
index d2e715c..93f19a4 100644 (file)
@@ -16,8 +16,18 @@ struct CSolver {
 
        /** 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. */
@@ -77,11 +87,11 @@ Function * completeTable(CSolver *, Table *);
 
 /** 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. */