Inline Encoding Structs into appropriate AST Nodes
[satune.git] / src / AST / element.c
index 7401173ba806df7f9648ae8a81a957883764502c..a94db4b8d8ac27fbe812a6c44c1c0e2f650553ca 100644 (file)
@@ -5,8 +5,8 @@ Element *allocElementSet(Set * s) {
        ElementSet * tmp=(ElementSet *)ourmalloc(sizeof(ElementSet));
        GETELEMENTTYPE(tmp)= ELEMSET;
        tmp->set=s;
-       tmp->encoding=NULL;
        allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
+       initElementEncoding(&tmp->encoding, (Element *) tmp);
        return &tmp->base;
 }
 
@@ -19,17 +19,29 @@ Element* allocElementFunction(Function * function, Element ** array, uint numArr
        allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
        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;
 }
 
 void deleteElement(Element *This) {
        switch(GETELEMENTTYPE(This)) {
-       case ELEMFUNCRETURN:
-               deleteInlineArrayElement(&((ElementFunction *)This)->inputs);
+       case ELEMFUNCRETURN: {
+               ElementFunction *ef = (ElementFunction *) This;
+               deleteInlineArrayElement(&ef->inputs);
+               deleteElementEncoding(&ef->domainencoding);
+               deleteFunctionEncoding(&ef->functionencoding);
                break;
+       }
+       case ELEMSET: {
+               ElementSet *es = (ElementSet *) This;
+               deleteElementEncoding(&es->encoding);
+               break;
+       }
        default:
                ;
        }
        deleteVectorArrayASTNode(GETELEMENTPARENTS(This));
+
        ourfree(This);
 }