c63becf15adc54eada5b26105ebedbd923a8a897
[satune.git] / src / AST / function.cc
1 #include "function.h"
2 #include "table.h"
3 #include "set.h"
4
5
6 FunctionOperator::FunctionOperator(ArithOp _op, Set **domain, uint numDomain, Set *_range, OverFlowBehavior _overflowbehavior) : Function(OPERATORFUNC), op(_op), range(_range), overflowbehavior(_overflowbehavior) {
7         initArrayInitSet(&domains, domain, numDomain);
8 }
9
10 FunctionTable::FunctionTable (Table *_table, UndefinedBehavior _undefBehavior) : Function(TABLEFUNC), table(_table), undefBehavior(_undefBehavior) {
11 }
12
13 uint64_t FunctionOperator::applyFunctionOperator(uint numVals, uint64_t *values) {
14         ASSERT(numVals == 2);
15         switch (op) {
16         case ADD:
17                 return values[0] + values[1];
18                 break;
19         case SUB:
20                 return values[0] - values[1];
21                 break;
22         default:
23                 ASSERT(0);
24         }
25 }
26
27 bool FunctionOperator::isInRangeFunction(uint64_t val) {
28         return range->exists(val);
29 }
30
31 FunctionOperator::~FunctionOperator() {
32         deleteInlineArraySet(&domains);
33 }