developing function struct
authorHamed <hamed.gorjiara@gmail.com>
Tue, 20 Jun 2017 01:18:23 +0000 (18:18 -0700)
committerHamed <hamed.gorjiara@gmail.com>
Tue, 20 Jun 2017 01:18:23 +0000 (18:18 -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 d4b693e3fa71980a20a0770d4de381ec4fc0052c..c9d0717d0212a1060b92233d9a015b79ba47375c 100644 (file)
@@ -1 +1,33 @@
 #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;
+}
+
+void deleteFunction(Function* This){
+    switch( GETFUNCTIONTYPE(This)){
+       case TABLEFUNC:
+           ourfree((FunctionTable*)This);
+           break;
+       case OPERATORFUNC:
+           ourfree((FunctionOperator*) This);
+           break;
+       default:
+           ASSERT(0);
+    }
+}
index 459f0b55d3b3c8ee1c2195b7ef173f048d27cac0..e22ec7524bcb9194418082da8d7f25e4b940141d 100644 (file)
@@ -4,11 +4,29 @@
 #include "mymemory.h"
 #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 35418088be0ff31e624a3f72fbcf2acf650a42f4..63da8850249327fbb6fc89bc252a0980d4b52a95 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 c18e039f11347eb38a617b4c72e6d0ddae30d443..1d7b1cfd5db3912c1dc1888bcf17b993b6ce957a 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 727098b6053373ec78d87a058c885ed4b2eadf3f..0a589a59e20330aaa4f3263b316b3c947a29ccad 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 09adb1b07b1f2ec769479dd4bc8716f09b4a4abf..d2a572dbf70ed472aea307820c69573d61e713c5 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 5d23764847a39361833e6126eb3e69251ff108ca..513e3869d5000681826a0e90e0d2fdef951e2d4f 100644 (file)
@@ -12,4 +12,5 @@ struct Predicate {
 
 
 Predicate* allocPredicate(CompOp op, Set ** domain, uint numDomain);
+void deletePredicate(Predicate* predicate);
 #endif
index 9798d13562aa05f3a922629ee3c88871b94e886c..1f95f43c1d4b61d23a32f67ba4f9f6b220f3337b 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 8027f88046199120915df5c2ab8f43e8e58f4d34..21e3223bed689c99c53bca19a65a2c88f1c1ce05 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 216a2b5a799ef9536db431231722013296f164b4..b99d183c9878b3b8184e34f467f3d758300e9543 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 f81932cc46867d366ddc9c6c1abde611b9aab496..44ec39ba826f473b9f6d1fb1ce2bb6fe236fd91f 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 3e08e976a65b4b55367c0362298d5aebc916f096..bd473d530894189c7667c4b48fb90b92b414b29d 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 282912d2d09e6df861fbea1e5468921babcfd589..4520fa0921d96f2e58b3aa7c76fe9a424890928c 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 ec3be7d731d589d33771269e83559d3cf58730ca..58f63ac50032cc1335a1fb3e51bfd3a8b7707993 100644 (file)
@@ -3,7 +3,7 @@
 #include "element.h"
 #include "set.h"
 #include "common.h"
-#include "struct.h"
+#include "structs.h"
 
 void baseBinaryIndexElementAssign(ElementEncoding *This) {
        Element * element=This->element;
index d232592fef332c3d58cbe6670569f3e03ce0cfe0..6de8bcf372c7bff7583bd22f226fe47b56c03d4e 100644 (file)
@@ -41,6 +41,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 7179222096c54ab17af4cb31b5f2ec50e74659b8..62f4acdeaf472e3bc6b274698fba7d0c6bfeba1b 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));
+       }
+       deleteVectorOrder(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 d2e715c06f793e18a10b5181df19c15b92b8b18e..93f19a47a5db5b3127e97399c7b563ab1a977c33 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. */