removing true nodes from the OrderGraph
[satune.git] / src / AST / function.c
index d4b693e3fa71980a20a0770d4de381ec4fc0052c..3a32139a03f1edb5acc1ab8fd8e4252968291d7f 100644 (file)
@@ -1 +1,53 @@
 #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;
+       initArrayInitSet(&This->domains, domain, numDomain);
+       This->op = op;
+       This->overflowbehavior = overflowbehavior;
+       This->range = range;
+       return &This->base;
+}
+
+Function *allocFunctionTable (Table *table, UndefinedBehavior undefBehavior) {
+       FunctionTable *This = (FunctionTable *) ourmalloc(sizeof(FunctionTable));
+       GETFUNCTIONTYPE(This) = TABLEFUNC;
+       This->table = table;
+       This->undefBehavior = undefBehavior;
+       return &This->base;
+}
+
+uint64_t applyFunctionOperator(FunctionOperator *This, uint numVals, uint64_t *values) {
+       ASSERT(numVals == 2);
+       switch (This->op) {
+       case ADD:
+               return values[0] + values[1];
+               break;
+       case SUB:
+               return values[0] - values[1];
+               break;
+       default:
+               ASSERT(0);
+       }
+}
+
+bool isInRangeFunction(FunctionOperator *This, uint64_t val) {
+       return existsInSet(This->range, val);
+}
+
+void deleteFunction(Function *This) {
+       switch (GETFUNCTIONTYPE(This)) {
+       case TABLEFUNC:
+               break;
+       case OPERATORFUNC:
+               deleteInlineArraySet(&((FunctionOperator *) This)->domains);
+               break;
+       default:
+               ASSERT(0);
+       }
+       ourfree(This);
+}