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