]> git.sur5r.net Git - cc65/blob - src/cc65/exprnode.h
Working on the new parser
[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
85     NT_UNARY_MINUS,
86
87     NT_NOT,                     /* ~ */
88     NT_PLUS,                    /* + */
89     NT_MINUS,                   /* - */
90     NT_MUL,                     /* * */
91     NT_DIV,                     /* / */
92     NT_SHL,                     /* << */
93     NT_SHR,                     /* >> */
94     NT_AND,                     /* & */
95     NT_OR,                      /* | */
96     NT_XOR,                     /* ^ */
97
98     NT_ASSIGN,                  /* = */
99     NT_PLUS_ASSIGN,             /* += */
100     NT_MINUS_ASSIGN,            /* -= */
101     NT_MUL_ASSIGN,              /* *= */
102     NT_DIV_ASSIGN,              /* /= */
103     NT_SHL_ASSIGN,              /* <<= */
104     NT_SHR_ASSIGN,              /* >>= */
105     NT_AND_ASSIGN,              /* &= */
106     NT_OR_ASSIGN,               /* |= */
107     NT_XOR_ASSIGN,              /* ^= */
108
109     NT_PRE_DEC,                 /* -- */
110     NT_POST_DEC,                /* -- */
111     NT_PRE_INC,                 /* ++ */
112     NT_POST_INC,                /* ++ */
113
114     NT_BOOL_NOT,                /* ! */
115     NT_BOOL_OR,                 /* || */
116     NT_BOOL_AND,                /* && */
117
118     NT_EQ,                      /* == */
119     NT_NE,                      /* != */
120     NT_LT,                      /* < */
121     NT_LE,                      /* <= */
122     NT_GT,                      /* > */
123     NT_GE,                      /* >= */
124
125     NT_DEREF,                   /* * and others */
126
127     NT_COUNT                    /* Operation count */
128 } nodetype_t;
129
130
131
132 /* Struct describing one node in an expression tree */
133 typedef struct ExprNode ExprNode;
134 struct ExprNode {
135
136     /* Management data */
137     union {
138         struct ExprHeap*        Owner;  /* Heap, this node is in */
139         struct ExprNode*        Next;   /* Next in free list */
140     } MData;
141
142     Collection                  List;   /* List of subexpressions */
143     nodetype_t                  NT;     /* Node type */
144     type*                       Type;   /* Resulting type */
145     int                         LValue; /* True if this is an lvalue */
146
147     union {
148         long                    I;      /* Constant int value if any */
149         double                  F;      /* Constant float value if any */
150     } V;
151 };
152
153
154
155 /* Predefined indices for node items in List */
156 enum {
157     IDX_LEFT    = 0,
158     IDX_RIGHT   = 1,
159     IDX_SYM     = 0
160 };
161
162 /* Some other constants for better readability */
163 enum {
164     RVALUE      = 0,
165     LVALUE      = 1
166 };
167
168
169
170 /*****************************************************************************/
171 /*                                   Code                                    */
172 /*****************************************************************************/
173
174
175
176 ExprNode* InitExprNode (ExprNode* E, nodetype_t NT, type* Type,
177                         int LValue, struct ExprHeap* Owner);
178 /* Initialize a new expression node */
179
180 void* GetItem (ExprNode* N, unsigned Index);
181 /* Return one of the items from the nodes item list */
182
183 void AppendItem (ExprNode* N, void* Item);
184 /* Append an item to the nodes item list */
185
186 void SetItem (ExprNode* N, void* Item, unsigned Index);
187 /* Set a specific node item. The item list is filled with null pointers as
188  * needed.
189  */
190
191 ExprNode* GetLeftNode (ExprNode* N);
192 /* Get the left sub-node from the list */
193
194 void SetLeftNode (ExprNode* Root, ExprNode* Left);
195 /* Set the left node in Root */
196
197 ExprNode* GetRightNode (ExprNode* N);
198 /* Get the right sub-node from the list */
199
200 void SetRightNode (ExprNode* Root, ExprNode* Right);
201 /* Set the right node in Root */
202
203 struct SymEntry* GetNodeSym (ExprNode* N);
204 /* Get the symbol entry for a NT_SYM node */
205
206 void SetNodeSym (ExprNode* N, struct SymEntry* Sym);
207 /* Set the symbol entry in a NT_SYM node */
208
209
210
211 /* End of exprnode.h */
212
213 #endif
214
215
216
217
218