commit 5884598d6118dbbe909880ee6c6a1e38cd602478
parent e39bdf2da0218151502600e8607a1b8aa690b12f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sat, 28 Nov 2015 16:00:02 +0100
Convert errors in Case() in semantic errors
Again, it is not needed to recover in this case.
Diffstat:
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git 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);
}