X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=diagnostic.c;h=c1a4ad8f57cac5631a3451fbef3f83f8424cf210;hb=64bf64a7a86bc49d31bb0d7a1e9f90f94cf259bb;hp=930b9bd52435d7d037102bbb2df59ea74993a224;hpb=f6c1ead779c365453da484355686e5e23ab0023d;p=cparser diff --git a/diagnostic.c b/diagnostic.c index 930b9bd..c1a4ad8 100644 --- a/diagnostic.c +++ b/diagnostic.c @@ -7,15 +7,18 @@ #include "token_t.h" #include "type.h" - -//#define ABORT_ON_ERROR - /** Number of occurred diagnostics. */ unsigned diagnostic_count = 0; /** Number of occurred errors. */ unsigned error_count = 0; /** Number of occurred warnings. */ unsigned warning_count = 0; +/** true if warnings should be inhibited */ +bool inhibit_all_warnings = false; +/** true if warnings should be treated as errors */ +bool warnings_are_errors = false; +/** true if the first error should stop the compilation */ +bool fatal_errors = false; /** * Issue a diagnostic message. @@ -61,6 +64,12 @@ static void diagnosticvf(const char *const fmt, va_list ap) break; } + case 'Y': { + const symbol_t *const symbol = va_arg(ap, const symbol_t*); + fputs(symbol->string, stderr); + break; + } + case 'E': { const expression_t* const expr = va_arg(ap, const expression_t*); print_expression(expr); @@ -130,28 +139,48 @@ void diagnosticf(const char *const fmt, ...) va_end(ap); } -void errorf(const source_position_t pos, const char *const fmt, ...) +static void errorvf(const source_position_t pos, + const char *const fmt, va_list ap) { - ++error_count; fprintf(stderr, "%s:%u: error: ", pos.input_name, pos.linenr); + ++error_count; + diagnosticvf(fmt, ap); + fputc('\n', stderr); + + if (fatal_errors) + abort(); +} +void errorf(const source_position_t pos, const char *const fmt, ...) +{ va_list ap; va_start(ap, fmt); - diagnosticvf(fmt, ap); + errorvf(pos, fmt, ap); va_end(ap); - fputc('\n', stderr); -#ifdef ABORT_ON_ERROR - abort(); -#endif + if (fatal_errors) + exit(1); } -void warningf(const source_position_t pos, const char *const fmt, ...) +static void warningvf(const source_position_t pos, + const char *const fmt, va_list ap) { - ++warning_count; fprintf(stderr, "%s:%u: warning: ", pos.input_name, pos.linenr); + ++warning_count; + diagnosticvf(fmt, ap); + fputc('\n', stderr); +} + +void warningf(const source_position_t pos, const char *const fmt, ...) +{ + if (inhibit_all_warnings) + return; + va_list ap; va_start(ap, fmt); - diagnosticvf(fmt, ap); + if (warnings_are_errors) { + errorvf(pos, fmt, ap); + } else { + warningvf(pos, fmt, ap); + } va_end(ap); - fputc('\n', stderr); }