X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fcasenode.c;h=25121f5e81667d63053196cb7ca20d5e00f4c7c5;hb=57c2e0cc0bcda3d08692abc60f5c85510801801d;hp=45a61ea6584fa2e7502a577db4d3ff8343f324f8;hpb=41d2cc8f915bd5513488fde96b652f0a59fba0b8;p=cc65 diff --git a/src/cc65/casenode.c b/src/cc65/casenode.c index 45a61ea65..25121f5e8 100644 --- a/src/cc65/casenode.c +++ b/src/cc65/casenode.c @@ -60,7 +60,7 @@ CaseNode* NewCaseNode (unsigned char Value) /* Initialize the fields */ N->Value = Value; - N->Label = GetLocalLabel (); + N->Label = 0; N->Nodes = 0; /* Return the new node */ @@ -138,14 +138,16 @@ unsigned InsertCaseValue (Collection* Nodes, unsigned long Val, unsigned Depth) */ { CaseNode* N = 0; + unsigned CaseLabel = GetLocalLabel (); /* Code label */ while (Depth--) { + int Index; + /* Get the key */ unsigned char Key = (Val >> (Depth * CHAR_BIT)) & 0xFF; /* Search for the node in the collection */ - int Index; if (SearchCaseNode (Nodes, Key, &Index) == 0) { /* Node not found - insert one */ @@ -153,10 +155,12 @@ unsigned InsertCaseValue (Collection* Nodes, unsigned long Val, unsigned Depth) CollInsert (Nodes, N, Index); /* If this is not the last round, create the collection for - * the subnodes. + * the subnodes, otherwise get a label for the code. */ if (Depth > 0) { - N->Nodes = NewCollection (); + N->Nodes = NewCollection (); + } else { + N->Label = CaseLabel; } } else { @@ -167,7 +171,7 @@ unsigned InsertCaseValue (Collection* Nodes, unsigned long Val, unsigned Depth) * duplicate case label in a switch. */ if (Depth == 0) { - Error ("Duplicate case label"); + Error ("Duplicate case label"); } } @@ -176,7 +180,7 @@ unsigned InsertCaseValue (Collection* Nodes, unsigned long Val, unsigned Depth) } /* Return the label of the node we found/created */ - return N->Label; + return CaseLabel; }