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;
56 /* Initialize the expression list in the node */
57 InitCollection (&E->List);
59 /* Return the node just initialized */
65 void* GetItem (ExprNode* N, unsigned Index)
66 /* Return one of the items from the nodes item list */
68 return CollAt (&N->List, Index);
73 void AppendItem (ExprNode* N, void* Item)
74 /* Append an item to the nodes item list */
76 CollAppend (&N->List, Item);
81 void SetItem (ExprNode* N, void* Item, unsigned Index)
82 /* Set a specific node item. The item list is filled with null pointers as
86 if (Index >= CollCount (&N->List)) {
87 /* Fill up with NULL pointers */
88 while (Index >= CollCount (&N->List) < Index) {
89 CollAppend (&N->List, 0);
91 /* Append the new item */
92 CollAppend (&N->List, Item);
94 /* There is an item with this index, replace it */
95 CollReplace (&N->List, Item, Index);
101 ExprNode* GetNode (ExprNode* N, unsigned Index)
102 /* Get one of the sub-nodes from the list */
104 return GetNode (N, Index);
109 ExprNode* GetLeftNode (ExprNode* N)
110 /* Get the left sub-node from the list */
112 return GetNode (N, IDX_LEFT);
117 void SetLeftNode (ExprNode* Root, ExprNode* Left)
118 /* Set the left node in Root */
120 SetItem (Root, Left, IDX_LEFT);
125 ExprNode* GetRightNode (ExprNode* N)
126 /* Get the right sub-node from the list */
128 return GetNode (N, IDX_RIGHT);
133 void SetRightNode (ExprNode* Root, ExprNode* Right)
134 /* Set the right node in Root */
136 SetItem (Root, Right, IDX_RIGHT);
141 struct SymEntry* GetNodeSym (ExprNode* N)
142 /* Get the symbol entry for a NT_SYM node */
144 return GetItem (N, IDX_SYM);
149 void SetNodeSym (ExprNode* N, struct SymEntry* Sym)
150 /* Set the symbol entry in a NT_SYM node */
152 SetItem (N, Sym, IDX_SYM);