4 #include "constraint.h"
8 Element *allocElementSet(Set * s) {
9 ElementSet * tmp=(ElementSet *)ourmalloc(sizeof(ElementSet));
10 GETELEMENTTYPE(tmp)= ELEMSET;
12 allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
13 initElementEncoding(&tmp->encoding, (Element *) tmp);
17 Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus){
18 ElementFunction* tmp = (ElementFunction*) ourmalloc(sizeof(ElementFunction));
19 GETELEMENTTYPE(tmp)= ELEMFUNCRETURN;
20 tmp->function=function;
21 tmp->overflowstatus = overflowstatus;
22 allocInlineArrayInitElement(&tmp->inputs, array, numArrays);
23 allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
24 for(uint i=0;i<numArrays;i++)
25 pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) tmp);
26 initElementEncoding(&tmp->domainencoding, (Element *) tmp);
27 initFunctionEncoding(&tmp->functionencoding, (Element *) tmp);
31 Set* getElementSet(Element* This){
32 switch(GETELEMENTTYPE(This)){
34 return ((ElementSet*)This)->set;
36 ;//Nope is needed for label assignment. i.e. next instruction isn't
37 Function* func = ((ElementFunction*)This)->function;
38 switch(GETFUNCTIONTYPE(func)){
40 return ((FunctionTable*)func)->table->range;
42 return ((FunctionOperator*)func)->range;
53 uint getElemEncodingInUseVarsSize(ElementEncoding* This){
55 for(uint i=0; i<This->encArraySize; i++){
56 if(isinUseElement(This, i)){
64 Constraint * getElementValueBinaryIndexConstraint(Element* This, uint64_t value) {
65 ASTNodeType type = GETELEMENTTYPE(This);
66 ASSERT(type == ELEMSET || type == ELEMFUNCRETURN);
67 ElementEncoding* elemEnc = getElementEncoding(This);
68 for(uint i=0; i<elemEnc->encArraySize; i++){
69 if( isinUseElement(elemEnc, i) && elemEnc->encodingArray[i]==value){
70 return generateBinaryConstraint(elemEnc->numVars,
71 elemEnc->variables, i);
78 void deleteElement(Element *This) {
79 switch(GETELEMENTTYPE(This)) {
80 case ELEMFUNCRETURN: {
81 ElementFunction *ef = (ElementFunction *) This;
82 deleteInlineArrayElement(&ef->inputs);
83 deleteElementEncoding(&ef->domainencoding);
84 deleteFunctionEncoding(&ef->functionencoding);
88 ElementSet *es = (ElementSet *) This;
89 deleteElementEncoding(&es->encoding);
95 deleteVectorArrayASTNode(GETELEMENTPARENTS(This));