More code towards graph
[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 #include "csolver.h"
8
9 Element::Element(ASTNodeType _type) :
10         ASTNode(_type),
11         encoding(this) {
12 }
13
14 ElementSet::ElementSet(Set *s) :
15         Element(ELEMSET),
16         set(s) {
17 }
18
19 ElementSet::ElementSet(ASTNodeType _type, Set *s) :
20         Element(_type),
21         set(s) {
22 }
23
24 ElementFunction::ElementFunction(Function *_function, Element **array, uint numArrays, BooleanEdge _overflowstatus) :
25         Element(ELEMFUNCRETURN),
26         inputs(array, numArrays),
27         overflowstatus(_overflowstatus),
28         functionencoding(this),
29         function(_function) {
30 }
31
32 ElementConst::ElementConst(uint64_t _value, Set *_set) :
33         ElementSet(ELEMCONST, _set),
34         value(_value) {
35 }
36
37 Element *ElementConst::clone(CSolver *solver, CloneMap *map) {
38         return solver->getElementConst(type, value);
39 }
40
41 Element *ElementSet::clone(CSolver *solver, CloneMap *map) {
42         Element *e = (Element *) map->get(this);
43         if (e != NULL)
44                 return e;
45         e = solver->getElementVar(set->clone(solver, map));
46         map->put(e, e);
47         return e;
48 }
49
50 Element *ElementFunction::clone(CSolver *solver, CloneMap *map) {
51         Element *array[inputs.getSize()];
52         for (uint i = 0; i < inputs.getSize(); i++) {
53                 array[i] = inputs.get(i)->clone(solver, map);
54         }
55         Element *e = solver->applyFunction(function->clone(solver, map), array, inputs.getSize(), overflowstatus->clone(solver, map));
56         return e;
57 }
58
59 void ElementFunction::updateParents() {
60         for(uint i=0;i < inputs.getSize(); i++) inputs.get(i)->parents.push(this);
61 }
62
63 Set * ElementFunction::getRange() {
64         return function->getRange();
65 }