4 #include "constraint.h"
6 Element *allocElementSet(Set * s) {
7 ElementSet * tmp=(ElementSet *)ourmalloc(sizeof(ElementSet));
8 GETELEMENTTYPE(tmp)= ELEMSET;
10 allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
11 initElementEncoding(&tmp->encoding, (Element *) tmp);
15 Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus){
16 ElementFunction* tmp = (ElementFunction*) ourmalloc(sizeof(ElementFunction));
17 GETELEMENTTYPE(tmp)= ELEMFUNCRETURN;
18 tmp->function=function;
19 tmp->overflowstatus = overflowstatus;
20 allocInlineArrayInitElement(&tmp->inputs, array, numArrays);
21 allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
22 for(uint i=0;i<numArrays;i++)
23 pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) tmp);
24 initElementEncoding(&tmp->domainencoding, (Element *) tmp);
25 initFunctionEncoding(&tmp->functionencoding, (Element *) tmp);
29 uint getElementSize(Element* This){
30 switch(GETELEMENTTYPE(This)){
32 return getSetSize( ((ElementSet*)This)->set );
43 Constraint * getElementValueConstraint(Element* This, uint64_t value) {
44 switch(GETELEMENTTYPE(This)){
46 ; //Statement is needed for a label and This is a NOPE
47 ElementSet* elemSet= ((ElementSet*)This);
48 uint size = getSetSize(elemSet->set);
49 for(uint i=0; i<size; i++){
50 if( getElementEncoding(elemSet)->encodingArray[i]==value){
51 return generateBinaryConstraint(getElementEncoding(elemSet)->numVars,
52 getElementEncoding(elemSet)->variables, i);
65 void deleteElement(Element *This) {
66 switch(GETELEMENTTYPE(This)) {
67 case ELEMFUNCRETURN: {
68 ElementFunction *ef = (ElementFunction *) This;
69 deleteInlineArrayElement(&ef->inputs);
70 deleteElementEncoding(&ef->domainencoding);
71 deleteFunctionEncoding(&ef->functionencoding);
75 ElementSet *es = (ElementSet *) This;
76 deleteElementEncoding(&es->encoding);
82 deleteVectorArrayASTNode(GETELEMENTPARENTS(This));