mirror of
https://github.com/cc65/cc65.git
synced 2025-03-03 09:32:33 +00:00
Don't run into an internal error in case of a duplicate switch label.
git-svn-id: svn://svn.cc65.org/cc65/trunk@1029 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
8546ab22cc
commit
e17b0a0aac
@ -60,7 +60,7 @@ CaseNode* NewCaseNode (unsigned char Value)
|
|||||||
|
|
||||||
/* Initialize the fields */
|
/* Initialize the fields */
|
||||||
N->Value = Value;
|
N->Value = Value;
|
||||||
N->Label = GetLocalLabel ();
|
N->Label = 0;
|
||||||
N->Nodes = 0;
|
N->Nodes = 0;
|
||||||
|
|
||||||
/* Return the new node */
|
/* Return the new node */
|
||||||
@ -138,14 +138,16 @@ unsigned InsertCaseValue (Collection* Nodes, unsigned long Val, unsigned Depth)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
CaseNode* N = 0;
|
CaseNode* N = 0;
|
||||||
|
unsigned CaseLabel = GetLocalLabel (); /* Code label */
|
||||||
|
|
||||||
while (Depth--) {
|
while (Depth--) {
|
||||||
|
|
||||||
|
int Index;
|
||||||
|
|
||||||
/* Get the key */
|
/* Get the key */
|
||||||
unsigned char Key = (Val >> (Depth * CHAR_BIT)) & 0xFF;
|
unsigned char Key = (Val >> (Depth * CHAR_BIT)) & 0xFF;
|
||||||
|
|
||||||
/* Search for the node in the collection */
|
/* Search for the node in the collection */
|
||||||
int Index;
|
|
||||||
if (SearchCaseNode (Nodes, Key, &Index) == 0) {
|
if (SearchCaseNode (Nodes, Key, &Index) == 0) {
|
||||||
|
|
||||||
/* Node not found - insert one */
|
/* Node not found - insert one */
|
||||||
@ -153,10 +155,12 @@ unsigned InsertCaseValue (Collection* Nodes, unsigned long Val, unsigned Depth)
|
|||||||
CollInsert (Nodes, N, Index);
|
CollInsert (Nodes, N, Index);
|
||||||
|
|
||||||
/* If this is not the last round, create the collection for
|
/* 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) {
|
if (Depth > 0) {
|
||||||
N->Nodes = NewCollection ();
|
N->Nodes = NewCollection ();
|
||||||
|
} else {
|
||||||
|
N->Label = CaseLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -167,7 +171,7 @@ unsigned InsertCaseValue (Collection* Nodes, unsigned long Val, unsigned Depth)
|
|||||||
* duplicate case label in a switch.
|
* duplicate case label in a switch.
|
||||||
*/
|
*/
|
||||||
if (Depth == 0) {
|
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 the label of the node we found/created */
|
||||||
return N->Label;
|
return CaseLabel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user