[hackers] [scc] Convert orphaned break and continue into semantic error || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sat, 28 Nov 2015 10:51:06 +0100 (CET)

commit 6d283bb403b52df5f45b9cb81c6a70c181e45f7c
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sat Nov 28 10:48:42 2015 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sat Nov 28 10:48:42 2015 +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.

diff --git a/cc1/stmt.c b/cc1/stmt.c
index c824d29..a16f458 100644
--- a/cc1/stmt.c
+++ b/cc1/stmt.c
_AT_@ -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
Received on Sat Nov 28 2015 - 10:51:06 CET

This archive was generated by hypermail 2.3.0 : Sat Nov 28 2015 - 11:00:14 CET