X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=diagnostic.c;h=c1a4ad8f57cac5631a3451fbef3f83f8424cf210;hb=524755e6c9e00c7aa78ecd7da9ecc3b15e795a43;hp=9a7ca82fb0b25bb160bd3b190a69a0214f52ca9a;hpb=63e9daef66b06084272b2be411bfd1c1ed64dbc6;p=cparser diff --git a/diagnostic.c b/diagnostic.c index 9a7ca82..c1a4ad8 100644 --- a/diagnostic.c +++ b/diagnostic.c @@ -7,13 +7,22 @@ #include "token_t.h" #include "type.h" - -//#define ABORT_ON_ERROR - - -bool found_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. + */ static void diagnosticvf(const char *const fmt, va_list ap) { for (const char* f = fmt; *f != '\0'; ++f) { @@ -38,7 +47,7 @@ static void diagnosticvf(const char *const fmt, va_list ap) } case 'c': { - const unsigned char val = va_arg(ap, int); + const unsigned char val = (unsigned char) va_arg(ap, int); fputc(val, stderr); break; } @@ -55,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); @@ -119,31 +134,53 @@ void diagnosticf(const char *const fmt, ...) { va_list ap; va_start(ap, fmt); + ++diagnostic_count; diagnosticvf(fmt, ap); 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) { - found_error = true; 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) { 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); }