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