23e016cb0cc2a902a35d7c97b128fd1733031637
[satune.git] / src / AST / element.h
1 #ifndef ELEMENT_H
2 #define ELEMENT_H
3 #include "classlist.h"
4 #include "mymemory.h"
5 #include "structs.h"
6 #include "astnode.h"
7 #include "functionencoding.h"
8 #include "elementencoding.h"
9 #include "boolean.h"
10
11 #define GETELEMENTTYPE(o) GETASTNODETYPE(o)
12 #define GETELEMENTPARENTS(o) (&((Element*)o)->parents)          
13 struct Element {
14         ASTNode base;
15         VectorASTNode parents;
16 };
17
18 struct ElementConst {
19         Element base;
20         Set * set;
21         uint64_t value;
22         ElementEncoding encoding;
23 };
24
25 struct ElementSet {
26         Element base;
27         Set * set;
28         ElementEncoding encoding;
29 };
30
31 struct ElementFunction {
32         Element base;
33         Function * function;
34         ArrayElement inputs;
35         Boolean * overflowstatus;
36         FunctionEncoding functionencoding;
37         ElementEncoding rangeencoding;
38 };
39
40 Element * allocElementConst(uint64_t value, VarType type);
41 Element * allocElementSet(Set *s);
42 Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus);
43 void deleteElement(Element *This);
44 Set* getElementSet(Element* This);
45
46 static inline ElementEncoding* getElementEncoding(Element* This){
47         switch(GETELEMENTTYPE(This)){
48                 case ELEMSET:
49                         return &((ElementSet*)This)->encoding;
50                 case ELEMFUNCRETURN:            
51                         return &((ElementFunction*)This)->rangeencoding;
52                 case ELEMCONST:
53                         return &((ElementConst*)This)->encoding;
54                 default:
55                         ASSERT(0);
56         }
57         return NULL;
58 }
59
60 static inline FunctionEncoding* getElementFunctionEncoding(ElementFunction* func){
61         return &func->functionencoding;
62 }
63 #endif