scc

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

commit 3e242e211f63abae5f4df5d3c41fb40452b6a500
parent c65b15611c17d3f264c71ee7f326c15d2e838431
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Apr 2015 20:10:50 +0200

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 ';').

Diffstat:
Mcc1/cc1.h | 6++++++
Mcc1/decl.c | 9+++++++--
Mcc1/error.c | 20++++++++++++++++++++
Mcc1/main.c | 1-
4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -4,6 +4,12 @@ extern void error(char *fmt, ...); 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 diff --git 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 @@ extdecl(void) 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: diff --git 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 @@ warn(char *fmt, ...) } void +setsafe(uint8_t type) +{ + safe = type; +} + +void error(char *fmt, ...) { va_list va; @@ -45,6 +53,18 @@ error(char *fmt, ...) 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); } diff --git a/cc1/main.c b/cc1/main.c @@ -68,7 +68,6 @@ main(int argc, char *argv[]) ikeywords(); lexfile(*argv); - setjmp(recover); next(); while (yytoken != EOFTOK)