#include "table.h"
Element *allocElementSet(Set * s) {
- ElementSet * tmp=(ElementSet *)ourmalloc(sizeof(ElementSet));
- GETELEMENTTYPE(tmp)= ELEMSET;
- tmp->set=s;
- allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
- initElementEncoding(&tmp->encoding, (Element *) tmp);
- return &tmp->base;
+ ElementSet * This=(ElementSet *)ourmalloc(sizeof(ElementSet));
+ GETELEMENTTYPE(This)= ELEMSET;
+ This->set=s;
+ initDefVectorASTNode(GETELEMENTPARENTS(This));
+ initElementEncoding(&This->encoding, (Element *) This);
+ return &This->base;
}
Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus){
- ElementFunction* tmp = (ElementFunction*) ourmalloc(sizeof(ElementFunction));
- GETELEMENTTYPE(tmp)= ELEMFUNCRETURN;
- tmp->function=function;
- tmp->overflowstatus = overflowstatus;
- allocInlineArrayInitElement(&tmp->inputs, array, numArrays);
- allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
+ ElementFunction* This = (ElementFunction*) ourmalloc(sizeof(ElementFunction));
+ GETELEMENTTYPE(This)= ELEMFUNCRETURN;
+ This->function=function;
+ This->overflowstatus = overflowstatus;
+ initArrayInitElement(&This->inputs, array, numArrays);
+ initDefVectorASTNode(GETELEMENTPARENTS(This));
for(uint i=0;i<numArrays;i++)
- pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) tmp);
- initElementEncoding(&tmp->domainencoding, (Element *) tmp);
- initFunctionEncoding(&tmp->functionencoding, (Element *) tmp);
- return &tmp->base;
+ pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) This);
+ initElementEncoding(&This->rangeencoding, (Element *) This);
+ initFunctionEncoding(&This->functionencoding, (Element *) This);
+ return &This->base;
+}
+
+Element * allocElementConst(uint64_t value, VarType type) {
+ ElementConst * This=(ElementConst *)ourmalloc(sizeof(ElementConst));
+ GETELEMENTTYPE(This)= ELEMCONST;
+ This->value=value;
+ This->set=allocSet(type, (uint64_t[]){value}, 1);
+ initDefVectorASTNode(GETELEMENTPARENTS(This));
+ initElementEncoding(&This->encoding, (Element *) This);
+ return &This->base;
}
Set* getElementSet(Element* This){
switch(GETELEMENTTYPE(This)){
- case ELEMSET:
- return ((ElementSet*)This)->set;
- case ELEMFUNCRETURN:
- ;//Nope is needed for label assignment. i.e. next instruction isn't
- Function* func = ((ElementFunction*)This)->function;
- switch(GETFUNCTIONTYPE(func)){
- case TABLEFUNC:
- return ((FunctionTable*)func)->table->range;
- case OPERATORFUNC:
- return ((FunctionOperator*)func)->range;
- default:
- ASSERT(0);
- }
+ case ELEMSET:
+ return ((ElementSet*)This)->set;
+ case ELEMCONST:
+ return ((ElementConst*)This)->set;
+ case ELEMFUNCRETURN: {
+ Function* func = ((ElementFunction*)This)->function;
+ switch(GETFUNCTIONTYPE(func)){
+ case TABLEFUNC:
+ return ((FunctionTable*)func)->table->range;
+ case OPERATORFUNC:
+ return ((FunctionOperator*)func)->range;
default:
ASSERT(0);
- }
- ASSERT(0);
- return NULL;
-}
-
-uint getElemEncodingInUseVarsSize(ElementEncoding* This){
- uint size=0;
- for(uint i=0; i<This->encArraySize; i++){
- if(isinUseElement(This, i)){
- size++;
}
}
- return size;
-}
-
-
-Constraint * getElementValueBinaryIndexConstraint(Element* This, uint64_t value) {
- ASTNodeType type = GETELEMENTTYPE(This);
- ASSERT(type == ELEMSET || type == ELEMFUNCRETURN);
- ElementEncoding* elemEnc = getElementEncoding(This);
- for(uint i=0; i<elemEnc->encArraySize; i++){
- if( isinUseElement(elemEnc, i) && elemEnc->encodingArray[i]==value){
- return generateBinaryConstraint(elemEnc->numVars,
- elemEnc->variables, i);
- }
+ default:
+ ASSERT(0);
}
ASSERT(0);
return NULL;
case ELEMFUNCRETURN: {
ElementFunction *ef = (ElementFunction *) This;
deleteInlineArrayElement(&ef->inputs);
- deleteElementEncoding(&ef->domainencoding);
+ deleteElementEncoding(&ef->rangeencoding);
deleteFunctionEncoding(&ef->functionencoding);
break;
}
deleteElementEncoding(&es->encoding);
break;
}
+ case ELEMCONST: {
+ ElementConst *ec = (ElementConst *) This;
+ deleteSet(ec->set);//Client did not create, so we free it
+ deleteElementEncoding(&ec->encoding);
+ break;
+ }
default:
- ;
+ ASSERT(0);
}
deleteVectorArrayASTNode(GETELEMENTPARENTS(This));
-
ourfree(This);
}