]> git.sur5r.net Git - cc65/blob - src/cc65/casenode.h
Merge remote-tracking branch 'upstream/master' into a5200
[cc65] / src / cc65 / casenode.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                casenode.h                                 */
4 /*                                                                           */
5 /*        Node for the tree that is generated for a switch statement         */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@cc65.org                                                 */
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 #ifndef CASENODE_H
37 #define CASENODE_H
38
39
40
41 /* common */
42 #include "coll.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Data                                    */
48 /*****************************************************************************/
49
50
51
52 typedef struct CaseNode CaseNode;
53 struct CaseNode {
54     unsigned char Value;
55     unsigned      Label;
56     Collection*   Nodes;
57 };
58
59
60
61 /*****************************************************************************/
62 /*                                   Code                                    */
63 /*****************************************************************************/
64
65
66
67 CaseNode* NewCaseNode (unsigned char Value);
68 /* Create and initialize a new CaseNode */
69
70 void FreeCaseNode (CaseNode* N);
71 /* Delete a case node plus all sub nodes */
72
73 #if defined(HAVE_INLINE)
74 INLINE CaseNode* CN_GetSubNode (CaseNode* N, unsigned Index)
75 /* Get a sub node of the given node */
76 {
77     return CollAt (N->Nodes, Index);
78 }
79 #else
80 #  define CN_GetSubNode(N, Index) CollAt (&(N)->Nodes, Index)
81 #endif
82
83 #if defined(HAVE_INLINE)
84 INLINE unsigned char CN_GetValue (const CaseNode* N)
85 /* Return the value for a case node */
86 {
87     return N->Value;
88 }
89 #else
90 #  define CN_GetValue(N)  ((N)->Value)
91 #endif
92
93 #if defined(HAVE_INLINE)
94 INLINE unsigned CN_GetLabel (const CaseNode* N)
95 /* Return the label for a case node */
96 {
97     return N->Label;
98 }
99 #else
100 #  define CN_GetLabel(N)  ((N)->Label)
101 #endif
102
103 #if defined(HAVE_INLINE)
104 INLINE int CN_IsLeafNode (const CaseNode* N)
105 /* Return true if this is a leaf node */
106 {
107     return (N->Nodes == 0);
108 }
109 #else
110 #  define CN_IsLeafNode(N)  ((N)->Nodes == 0)
111 #endif
112
113 void FreeCaseNodeColl (Collection* Nodes);
114 /* Free a collection of case nodes */
115
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
120  * false.
121  */
122
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.
126  */
127
128
129
130 /* End of casenode.h */
131
132 #endif