commit 5884598d6118dbbe909880ee6c6a1e38cd602478
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Sat Nov 28 16:00:02 2015 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Sat Nov 28 16:20:29 2015 +0100

    Convert errors in Case() in semantic errors
    
    Again, it is not needed to recover in this case.

diff --git a/cc1/stmt.c b/cc1/stmt.c
index a16f458..244aabd 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -238,17 +238,20 @@ Case(Symbol *lbreak, Symbol *lcont, Caselist *lswitch)
 
        expect(CASE);
        if (!lswitch)
-               error("case label not within a switch statement");
+               errorp("case label not within a switch statement");
        if ((np = iconstexpr()) == NULL)
-               error("case label does not reduce to an integer constant");
+               errorp("case label does not reduce to an integer constant");
        expect(':');
-       pcase = xmalloc(sizeof(*pcase));
-       pcase->expr = np;
-       pcase->next = lswitch->head;
-       emit(OLABEL, pcase->label = newlabel());
-       lswitch->head = pcase;
-       if (++lswitch->nr == NR_SWITCH)
-               error("too case labels for a switch statement");
+       if (lswitch) {
+               pcase = xmalloc(sizeof(*pcase));
+               pcase->expr = np;
+               pcase->next = lswitch->head;
+               emit(OLABEL, pcase->label = newlabel());
+               lswitch->head = pcase;
+               if (++lswitch->nr == NR_SWITCH)
+                       errorp("too case labels for a switch statement");
+               /* TODO: Avoid repetion of this error for the same switch */
+       }
        stmt(lbreak, lcont, lswitch);
 }
 

Reply via email to