]> git.sur5r.net Git - cc65/blob - src/cc65/exprnode.c
Working on the new parser
[cc65] / src / cc65 / exprnode.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                exprnode.c                                 */
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 #include "exprnode.h"
37
38
39
40 /*****************************************************************************/
41 /*                                   Code                                    */
42 /*****************************************************************************/
43
44
45
46 ExprNode* InitExprNode (ExprNode* E, nodetype_t NT, type* Type,
47                         int LValue, struct ExprHeap* Owner)
48 /* Initialize a new expression node */
49 {
50     /* Intialize basic data */
51     E->MData.Owner = Owner;
52     E->NT          = NT;
53     E->Type        = Type;
54     E->LValue      = LValue;
55
56     /* Initialize the expression list in the node */
57     InitCollection (&E->List);
58
59     /* Return the node just initialized */
60     return E;
61 }
62
63
64
65 void* GetItem (ExprNode* N, unsigned Index)
66 /* Return one of the items from the nodes item list */
67 {
68     return CollAt (&N->List, Index);
69 }
70
71
72
73 void AppendItem (ExprNode* N, void* Item)
74 /* Append an item to the nodes item list */
75 {
76     CollAppend (&N->List, Item);
77 }
78
79
80
81 void SetItem (ExprNode* N, void* Item, unsigned Index)
82 /* Set a specific node item. The item list is filled with null pointers as
83  * needed.
84  */
85 {
86     if (Index >= CollCount (&N->List)) {
87         /* Fill up with NULL pointers */
88         while (Index >= CollCount (&N->List) < Index) {
89             CollAppend (&N->List, 0);
90         }
91         /* Append the new item */
92         CollAppend (&N->List, Item);
93     } else {
94         /* There is an item with this index, replace it */
95         CollReplace (&N->List, Item, Index);
96     }
97 }
98
99
100
101 ExprNode* GetNode (ExprNode* N, unsigned Index)
102 /* Get one of the sub-nodes from the list */
103 {
104     return GetNode (N, Index);
105 }
106
107
108
109 ExprNode* GetLeftNode (ExprNode* N)
110 /* Get the left sub-node from the list */
111 {
112     return GetNode (N, IDX_LEFT);
113 }
114
115
116
117 void SetLeftNode (ExprNode* Root, ExprNode* Left)
118 /* Set the left node in Root */
119 {
120     SetItem (Root, Left, IDX_LEFT);
121 }
122
123
124
125 ExprNode* GetRightNode (ExprNode* N)
126 /* Get the right sub-node from the list */
127 {
128     return GetNode (N, IDX_RIGHT);
129 }
130
131
132
133 void SetRightNode (ExprNode* Root, ExprNode* Right)
134 /* Set the right node in Root */
135 {
136     SetItem (Root, Right, IDX_RIGHT);
137 }
138
139
140
141 struct SymEntry* GetNodeSym (ExprNode* N)
142 /* Get the symbol entry for a NT_SYM node */
143 {
144     return GetItem (N, IDX_SYM);
145 }
146
147
148
149 void SetNodeSym (ExprNode* N, struct SymEntry* Sym)
150 /* Set the symbol entry in a NT_SYM node */
151 {
152     SetItem (N, Sym, IDX_SYM);
153 }
154
155
156
157