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 This->overflowstatus = overflowstatus;
22 initArrayInitElement(&This->inputs, array, numArrays);
23 initDefVectorASTNode(GETELEMENTPARENTS(This));
24 for(uint i=0;i<numArrays;i++)
25 pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) This);
26 initElementEncoding(&This->rangeencoding, (Element *) This);
27 initFunctionEncoding(&This->functionencoding, (Element *) This);
31 Element * allocElementConst(uint64_t value, VarType type) {
32 ElementConst * This=(ElementConst *)ourmalloc(sizeof(ElementConst));
33 GETELEMENTTYPE(This)= ELEMCONST;
35 This->set=allocSet(type, (uint64_t[]){value}, 1);
36 initDefVectorASTNode(GETELEMENTPARENTS(This));
37 initElementEncoding(&This->encoding, (Element *) This);
41 Set* getElementSet(Element* This){
42 switch(GETELEMENTTYPE(This)){
44 return ((ElementSet*)This)->set;
46 return ((ElementConst*)This)->set;
47 case ELEMFUNCRETURN: {
48 Function* func = ((ElementFunction*)This)->function;
49 switch(GETFUNCTIONTYPE(func)){
51 return ((FunctionTable*)func)->table->range;
53 return ((FunctionOperator*)func)->range;
65 void deleteElement(Element *This) {
66 switch(GETELEMENTTYPE(This)) {
67 case ELEMFUNCRETURN: {
68 ElementFunction *ef = (ElementFunction *) This;
69 deleteInlineArrayElement(&ef->inputs);
70 deleteElementEncoding(&ef->rangeencoding);
71 deleteFunctionEncoding(&ef->functionencoding);
75 ElementSet *es = (ElementSet *) This;
76 deleteElementEncoding(&es->encoding);
80 ElementConst *ec = (ElementConst *) This;
81 deleteSet(ec->set);//Client did not create, so we free it
82 deleteElementEncoding(&ec->encoding);
88 deleteVectorArrayASTNode(GETELEMENTPARENTS(This));