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