]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/diagnostic.h
* dbxout.c: Follow spelling conventions.
[thirdparty/gcc.git] / gcc / diagnostic.h
CommitLineData
993ca5a5 1/* Various declarations for language-independent diagnostics subroutines.
e718c89f 2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
993ca5a5 3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4
f12b58b3 5This file is part of GCC.
993ca5a5 6
f12b58b3 7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 2, or (at your option) any later
10version.
993ca5a5 11
f12b58b3 12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
993ca5a5 16
17You should have received a copy of the GNU General Public License
f12b58b3 18along with GCC; see the file COPYING. If not, write to the Free
19Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2002111-1307, USA. */
993ca5a5 21
2a281353 22#ifndef GCC_DIAGNOSTIC_H
23#define GCC_DIAGNOSTIC_H
993ca5a5 24
25#include "obstack.h"
73b2a785 26#include "location.h"
993ca5a5 27
25e2ffe1 28/* The type of a text to be formatted according a format specification
29 along with a list of things. */
30typedef struct
31{
32 const char *format_spec;
33 va_list *args_ptr;
34} text_info;
993ca5a5 35
25e2ffe1 36/* Contants used to discreminate diagnostics. */
79bef68a 37typedef enum
38{
39#define DEFINE_DIAGNOSTIC_KIND(K, M) K,
40#include "diagnostic.def"
41#undef DEFINE_DIAGNOSTIC_KIND
42 DK_LAST_DIAGNOSTIC_KIND
43} diagnostic_t;
44
25e2ffe1 45/* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
46 its context and its KIND (ice, error, warning, note, ...) See complete
47 list in diagnostic.def. */
48typedef struct
49{
50 text_info message;
51 location_t location;
52 /* The kind of diagnostic it is about. */
53 diagnostic_t kind;
54} diagnostic_info;
55
79bef68a 56#define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
57
9b74c3b4 58/* How often diagnostics are prefixed by their locations:
59 o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
60 o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once;
61 o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical
62 line is started. */
63typedef enum
64{
65 DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0,
66 DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1,
67 DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2
68} diagnostic_prefixing_rule_t;
8c57b41f 69
b52baaa6 70/* This data structure encapsulates an output_buffer's state. */
dfac2e0f 71typedef struct
993ca5a5 72{
a7dce381 73 /* The prefix for each new line. */
990339dd 74 const char *prefix;
a587b03b 75
993ca5a5 76 /* The real upper bound of number of characters per line, taking into
b52baaa6 77 account the case of a very very looong prefix. */
993ca5a5 78 int maximum_length;
a587b03b 79
993ca5a5 80 /* The ideal upper bound of number of characters per line, as suggested
88b5b080 81 by front-end. */
993ca5a5 82 int ideal_maximum_length;
08b0e1fc 83
84 /* Indentation count. */
85 int indent_skip;
86
8c57b41f 87 /* Nonzero if current PREFIX was emitted at least once. */
910f6d8f 88 bool emitted_prefix_p;
b9995fca 89
90 /* Nonzero means one should emit a newline before outputing anything. */
910f6d8f 91 bool need_newline_p;
b9995fca 92
9b74c3b4 93 /* Current prefixing rule. */
94 diagnostic_prefixing_rule_t prefixing_rule;
dfac2e0f 95} output_state;
96
25e2ffe1 97/* The type of a hook that formats client-specific data (trees mostly) into
98 an output_buffer. A client-supplied formatter returns true if everything
99 goes well. */
100typedef struct output_buffer output_buffer;
101typedef bool (*printer_fn) PARAMS ((output_buffer *, text_info *));
102
5397e5a3 103/* The output buffer datatype. This is best seen as an abstract datatype
104 whose fields should not be accessed directly by clients. */
dfac2e0f 105struct output_buffer
106{
a587b03b 107 /* The current state of the buffer. */
108 output_state state;
109
83af9cb1 110 /* Where to output formatted text. */
111 FILE* stream;
a587b03b 112
dfac2e0f 113 /* The obstack where the text is built up. */
114 struct obstack obstack;
a587b03b 115
dfac2e0f 116 /* The amount of characters output so far. */
117 int line_length;
631fae11 118
119 /* This must be large enough to hold any printed integer or
120 floating-point value. */
121 char digit_buffer[128];
b165d8b0 122
25e2ffe1 123 /* If non-NULL, this function formats a TEXT into the BUFFER. When called,
124 TEXT->format_spec points to a format code. FORMAT_DECODER should call
125 output_add_string (and related functions) to add data to the BUFFER.
126 FORMAT_DECODER can read arguments from *TEXT->args_pts using VA_ARG.
127 If the BUFFER needs additional characters from the format string, it
128 should advance the TEXT->format_spec as it goes. When FORMAT_DECODER
129 returns, TEXT->format_spec should point to the last character processed.
130 */
b165d8b0 131 printer_fn format_decoder;
25e2ffe1 132} ;
993ca5a5 133
25e2ffe1 134#define output_prefix(BUFFER) (BUFFER)->state.prefix
910f6d8f 135
136/* The stream attached to the output_buffer, where the formatted
137 diagnostics will ultimately go. Works only on `output_buffer *'. */
83af9cb1 138#define output_buffer_attached_stream(BUFFER) (BUFFER)->stream
910f6d8f 139
910f6d8f 140/* In line-wrapping mode, whether we should start a new line. */
b9995fca 141#define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
910f6d8f 142
143/* The amount of whitespace to be emitted when starting a new line. */
08b0e1fc 144#define output_indentation(BUFFER) (BUFFER)->state.indent_skip
910f6d8f 145
5397e5a3 146/* A pointer to the formatted diagnostic message. */
29793aad 147#define output_message_text(BUFFER) \
148 ((const char *) obstack_base (&(BUFFER)->obstack))
dfac2e0f 149
06c7407c 150/* Client supplied function used to decode formats. */
151#define output_format_decoder(BUFFER) (BUFFER)->format_decoder
152
153/* Prefixing rule used in formatting a diagnostic message. */
154#define output_prefixing_rule(BUFFER) (BUFFER)->state.prefixing_rule
155
156/* Maximum characters per line in automatic line wrapping mode.
157 Zero means don't wrap lines. */
158#define output_line_cutoff(BUFFER) (BUFFER)->state.ideal_maximum_length
159
25e2ffe1 160/* True if BUFFER is in line-wrapping mode. */
161#define output_is_line_wrapping(BUFFER) (output_line_cutoff (BUFFER) > 0)
162
8e10b18f 163#define output_formatted_scalar(BUFFER, FORMAT, INTEGER) \
b38e286c 164 do \
165 { \
166 sprintf ((BUFFER)->digit_buffer, FORMAT, INTEGER); \
167 output_add_string (BUFFER, (BUFFER)->digit_buffer); \
168 } \
169 while (0)
170
25e2ffe1 171/* Forward declarations. */
172typedef struct diagnostic_context diagnostic_context;
173typedef void (*diagnostic_starter_fn) PARAMS ((diagnostic_context *,
174 diagnostic_info *));
175typedef diagnostic_starter_fn diagnostic_finalizer_fn;
176
b52baaa6 177/* This data structure bundles altogether any information relevant to
92d99247 178 the context of a diagnostic message. */
179struct diagnostic_context
180{
ce601f29 181 /* Where most of the diagnostic formatting work is done. In Object
182 Oriented terms, we'll say that diagnostic_context is a sub-class of
183 output_buffer. */
184 output_buffer buffer;
185
5397e5a3 186 /* The number of times we have issued diagnostics. */
187 int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
188
a787dd05 189 /* True if we should display the "warnings are being tread as error"
190 message, usually displayed once per compiler run. */
191 bool warnings_are_errors_message;
192
92d99247 193 /* This function is called before any message is printed out. It is
b52baaa6 194 responsible for preparing message prefix and such. For example, it
92d99247 195 might say:
196 In file included from "/usr/local/include/curses.h:5:
197 from "/home/gdr/src/nifty_printer.h:56:
198 ...
199 */
25e2ffe1 200 diagnostic_starter_fn begin_diagnostic;
92d99247 201
a7dce381 202 /* This function is called after the diagnostic message is printed. */
25e2ffe1 203 diagnostic_finalizer_fn end_diagnostic;
92d99247 204
c003992a 205 /* Client hook to report an internal error. */
206 void (*internal_error) PARAMS ((const char *, va_list *));
207
25e2ffe1 208 /* Function of last diagnostic message; more generally, function such that
209 if next diagnostic message is in it then we don't have to mention the
210 function name. */
211 tree last_function;
212
213 /* Used to detect when input_file_stack has changed since last described. */
214 int last_module;
215
216 int lock;
217
92d99247 218 /* Hook for front-end extensions. */
219 void *x_data;
220};
221
910f6d8f 222/* Client supplied function to announce a diagnostic. */
92d99247 223#define diagnostic_starter(DC) (DC)->begin_diagnostic
910f6d8f 224
225/* Client supplied function called after a diagnostic message is
226 displayed. */
92d99247 227#define diagnostic_finalizer(DC) (DC)->end_diagnostic
910f6d8f 228
dd5b4b36 229/* Extension hook for client. */
92d99247 230#define diagnostic_auxiliary_data(DC) (DC)->x_data
910f6d8f 231
06c7407c 232/* Same as output_format_decoder. Works on 'diagnostic_context *'. */
233#define diagnostic_format_decoder(DC) output_format_decoder (&(DC)->buffer)
910f6d8f 234
06c7407c 235/* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */
236#define diagnostic_prefixing_rule(DC) output_prefixing_rule (&(DC)->buffer)
92d99247 237
b165d8b0 238/* Maximum characters per line in automatic line wrapping mode.
88b5b080 239 Zero means don't wrap lines. */
06c7407c 240#define diagnostic_line_cutoff(DC) output_line_cutoff (&(DC)->buffer)
241
25e2ffe1 242/* True if the last function in which a diagnostic was reported is
243 different from the current one. */
244#define diagnostic_last_function_changed(DC) \
245 ((DC)->last_function != current_function_decl)
246
247/* Remember the current function as being the last one in which we report
248 a diagnostic. */
249#define diagnostic_set_last_function(DC) \
250 (DC)->last_function = current_function_decl
251
252/* True if the last module or file in which a diagnostic was reported is
253 different from the current one. */
254#define diagnostic_last_module_changed(DC) \
255 ((DC)->last_module != input_file_stack_tick)
06c7407c 256
25e2ffe1 257/* Remember the current module or file as being the last one in which we
258 report a diagnostic. */
259#define diagnostic_set_last_module(DC) \
260 (DC)->last_module = input_file_stack_tick
990339dd 261
5397e5a3 262/* This diagnostic_context is used by front-ends that directly output
990339dd 263 diagnostic messages without going through `error', `warning',
910f6d8f 264 and similar functions. */
ce601f29 265extern diagnostic_context *global_dc;
990339dd 266
910f6d8f 267/* The total count of a KIND of diagnostics meitted so far. */
5397e5a3 268#define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)]
a587b03b 269
270/* The number of errors that have been issued so far. Ideally, these
5397e5a3 271 would take a diagnostic_context as an argument. */
910f6d8f 272#define errorcount diagnostic_kind_count (global_dc, DK_ERROR)
a587b03b 273/* Similarly, but for warnings. */
910f6d8f 274#define warningcount diagnostic_kind_count (global_dc, DK_WARNING)
a587b03b 275/* Similarly, but for sorrys. */
910f6d8f 276#define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
a587b03b 277
6ef828f9 278/* Returns nonzero if warnings should be emitted. */
a587b03b 279#define diagnostic_report_warnings_p() \
280 (!inhibit_warnings \
281 && !(in_system_header && !warn_system_headers))
282
25e2ffe1 283#define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D)
a587b03b 284
25e2ffe1 285/* Dignostic related functions. */
b165d8b0 286extern void diagnostic_initialize PARAMS ((diagnostic_context *));
25e2ffe1 287extern void diagnostic_report_current_module PARAMS ((diagnostic_context *));
288extern void diagnostic_report_current_function PARAMS ((diagnostic_context *));
289extern void diagnostic_flush_buffer PARAMS ((diagnostic_context *));
a787dd05 290extern bool diagnostic_count_diagnostic PARAMS ((diagnostic_context *,
25e2ffe1 291 diagnostic_t));
292extern void diagnostic_report_diagnostic PARAMS ((diagnostic_context *,
293 diagnostic_info *));
294extern void diagnostic_set_info PARAMS ((diagnostic_info *,
295 const char *, va_list *,
296 const char *, int,
297 diagnostic_t));
298extern char *diagnostic_build_prefix PARAMS ((diagnostic_info *));
299
300/* Pure text formatting support functions. */
bccf563b 301extern void init_output_buffer PARAMS ((output_buffer *,
302 const char *, int));
bccf563b 303extern void output_clear PARAMS ((output_buffer *));
bccf563b 304extern const char *output_last_position PARAMS ((const output_buffer *));
305extern void output_set_prefix PARAMS ((output_buffer *,
306 const char *));
307extern void output_destroy_prefix PARAMS ((output_buffer *));
b165d8b0 308extern void output_set_maximum_length PARAMS ((output_buffer *, int));
bccf563b 309extern void output_emit_prefix PARAMS ((output_buffer *));
310extern void output_add_newline PARAMS ((output_buffer *));
311extern void output_add_space PARAMS ((output_buffer *));
312extern int output_space_left PARAMS ((const output_buffer *));
313extern void output_append PARAMS ((output_buffer *, const char *,
314 const char *));
315extern void output_add_character PARAMS ((output_buffer *, int));
316extern void output_decimal PARAMS ((output_buffer *, int));
317extern void output_add_string PARAMS ((output_buffer *,
318 const char *));
9ba44007 319extern void output_add_identifier PARAMS ((output_buffer *, tree));
bccf563b 320extern const char *output_finalize_message PARAMS ((output_buffer *));
321extern void output_clear_message_text PARAMS ((output_buffer *));
322extern void output_printf PARAMS ((output_buffer *, const char *,
323 ...)) ATTRIBUTE_PRINTF_2;
bccf563b 324extern void output_verbatim PARAMS ((output_buffer *, const char *,
325 ...)) ATTRIBUTE_PRINTF_2;
326extern void verbatim PARAMS ((const char *, ...))
327 ATTRIBUTE_PRINTF_1;
bccf563b 328extern char *file_name_as_prefix PARAMS ((const char *));
8e10b18f 329extern void inform PARAMS ((const char *, ...));
993ca5a5 330
2a281353 331#endif /* ! GCC_DIAGNOSTIC_H */