shithub: scc

Download patch

ref: 5884598d6118dbbe909880ee6c6a1e38cd602478
parent: e39bdf2da0218151502600e8607a1b8aa690b12f
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sat Nov 28 11:00:02 EST 2015

Convert errors in Case() in semantic errors

Again, it is not needed to recover in this case.

--- a/cc1/stmt.c
+++ b/cc1/stmt.c
@@ -238,17 +238,20 @@
 
 	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);
 }