1 /*****************************************************************************/
5 /* Expression node structure for the cc65 C compiler */
9 /* (C) 2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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. */
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: */
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 */
32 /*****************************************************************************/
40 /*****************************************************************************/
42 /*****************************************************************************/
46 ExprNode* InitExprNode (ExprNode* E, nodetype_t NT, type* Type,
47 int LValue, struct ExprHeap* Owner)
48 /* Initialize a new expression node */
50 /* Intialize basic data */
51 E->MData.Owner = Owner;
58 /* Initialize the expression list in the node */
59 InitCollection (&E->List);
61 /* Return the node just initialized */
67 void* GetItem (ExprNode* N, unsigned Index)
68 /* Return one of the items from the nodes item list */
70 return CollAt (&N->List, Index);
75 void AppendItem (ExprNode* N, void* Item)
76 /* Append an item to the nodes item list */
78 CollAppend (&N->List, Item);
83 void SetItem (ExprNode* N, void* Item, unsigned Index)
84 /* Set a specific node item. The item list is filled with null pointers as
88 if (Index >= CollCount (&N->List)) {
89 /* Fill up with NULL pointers */
90 while (Index >= CollCount (&N->List) < Index) {
91 CollAppend (&N->List, 0);
93 /* Append the new item */
94 CollAppend (&N->List, Item);
96 /* There is an item with this index, replace it */
97 CollReplace (&N->List, Item, Index);
103 ExprNode* GetNode (ExprNode* N, unsigned Index)
104 /* Get one of the sub-nodes from the list */
106 return GetNode (N, Index);
111 ExprNode* GetLeftNode (ExprNode* N)
112 /* Get the left sub-node from the list */
114 return GetNode (N, IDX_LEFT);
119 void SetLeftNode (ExprNode* Root, ExprNode* Left)
120 /* Set the left node in Root */
122 SetItem (Root, Left, IDX_LEFT);
127 ExprNode* GetRightNode (ExprNode* N)
128 /* Get the right sub-node from the list */
130 return GetNode (N, IDX_RIGHT);
135 void SetRightNode (ExprNode* Root, ExprNode* Right)
136 /* Set the right node in Root */
138 SetItem (Root, Right, IDX_RIGHT);
143 struct SymEntry* GetNodeSym (ExprNode* N)
144 /* Get the symbol entry for a NT_SYM node */
146 return GetItem (N, IDX_SYM);
151 void SetNodeSym (ExprNode* N, struct SymEntry* Sym)
152 /* Set the symbol entry in a NT_SYM node */
154 SetItem (N, Sym, IDX_SYM);