scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 9e29fc687fadb6d0ef18e986825c1b788ddd7284
parent 5884598d6118dbbe909880ee6c6a1e38cd602478
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 28 Nov 2015 16:12:53 +0100

Avoid multiple message errors in Case()

It is anonnying to get a full page of the same error,
so it is a good idea to mark the error like already
printed. There is no problems with the value of nr,
since this field is only used to generate this error.

Diffstat:
Mcc1/stmt.c | 18++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -242,15 +242,17 @@ Case(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) if ((np = iconstexpr()) == NULL) errorp("case label does not reduce to an integer constant"); expect(':'); - 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) + if (lswitch && lswitch->nr >= 0) { + if (++lswitch->nr == NR_SWITCH) { errorp("too case labels for a switch statement"); - /* TODO: Avoid repetion of this error for the same switch */ + lswitch->nr = -1; + } else { + pcase = xmalloc(sizeof(*pcase)); + pcase->expr = np; + pcase->next = lswitch->head; + emit(OLABEL, pcase->label = newlabel()); + lswitch->head = pcase; + } } stmt(lbreak, lcont, lswitch); }