Switch to vector class
[satune.git] / src / AST / element.cc
1 #include "element.h"
2 #include "structs.h"
3 #include "set.h"
4 #include "constraint.h"
5 #include "function.h"
6 #include "table.h"
7
8 Element::Element(ASTNodeType _type) : ASTNode(_type) {
9         initElementEncoding(&encoding, (Element *) this);
10 }
11
12 ElementSet::ElementSet(Set *s) : Element(ELEMSET), set(s) {
13 }
14
15 ElementFunction::ElementFunction(Function *_function, Element **array, uint numArrays, Boolean *_overflowstatus) : Element(ELEMFUNCRETURN), function(_function), inputs(array, numArrays), overflowstatus(_overflowstatus) {
16         for (uint i = 0; i < numArrays; i++)
17                 GETELEMENTPARENTS(array[i])->push(this);
18         initFunctionEncoding(&functionencoding, this);
19 }
20
21 ElementConst::ElementConst(uint64_t _value, VarType _type) : Element(ELEMCONST), value(_value) {
22         uint64_t array[]={value};
23         set = new Set(_type, array, 1);
24 }
25
26 Set *getElementSet(Element *This) {
27         switch (GETELEMENTTYPE(This)) {
28         case ELEMSET:
29                 return ((ElementSet *)This)->set;
30         case ELEMCONST:
31                 return ((ElementConst *)This)->set;
32         case ELEMFUNCRETURN: {
33                 Function *func = ((ElementFunction *)This)->function;
34                 switch (GETFUNCTIONTYPE(func)) {
35                 case TABLEFUNC:
36                         return ((FunctionTable *)func)->table->range;
37                 case OPERATORFUNC:
38                         return ((FunctionOperator *)func)->range;
39                 default:
40                         ASSERT(0);
41                 }
42         }
43         default:
44                 ASSERT(0);
45         }
46         ASSERT(0);
47         return NULL;
48 }
49
50 ElementFunction::~ElementFunction() {
51         deleteFunctionEncoding(&functionencoding);
52 }
53
54 ElementConst::~ElementConst() {
55         delete set;
56 }
57
58 Element::~Element() {
59         deleteElementEncoding(&encoding);
60 }