scc

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

commit db85440bb52b69b15dc485069a639ef92a4d50fd
parent 867af16e5a690b302707c010ca5b4b8f41a28845
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Apr 2015 15:12:32 +0200

Improve the longjmp logic

Diffstat:
Mcc1/cc1.h | 4++--
Mcc1/error.c | 21++++++++++-----------
2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/cc1/cc1.h b/cc1/cc1.h @@ -1,7 +1,7 @@ -extern void error(const char *fmt, ...); -extern void warn(const char *fmt, ...); +extern void error(char *fmt, ...); +extern void warn(char *fmt, ...); extern void unexpected(void); /* definitions of types */ diff --git a/cc1/error.c b/cc1/error.c @@ -8,29 +8,26 @@ #include "../inc/cc.h" #include "cc1.h" +extern uint8_t failure; +extern jmp_buf recover; + static void -warn_helper(int8_t flag, const char *fmt, va_list va) +warn_helper(int8_t flag, char *fmt, va_list va) { extern unsigned linenum; extern unsigned columnum; extern const char *filename; - extern uint8_t failure; - extern jmp_buf recover; if (!flag) return; fprintf(stderr, "%s:%s:%u: ", - (flag < 0) ? "warning" : "error", filename, linenum); + (flag < 0) ? "error" : "warning", filename, linenum); vfprintf(stderr, fmt, va); putc('\n', stderr); - if (flag < 0) { - failure = 1; - longjmp(recover, 1); - } } void -warn(const char *fmt, ...) +warn(char *fmt, ...) { extern uint8_t warnings; @@ -41,12 +38,15 @@ warn(const char *fmt, ...) } void -error(const char *fmt, ...) +error(char *fmt, ...) { va_list va; va_start(va, fmt); warn_helper(-1, fmt, va); va_end(va); + + failure = 1; + longjmp(recover, 1); } void @@ -54,4 +54,3 @@ unexpected(void) { error("unexpected '%s'", yytext); } -