]> git.sur5r.net Git - cc65/blobdiff - src/cc65/swstmt.c
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / cc65 / swstmt.c
index b5c4b2b8f06948d66993a27cc2b997b59580aebf..7e48b58d2cf0daf5677f3f3283a3407c3e479b38 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                swstmt.c                                  */
+/*                                 swstmt.c                                  */
 /*                                                                           */
-/*                       Parse the switch statement                         */
+/*                        Parse the switch statement                         */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
@@ -56,7 +56,7 @@
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
@@ -78,7 +78,7 @@ static SwitchCtrl* Switch = 0;
 
 
 /*****************************************************************************/
-/*                                  Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -90,9 +90,10 @@ void SwitchStatement (void)
     CodeMark    CaseCodeStart;  /* Start of code marker */
     CodeMark    SwitchCodeStart;/* Start of switch code */
     CodeMark    SwitchCodeEnd;  /* End of switch code */
-    unsigned    ExitLabel;     /* Exit label */
+    unsigned    ExitLabel;      /* Exit label */
     unsigned    SwitchCodeLabel;/* Label for the switch code */
     int         HaveBreak = 0;  /* True if the last statement had a break */
+    int         RCurlyBrace;    /* True if last token is right curly brace */
     SwitchCtrl* OldSwitch;      /* Pointer to old switch control data */
     SwitchCtrl  SwitchData;     /* New switch data */
 
@@ -107,8 +108,8 @@ void SwitchStatement (void)
     Expression0 (&SwitchExpr);
     if (!IsClassInt (SwitchExpr.Type))  {
         Error ("Switch quantity is not an integer");
-       /* To avoid any compiler errors, make the expression a valid int */
-       ED_MakeConstAbsInt (&SwitchExpr, 1);
+        /* To avoid any compiler errors, make the expression a valid int */
+        ED_MakeConstAbsInt (&SwitchExpr, 1);
     }
     ConsumeRParen ();
 
@@ -151,11 +152,11 @@ void SwitchStatement (void)
     /* Parse the following statement, which will actually be a compound
      * statement because of the curly brace at the current input position
      */
-    HaveBreak = Statement (0);
+    HaveBreak = Statement (&RCurlyBrace);
 
     /* Check if we had any labels */
     if (CollCount (SwitchData.Nodes) == 0 && SwitchData.DefaultLabel == 0) {
-       Warning ("No case labels");
+        Warning ("No case labels");
     }
 
     /* If the last statement did not have a break, we may have an open
@@ -188,7 +189,7 @@ void SwitchStatement (void)
 
     /* Define the exit label */
     g_defcodelabel (ExitLabel);
-                                                                    
+
     /* Exit the loop */
     DelLoop ();
 
@@ -197,6 +198,13 @@ void SwitchStatement (void)
 
     /* Free the case value tree */
     FreeCaseNodeColl (SwitchData.Nodes);
+
+    /* If the case statement was (correctly) terminated by a closing curly
+     * brace, skip it now.
+     */
+    if (RCurlyBrace) {
+        NextToken ();
+    }
 }