shithub: scc

Download patch

ref: 3e242e211f63abae5f4df5d3c41fb40452b6a500
parent: c65b15611c17d3f264c71ee7f326c15d2e838431
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Apr 21 16:10:50 EDT 2015

Add error recovery at external declaration level.

At this point the only thing we can do is to search
the end of the declaration (the ';').

--- a/cc1/cc1.h
+++ b/cc1/cc1.h
@@ -4,6 +4,12 @@
 extern void warn(char *fmt, ...);
 extern void unexpected(void);
 extern void softerror(char *fmt, ...);
+extern void setsafe(uint8_t type);
+
+enum {
+	END_DECL
+};
+
 /* definitions of types */
 
 #define CTX_OUTER 0
--- a/cc1/decl.c
+++ b/cc1/decl.c
@@ -1,6 +1,6 @@
-#include <assert.h>
-#include <stddef.h>
+
 #include <inttypes.h>
+#include <setjmp.h>
 #include <string.h>
 
 #include "../inc/sizes.h"
@@ -493,6 +493,11 @@
 	int8_t sclass;
 	Symbol *sym;
 	extern Symbol *curfun;
+	extern jmp_buf recover;
+
+	setsafe(END_DECL);
+	if (setjmp(recover))
+		return;
 
 	switch (yytoken) {
 	case IDEN: case TYPE: case TYPEIDEN: case SCLASS: case TQUALIFIER:
--- a/cc1/error.c
+++ b/cc1/error.c
@@ -11,6 +11,8 @@
 extern uint8_t failure;
 extern jmp_buf recover;
 
+static uint8_t safe;
+
 static void
 warn_helper(int8_t flag, char *fmt, va_list va)
 {
@@ -38,6 +40,12 @@
 }
 
 void
+setsafe(uint8_t type)
+{
+	safe = type;
+}
+
+void
 error(char *fmt, ...)
 {
 	va_list va;
@@ -45,6 +53,18 @@
 	warn_helper(-1, fmt, va);
 	va_end(va);
 	failure = 1;
+
+	for (;; next()) {
+		switch (safe) {
+		case END_DECL:
+			if (yytoken == ';')
+				goto jump;
+			break;
+		}
+	}
+
+jump:
+	next();
 	longjmp(recover, 1);
 }
 
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -68,7 +68,6 @@
 	ikeywords();
 	lexfile(*argv);
 
-	setjmp(recover);
 	next();
 
 	while (yytoken != EOFTOK)