Add Const API to frontend
[satune.git] / src / AST / element.h
index 986e380e0f03c9eb83ae1f299d4e3b95dc8abbcd..beab5af1e17aa065249afbae95a96c2109ab50d7 100644 (file)
@@ -2,30 +2,60 @@
 #define ELEMENT_H
 #include "classlist.h"
 #include "mymemory.h"
-#include "ops.h"
 #include "structs.h"
+#include "astnode.h"
+#include "functionencoding.h"
+#include "elementencoding.h"
+#include "boolean.h"
 
-#define GETELEMENTTYPE(o) (((Element*)o)->type)
-
-//FIXME:TALK ABOUT ELEMENT
+#define GETELEMENTTYPE(o) GETASTNODETYPE(o)
+#define GETELEMENTPARENTS(o) (&((Element*)o)->parents)         
 struct Element {
-       ElementType type;
+       ASTNode base;
+       VectorASTNode parents;
+};
+
+struct ElementConst {
+       Element base;
+       Set * set;
+       uint64_t value;
+       ElementEncoding encoding;
 };
 
 struct ElementSet {
-    Element base;
-    Set * set;
-    ElementEncoding * encoding;
+       Element base;
+       Set * set;
+       ElementEncoding encoding;
 };
 
-struct ElementFunction{
-    Element base;
-    Function * function;
-    VectorElement* Elements;
-    Boolean * overflowstatus;
+struct ElementFunction {
+       Element base;
+       Function * function;
+       ArrayElement inputs;
+       Boolean * overflowstatus;
+       FunctionEncoding functionencoding;
+       ElementEncoding rangeencoding;
 };
 
+Element * allocElementConst(uint64_t value, VarType type);
 Element * allocElementSet(Set *s);
 Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus);
 void deleteElement(Element *This);
+Set* getElementSet(Element* This);
+
+static inline ElementEncoding* getElementEncoding(Element* This){
+       switch(GETELEMENTTYPE(This)){
+               case ELEMSET:
+                       return &((ElementSet*)This)->encoding;
+               case ELEMFUNCRETURN:            
+                       return &((ElementFunction*)This)->rangeencoding;
+               default:
+                       ASSERT(0);
+       }
+       return NULL;
+}
+
+static inline FunctionEncoding* getElementFunctionEncoding(ElementFunction* func){
+       return &func->functionencoding;
+}
 #endif