scc

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

commit 6d283bb403b52df5f45b9cb81c6a70c181e45f7c
parent 9c337dec526ba7b485ba66957f196249afa82922
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 28 Nov 2015 10:48:42 +0100

Convert orphaned break and continue into semantic error

In this case it is not needed to recover from the error,
we only have to emit a diagnosis and we can continue
without modifying the parser flow.

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

diff --git a/cc1/stmt.c b/cc1/stmt.c @@ -163,20 +163,24 @@ static void Break(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) { expect(BREAK); - if (!lbreak) - error("break statement not within loop or switch"); - emit(OJUMP, lbreak); - expect(';'); + if (!lbreak) { + errorp("break statement not within loop or switch"); + } else { + emit(OJUMP, lbreak); + expect(';'); + } } static void Continue(Symbol *lbreak, Symbol *lcont, Caselist *lswitch) { expect(CONTINUE); - if (!lcont) - error("continue statement not within loop"); - emit(OJUMP, lcont); - expect(';'); + if (!lcont) { + errorp("continue statement not within loop"); + } else { + emit(OJUMP, lcont); + expect(';'); + } } static void