X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=diagnostic.c;h=af15aa40ec86134bdcfdd39741a4d9c2b9c3197d;hb=b00408fc909b04714fcbfbc79985c70b5bedeb66;hp=eacf085389f7087743c844088c010c63af295938;hpb=33a03247c00d9a5dc659f4be9065d649d839e629;p=cparser diff --git a/diagnostic.c b/diagnostic.c index eacf085..af15aa4 100644 --- a/diagnostic.c +++ b/diagnostic.c @@ -1,6 +1,6 @@ /* * This file is part of cparser. - * Copyright (C) 2007-2008 Matthias Braun + * Copyright (C) 2007-2009 Matthias Braun * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,6 +22,7 @@ #include "diagnostic.h" #include "adt/error.h" +#include "entity_t.h" #include "symbol_t.h" #include "token_t.h" #include "ast.h" @@ -29,19 +30,24 @@ #include "warning.h" /** Number of occurred diagnostics. */ -unsigned diagnostic_count = 0; +unsigned diagnostic_count = 0; /** Number of occurred errors. */ -unsigned error_count = 0; +unsigned error_count = 0; /** Number of occurred warnings. */ -unsigned warning_count = 0; +unsigned warning_count = 0; +bool show_column = true; +bool diagnostics_show_option = true; static const source_position_t *curr_pos = NULL; /** * prints an additional source position */ -static void print_source_position(FILE *out, const source_position_t *pos) { - fprintf(out, "at line %u", pos->linenr); +static void print_source_position(FILE *out, const source_position_t *pos) +{ + fprintf(out, "at line %u", pos->lineno); + if (show_column) + fprintf(out, ":%u", pos->colno); if (curr_pos == NULL || curr_pos->input_name != pos->input_name) fprintf(out, " of \"%s\"", pos->input_name); } @@ -66,12 +72,6 @@ static void diagnosticvf(const char *const fmt, va_list ap) fputc(*f, stderr); break; - case 'C': { - const wint_t val = va_arg(ap, wint_t); - fputwc(val, stderr); - break; - } - case 'c': { const unsigned char val = (unsigned char) va_arg(ap, int); fputc(val, stderr); @@ -90,6 +90,14 @@ static void diagnosticvf(const char *const fmt, va_list ap) break; } + case 'S': { + const string_t *str = va_arg(ap, const string_t*); + for (size_t i = 0; i < str->size; ++i) { + fputc(str->begin[i], stderr); + } + break; + } + case 'u': { const unsigned int val = va_arg(ap, unsigned int); fprintf(stderr, "%u", val); @@ -113,7 +121,7 @@ static void diagnosticvf(const char *const fmt, va_list ap) case 'Q': { const unsigned qualifiers = va_arg(ap, unsigned); - print_type_qualifiers(qualifiers); + print_type_qualifiers(qualifiers, QUAL_SEP_NONE); break; } @@ -162,6 +170,22 @@ static void diagnosticvf(const char *const fmt, va_list ap) break; } + case 'N': { + entity_t const *const ent = va_arg(ap, entity_t const*); + if (extended && is_declaration(ent)) { + print_type_ext(ent->declaration.type, ent->base.symbol, NULL); + } else { + char const *const kind = get_entity_kind_name(ent->kind); + symbol_t const *const sym = ent->base.symbol; + if (sym) { + fprintf(stderr, "%s %s", kind, sym->string); + } else { + fprintf(stderr, "anonymous %s", kind); + } + } + break; + } + case 'P': { const source_position_t *pos = va_arg(ap, const source_position_t *); print_source_position(stderr, pos); @@ -187,16 +211,25 @@ void diagnosticf(const char *const fmt, ...) va_end(ap); } +static void diagnosticposvf(source_position_t const *const pos, char const *const kind, char const *const fmt, va_list ap) +{ + FILE *const out = stderr; + fprintf(out, "%s:%u:", pos->input_name, pos->lineno); + if (show_column) + fprintf(out, "%u:", pos->colno); + fprintf(out, " %s: ", kind); + curr_pos = pos; + diagnosticvf(fmt, ap); +} + static void errorvf(const source_position_t *pos, const char *const fmt, va_list ap) { - fprintf(stderr, "%s:%u: error: ", pos->input_name, pos->linenr); - ++error_count; curr_pos = pos; - diagnosticvf(fmt, ap); + ++error_count; + diagnosticposvf(pos, "error", fmt, ap); fputc('\n', stderr); - - if (warning.fatal_errors) + if (is_warn_on(WARN_FATAL_ERRORS)) exit(EXIT_FAILURE); } @@ -204,30 +237,34 @@ void errorf(const source_position_t *pos, const char *const fmt, ...) { va_list ap; va_start(ap, fmt); - curr_pos = pos; errorvf(pos, fmt, ap); va_end(ap); } -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; - curr_pos = pos; - diagnosticvf(fmt, ap); - fputc('\n', stderr); -} - -void warningf(const source_position_t *pos, const char *const fmt, ...) +void warningf(warning_t const warn, source_position_t const* pos, char const *const fmt, ...) { va_list ap; va_start(ap, fmt); - curr_pos = pos; - if (warning.s_are_errors) { - errorvf(pos, fmt, ap); - } else { - warningvf(pos, fmt, ap); + warning_switch_t const *const s = get_warn_switch(warn); + switch ((unsigned) s->state) { + char const* kind; + case WARN_STATE_ON: + if (is_warn_on(WARN_ERROR)) { + case WARN_STATE_ON | WARN_STATE_ERROR: + ++error_count; + kind = "error"; + } else { + case WARN_STATE_ON | WARN_STATE_NO_ERROR: + ++warning_count; + kind = "warning"; + } + diagnosticposvf(pos, kind, fmt, ap); + if (diagnostics_show_option) + fprintf(stderr, " [-W%s]\n", s->name); + break; + + default: + break; } va_end(ap); } @@ -235,9 +272,7 @@ void warningf(const source_position_t *pos, const char *const fmt, ...) static void internal_errorvf(const source_position_t *pos, const char *const fmt, va_list ap) { - fprintf(stderr, "%s:%u: internal error: ", pos->input_name, pos->linenr); - curr_pos = pos; - diagnosticvf(fmt, ap); + diagnosticposvf(pos, "internal error", fmt, ap); fputc('\n', stderr); }