Switch array struct to 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         initDefVectorASTNode(GETELEMENTPARENTS(this));
10         initElementEncoding(&encoding, (Element *) this);
11 }
12
13 ElementSet::ElementSet(Set *s) : Element(ELEMSET), set(s) {
14 }
15
16 ElementFunction::ElementFunction(Function *_function, Element **array, uint numArrays, Boolean *_overflowstatus) : Element(ELEMFUNCRETURN), function(_function), inputs(array, numArrays), overflowstatus(_overflowstatus) {
17         for (uint i = 0; i < numArrays; i++)
18                 pushVectorASTNode(GETELEMENTPARENTS(array[i]), this);
19         initFunctionEncoding(&functionencoding, this);
20 }
21
22 ElementConst::ElementConst(uint64_t _value, VarType _type) : Element(ELEMCONST), value(_value) {
23         uint64_t array[]={value};
24         set = new Set(_type, array, 1);
25 }
26
27 Set *getElementSet(Element *This) {
28         switch (GETELEMENTTYPE(This)) {
29         case ELEMSET:
30                 return ((ElementSet *)This)->set;
31         case ELEMCONST:
32                 return ((ElementConst *)This)->set;
33         case ELEMFUNCRETURN: {
34                 Function *func = ((ElementFunction *)This)->function;
35                 switch (GETFUNCTIONTYPE(func)) {
36                 case TABLEFUNC:
37                         return ((FunctionTable *)func)->table->range;
38                 case OPERATORFUNC:
39                         return ((FunctionOperator *)func)->range;
40                 default:
41                         ASSERT(0);
42                 }
43         }
44         default:
45                 ASSERT(0);
46         }
47         ASSERT(0);
48         return NULL;
49 }
50
51 ElementFunction::~ElementFunction() {
52         deleteFunctionEncoding(&functionencoding);
53 }
54
55 ElementConst::~ElementConst() {
56         delete set;
57 }
58
59 Element::~Element() {
60         deleteElementEncoding(&encoding);
61         deleteVectorArrayASTNode(GETELEMENTPARENTS(this));
62 }