]> git.sur5r.net Git - cc65/blob - src/cc65/exprnode.h
29dbc74d2eb2f0be5ad3a5370a2443ff11dcfa76
[cc65] / src / cc65 / exprnode.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                exprnode.h                                 */
4 /*                                                                           */
5 /*             Expression node structure for the cc65 C compiler             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@musoftware.de                                            */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef EXPRNODE_H
37 #define EXPRNODE_H
38
39
40
41 /* common */
42 #include "coll.h"
43
44 /* cc65 */
45 #include "datatype.h"
46
47
48
49 /*****************************************************************************/
50 /*                                 Forwards                                  */
51 /*****************************************************************************/
52
53
54
55 struct ExprHeap;
56 struct SymEntry;
57
58
59
60 /*****************************************************************************/
61 /*                                   Data                                    */
62 /*****************************************************************************/
63
64
65
66 /* Node types */
67 typedef enum {
68     NT_NONE,                    /* None (invalid) op */
69
70     NT_SYM,                     /* Symbol */
71     NT_CONST,                   /* A constant of some sort */
72     NT_ASM,                     /* Inline assembler */
73
74     NT_REG_A,                   /* A register */
75     NT_REG_X,                   /* X register */
76     NT_REG_Y,                   /* Y register */
77     NT_REG_AX,                  /* AX register */
78     NT_REG_EAX,                 /* EAX register */
79
80     NT_ARRAY_SUBSCRIPT,         /* Array subscript */
81     NT_STRUCT_ACCESS,           /* Access of a struct field */
82     NT_STRUCTPTR_ACCESS,        /* Access via struct ptr */
83     NT_FUNCTION_CALL,           /* Call a function */
84     NT_TYPECAST,                /* A cast */
85     NT_ADDRESS,                 /* Address operator (&) */
86     NT_INDIRECT,                /* Indirection operator (*) */
87
88     NT_UNARY_MINUS,
89     NT_COMPLEMENT,              /* ~ */
90     NT_BOOL_NOT,                /* ! */
91
92     NT_PLUS,                    /* + */
93     NT_MINUS,                   /* - */
94     NT_MUL,                     /* * */
95     NT_DIV,                     /* / */
96     NT_SHL,                     /* << */
97     NT_SHR,                     /* >> */
98     NT_AND,                     /* & */
99     NT_OR,                      /* | */
100     NT_XOR,                     /* ^ */
101
102     NT_TERNARY,                 /* ?: */
103
104     NT_ASSIGN,                  /* = */
105     NT_PLUS_ASSIGN,             /* += */
106     NT_MINUS_ASSIGN,            /* -= */
107     NT_MUL_ASSIGN,              /* *= */
108     NT_DIV_ASSIGN,              /* /= */
109     NT_SHL_ASSIGN,              /* <<= */
110     NT_SHR_ASSIGN,              /* >>= */
111     NT_AND_ASSIGN,              /* &= */
112     NT_OR_ASSIGN,               /* |= */
113     NT_XOR_ASSIGN,              /* ^= */
114
115     NT_PRE_DEC,                 /* -- */
116     NT_POST_DEC,                /* -- */
117     NT_PRE_INC,                 /* ++ */
118     NT_POST_INC,                /* ++ */
119
120     NT_BOOL_OR,                 /* || */
121     NT_BOOL_AND,                /* && */
122
123     NT_EQ,                      /* == */
124     NT_NE,                      /* != */
125     NT_LT,                      /* < */
126     NT_LE,                      /* <= */
127     NT_GT,                      /* > */
128     NT_GE,                      /* >= */
129
130     NT_COUNT                    /* Operation count */
131 } nodetype_t;
132
133
134
135 /* Struct describing one node in an expression tree */
136 typedef struct ExprNode ExprNode;
137 struct ExprNode {
138
139     /* Management data */
140     union {
141         struct ExprHeap*        Owner;  /* Heap, this node is in */
142         struct ExprNode*        Next;   /* Next in free list */
143     } MData;
144
145     Collection                  List;   /* List of subexpressions */
146     nodetype_t                  NT;     /* Node type */
147     type*                       Type;   /* Resulting type */
148     int                         LValue; /* True if this is an lvalue */
149
150     union {
151         long                    I;      /* Constant int value if any */
152         double                  F;      /* Constant float value if any */
153     } V;
154 };
155
156
157
158 /* Predefined indices for node items in List */
159 enum {
160     IDX_LEFT    = 0,
161     IDX_RIGHT   = 1,
162     IDX_SYM     = 0
163 };
164
165 /* Some other constants for better readability */
166 enum {
167     RVALUE      = 0,
168     LVALUE      = 1
169 };
170
171
172
173 /*****************************************************************************/
174 /*                                   Code                                    */
175 /*****************************************************************************/
176
177
178
179 ExprNode* InitExprNode (ExprNode* E, nodetype_t NT, type* Type,
180                         int LValue, struct ExprHeap* Owner);
181 /* Initialize a new expression node */
182
183 void* GetItem (ExprNode* N, unsigned Index);
184 /* Return one of the items from the nodes item list */
185
186 void AppendItem (ExprNode* N, void* Item);
187 /* Append an item to the nodes item list */
188
189 void SetItem (ExprNode* N, void* Item, unsigned Index);
190 /* Set a specific node item. The item list is filled with null pointers as
191  * needed.
192  */
193
194 ExprNode* GetLeftNode (ExprNode* N);
195 /* Get the left sub-node from the list */
196
197 void SetLeftNode (ExprNode* Root, ExprNode* Left);
198 /* Set the left node in Root */
199
200 ExprNode* GetRightNode (ExprNode* N);
201 /* Get the right sub-node from the list */
202
203 void SetRightNode (ExprNode* Root, ExprNode* Right);
204 /* Set the right node in Root */
205
206 struct SymEntry* GetNodeSym (ExprNode* N);
207 /* Get the symbol entry for a NT_SYM node */
208
209 void SetNodeSym (ExprNode* N, struct SymEntry* Sym);
210 /* Set the symbol entry in a NT_SYM node */
211
212
213
214 /* End of exprnode.h */
215
216 #endif
217
218
219
220
221