Add Order Encoding
[satune.git] / src / AST / element.c
1 #include "element.h"
2 #include "structs.h"
3
4 Element *allocElementSet(Set * s) {
5         ElementSet * tmp=(ElementSet *)ourmalloc(sizeof(ElementSet));
6         GETELEMENTTYPE(tmp)= ELEMSET;
7         tmp->set=s;
8         allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
9         initElementEncoding(&tmp->encoding, (Element *) tmp);
10         return &tmp->base;
11 }
12
13 Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus){
14         ElementFunction* tmp = (ElementFunction*) ourmalloc(sizeof(ElementFunction));
15         GETELEMENTTYPE(tmp)= ELEMFUNCRETURN;
16         tmp->function=function;
17         tmp->overflowstatus = overflowstatus;
18         allocInlineArrayInitElement(&tmp->inputs, array, numArrays);
19         allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
20         for(uint i=0;i<numArrays;i++)
21                 pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) tmp);
22         initElementEncoding(&tmp->domainencoding, (Element *) tmp);
23         initFunctionEncoding(&tmp->functionencoding, (Element *) tmp);
24         return &tmp->base;
25 }
26
27 void deleteElement(Element *This) {
28         switch(GETELEMENTTYPE(This)) {
29         case ELEMFUNCRETURN: {
30                 ElementFunction *ef = (ElementFunction *) This;
31                 deleteInlineArrayElement(&ef->inputs);
32                 deleteElementEncoding(&ef->domainencoding);
33                 deleteFunctionEncoding(&ef->functionencoding);
34                 break;
35         }
36         case ELEMSET: {
37                 ElementSet *es = (ElementSet *) This;
38                 deleteElementEncoding(&es->encoding);
39                 break;
40         }
41         default:
42                 ;
43         }
44         deleteVectorArrayASTNode(GETELEMENTPARENTS(This));
45
46         ourfree(This);
47 }