/*****************************************************************************/
/* */
-/* casenode.c */
+/* casenode.c */
/* */
-/* Node for the tree that is generated for a switch statement */
+/* Node for the tree that is generated for a switch statement */
/* */
/* */
/* */
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
/* Delete a case node plus all sub nodes */
{
if (N->Nodes) {
- FreeCaseNodeColl (N->Nodes);
+ FreeCaseNodeColl (N->Nodes);
}
xfree (N);
}
{
unsigned I;
for (I = 0; I < CollCount (Nodes); ++I) {
- FreeCaseNode (CollAtUnchecked (Nodes, I));
+ FreeCaseNode (CollAtUnchecked (Nodes, I));
}
FreeCollection (Nodes);
}
while (First <= Last) {
- /* Set current to mid of range */
- int Current = (Last + First) / 2;
+ /* Set current to mid of range */
+ int Current = (Last + First) / 2;
- /* Get the entry from this position */
- const CaseNode* N = CollConstAt (Nodes, Current);
+ /* Get the entry from this position */
+ const CaseNode* N = CollConstAt (Nodes, Current);
- /* Compare the values */
- if (N->Value < Key) {
- First = Current + 1;
- } else {
- Last = Current - 1;
- if (N->Value == Key) {
- /* Found. We cannot have duplicates, so end the search here. */
- S = 1;
- First = Current;
- }
- }
+ /* Compare the values */
+ if (N->Value < Key) {
+ First = Current + 1;
+ } else {
+ Last = Current - 1;
+ if (N->Value == Key) {
+ /* Found. We cannot have duplicates, so end the search here. */
+ S = 1;
+ First = Current;
+ }
+ }
}
while (Depth--) {
- int Index;
-
- /* Get the key */
- unsigned char Key = (Val >> (Depth * CHAR_BIT)) & 0xFF;
-
- /* Search for the node in the collection */
- if (SearchCaseNode (Nodes, Key, &Index) == 0) {
-
- /* Node not found - insert one */
- N = NewCaseNode (Key);
- CollInsert (Nodes, N, Index);
-
- /* If this is not the last round, create the collection for
- * the subnodes, otherwise get a label for the code.
- */
- if (Depth > 0) {
- N->Nodes = NewCollection ();
- } else {
- N->Label = CaseLabel;
- }
-
- } else {
- /* Node found, get it */
- N = CollAt (Nodes, Index);
-
- /* If this is the last round and we found a node, we have a
- * duplicate case label in a switch.
- */
- if (Depth == 0) {
- Error ("Duplicate case label");
- }
- }
-
- /* Get the collection from the node for the next round. */
- Nodes = N->Nodes;
+ int Index;
+
+ /* Get the key */
+ unsigned char Key = (Val >> (Depth * CHAR_BIT)) & 0xFF;
+
+ /* Search for the node in the collection */
+ if (SearchCaseNode (Nodes, Key, &Index) == 0) {
+
+ /* Node not found - insert one */
+ N = NewCaseNode (Key);
+ CollInsert (Nodes, N, Index);
+
+ /* If this is not the last round, create the collection for
+ * the subnodes, otherwise get a label for the code.
+ */
+ if (Depth > 0) {
+ N->Nodes = NewCollection ();
+ } else {
+ N->Label = CaseLabel;
+ }
+
+ } else {
+ /* Node found, get it */
+ N = CollAt (Nodes, Index);
+
+ /* If this is the last round and we found a node, we have a
+ * duplicate case label in a switch.
+ */
+ if (Depth == 0) {
+ Error ("Duplicate case label");
+ }
+ }
+
+ /* Get the collection from the node for the next round. */
+ Nodes = N->Nodes;
}
/* Return the label of the node we found/created */