]> git.sur5r.net Git - cc65/blob - src/cc65/exprnode.h
969ee7506f9a694cf6b4ca3080b2c55da53bc6fe
[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 #include "datatype.h"
42
43
44
45 /*****************************************************************************/
46 /*                                 Forwards                                  */
47 /*****************************************************************************/
48
49
50
51 struct SymEntry;
52
53
54
55 /*****************************************************************************/
56 /*                                   Data                                    */
57 /*****************************************************************************/
58
59
60
61 /* Node types */
62 typedef enum {
63     NT_NONE,                    /* None (invalid) op */
64
65     NT_SYM,                     /* Symbol */
66     NT_CONST,                   /* A constant of some sort */
67
68     NT_ICAST,                   /* Implicit type cast */
69     NT_ECAST,                   /* Explicit type cast */
70
71     NT_REG_A,                   /* A register */
72     NT_REG_X,                   /* X register */
73     NT_REG_Y,                   /* Y register */
74     NT_REG_AX,                  /* AX register */
75     NT_REG_EAX,                 /* EAX register */
76
77     NT_CALLFUNC,                /* Function call */
78     NT_PUSH,                    /* Push the value onto the stack */
79     NT_POP,                     /* Pop the value from the stack */
80
81     NT_NOT,                     /* ~ */
82     NT_PLUS,                    /* + */
83     NT_MINUS,                   /* - */
84     NT_MUL,                     /* * */
85     NT_DIV,                     /* / */
86     NT_SHL,                     /* << */
87     NT_SHR,                     /* >> */
88     NT_AND,                     /* & */
89     NT_OR,                      /* | */
90     NT_XOR,                     /* ^ */
91
92     NT_ASSIGN,                  /* = */
93     NT_PLUS_ASSIGN,             /* += */
94     NT_MINUS_ASSIGN,            /* -= */
95     NT_MUL_ASSIGN,              /* *= */
96     NT_DIV_ASSIGN,              /* /= */
97     NT_SHL_ASSIGN,              /* <<= */
98     NT_SHR_ASSIGN,              /* >>= */
99     NT_AND_ASSIGN,              /* &= */
100     NT_OR_ASSIGN,               /* |= */
101     NT_XOR_ASSIGN,              /* ^= */
102
103     NT_PRE_DEC,                 /* -- */
104     NT_POST_DEC,                /* -- */
105     NT_PRE_INC,                 /* ++ */
106     NT_POST_INC,                /* ++ */
107
108     NT_BOOL_NOT,                /* ! */
109     NT_BOOL_OR,                 /* || */
110     NT_BOOL_AND,                /* && */
111
112     NT_EQ,                      /* == */
113     NT_NE,                      /* != */
114     NT_LT,                      /* < */
115     NT_LE,                      /* <= */
116     NT_GT,                      /* > */
117     NT_GE,                      /* >= */
118
119     NT_DEREF,                   /* * and others */
120
121     NT_COUNT                    /* Operation count */
122 } nodetype_t;
123
124
125
126 /* Struct describing one node in an expression tree */
127 typedef struct ExprNode ExprNode;
128 struct ExprNode {
129
130     ExprNode*                   Left;   /* Left and right leaves */
131     ExprNode*                   Right;
132
133     nodetype_t                  NT;     /* Node type */
134     type*                       Type;   /* Resulting type */
135     int                         LValue; /* True if this is an lvalue */
136
137     union {
138         /* Branch data */
139         ExprNode*               Test;   /* Third expr for ternary op */
140
141         /* Leave data */
142         long                    I;      /* Constant int value if any */
143         double                  F;      /* Constant float value if any */
144         struct SymEntry*        Sym;    /* Symbol table entry if any */
145     } V;
146
147 };
148
149
150
151 /*****************************************************************************/
152 /*                                   Code                                    */
153 /*****************************************************************************/
154
155
156
157 void InitExprNode (ExprNode* E);
158 /* Initialize a new expression node */
159
160
161
162 /* End of exprnode.h */
163
164 #endif
165
166
167
168
169