2 * This file is part of cparser.
3 * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include "adt/error.h"
25 #include "diagnostic.h"
30 /** Number of occurred diagnostics. */
31 unsigned diagnostic_count = 0;
32 /** Number of occurred errors. */
33 unsigned error_count = 0;
34 /** Number of occurred warnings. */
35 unsigned warning_count = 0;
36 /** true if warnings should be inhibited */
37 bool inhibit_all_warnings = false;
40 * Issue a diagnostic message.
42 static void diagnosticvf(const char *const fmt, va_list ap)
44 for (const char* f = fmt; *f != '\0'; ++f) {
48 bool extended = false;
60 const wint_t val = va_arg(ap, wint_t);
66 const unsigned char val = (unsigned char) va_arg(ap, int);
72 const int val = va_arg(ap, int);
73 fprintf(stderr, "%d", val);
78 const char* const str = va_arg(ap, const char*);
84 const symbol_t *const symbol = va_arg(ap, const symbol_t*);
85 fputs(symbol->string, stderr);
90 const expression_t* const expr = va_arg(ap, const expression_t*);
91 print_expression(expr);
96 const unsigned qualifiers = va_arg(ap, unsigned);
97 print_type_qualifiers(qualifiers);
102 const type_t* const type = va_arg(ap, const type_t*);
103 const symbol_t* sym = NULL;
105 sym = va_arg(ap, const symbol_t*);
107 print_type_ext(type, sym, NULL);
112 const token_t* const token = va_arg(ap, const token_t*);
113 print_token(stderr, token);
120 va_list* toks = va_arg(ap, va_list*);
121 const char* const delimiter = va_arg(ap, const char*);
123 const token_type_t tok = va_arg(*toks, token_type_t);
129 fputs(delimiter, stderr);
131 print_token_type(stderr, tok);
134 const token_type_t token = va_arg(ap, token_type_t);
135 print_token_type(stderr, token);
141 panic("unknown format specifier");
149 void diagnosticf(const char *const fmt, ...)
154 diagnosticvf(fmt, ap);
158 static void errorvf(const source_position_t pos,
159 const char *const fmt, va_list ap)
161 fprintf(stderr, "%s:%u: error: ", pos.input_name, pos.linenr);
163 diagnosticvf(fmt, ap);
166 if (warning.fatal_errors)
170 void errorf(const source_position_t pos, const char *const fmt, ...)
174 errorvf(pos, fmt, ap);
178 static void warningvf(const source_position_t pos,
179 const char *const fmt, va_list ap)
181 fprintf(stderr, "%s:%u: warning: ", pos.input_name, pos.linenr);
183 diagnosticvf(fmt, ap);
187 void warningf(const source_position_t pos, const char *const fmt, ...)
189 if (inhibit_all_warnings)
194 if (warning.s_are_errors) {
195 errorvf(pos, fmt, ap);
197 warningvf(pos, fmt, ap);