4 #include "constraint.h"
8 Element *allocElementSet(Set *s) {
9 ElementSet *This = (ElementSet *)ourmalloc(sizeof(ElementSet));
10 GETELEMENTTYPE(This) = ELEMSET;
12 initDefVectorASTNode(GETELEMENTPARENTS(This));
13 initElementEncoding(&This->encoding, (Element *) This);
17 Element *allocElementFunction(Function *function, Element **array, uint numArrays, Boolean *overflowstatus) {
18 ElementFunction *This = (ElementFunction *) ourmalloc(sizeof(ElementFunction));
19 GETELEMENTTYPE(This) = ELEMFUNCRETURN;
20 This->function = function;
21 ASSERT(GETBOOLEANTYPE(overflowstatus) == BOOLEANVAR);
22 This->overflowstatus = overflowstatus;
23 initArrayInitElement(&This->inputs, array, numArrays);
24 initDefVectorASTNode(GETELEMENTPARENTS(This));
25 for (uint i = 0; i < numArrays; i++)
26 pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) This);
27 initElementEncoding(&This->rangeencoding, (Element *) This);
28 initFunctionEncoding(&This->functionencoding, (Element *) This);
32 Element *allocElementConst(uint64_t value, VarType type) {
33 ElementConst *This = (ElementConst *)ourmalloc(sizeof(ElementConst));
34 GETELEMENTTYPE(This) = ELEMCONST;
36 This->set = allocSet(type, (uint64_t[]) {value}, 1);
37 initDefVectorASTNode(GETELEMENTPARENTS(This));
38 initElementEncoding(&This->encoding, (Element *) This);
42 Set *getElementSet(Element *This) {
43 switch (GETELEMENTTYPE(This)) {
45 return ((ElementSet *)This)->set;
47 return ((ElementConst *)This)->set;
48 case ELEMFUNCRETURN: {
49 Function *func = ((ElementFunction *)This)->function;
50 switch (GETFUNCTIONTYPE(func)) {
52 return ((FunctionTable *)func)->table->range;
54 return ((FunctionOperator *)func)->range;
66 void deleteElement(Element *This) {
67 switch (GETELEMENTTYPE(This)) {
68 case ELEMFUNCRETURN: {
69 ElementFunction *ef = (ElementFunction *) This;
70 deleteInlineArrayElement(&ef->inputs);
71 deleteElementEncoding(&ef->rangeencoding);
72 deleteFunctionEncoding(&ef->functionencoding);
76 ElementSet *es = (ElementSet *) This;
77 deleteElementEncoding(&es->encoding);
81 ElementConst *ec = (ElementConst *) This;
82 deleteSet(ec->set);//Client did not create, so we free it
83 deleteElementEncoding(&ec->encoding);
89 deleteVectorArrayASTNode(GETELEMENTPARENTS(This));