1 /*****************************************************************************/
5 /* Node for the tree that is generated for a switch statement */
9 /* (C) 2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
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 /*****************************************************************************/
46 /*****************************************************************************/
48 /*****************************************************************************/
52 typedef struct CaseNode CaseNode;
61 /*****************************************************************************/
63 /*****************************************************************************/
67 CaseNode* NewCaseNode (unsigned char Value);
68 /* Create and initialize a new CaseNode */
70 void FreeCaseNode (CaseNode* N);
71 /* Delete a case node plus all sub nodes */
73 #if defined(HAVE_INLINE)
74 INLINE CaseNode* CN_GetSubNode (CaseNode* N, unsigned Index)
75 /* Get a sub node of the given node */
77 return CollAt (N->Nodes, Index);
80 # define CN_GetSubNode(N, Index) CollAt (&(N)->Nodes, Index)
83 #if defined(HAVE_INLINE)
84 INLINE unsigned char CN_GetValue (const CaseNode* N)
85 /* Return the value for a case node */
90 # define CN_GetValue(N) ((N)->Value)
93 #if defined(HAVE_INLINE)
94 INLINE unsigned CN_GetLabel (const CaseNode* N)
95 /* Return the label for a case node */
100 # define CN_GetLabel(N) ((N)->Label)
103 #if defined(HAVE_INLINE)
104 INLINE int CN_IsLeafNode (const CaseNode* N)
105 /* Return true if this is a leaf node */
107 return (N->Nodes == 0);
110 # define CN_IsLeafNode(N) ((N)->Nodes == 0)
113 void FreeCaseNodeColl (Collection* Nodes);
114 /* Free a collection of case nodes */
116 int SearchCaseNode (const Collection* Nodes, unsigned char Key, int* Index);
117 /* Search for a node in the given collection. If the node has been found,
118 * set Index to the index of the node and return true. If the node was not
119 * found, set Index the the insertion position of the node and return
123 unsigned InsertCaseValue (Collection* Nodes, unsigned long Val, unsigned Depth);
124 /* Insert a new case value into a CaseNode tree with the given depth. Return
125 * the code label for the value.
130 /* End of casenode.h */