1 /* Various declarations for language-independent diagnostics subroutines.
2 Copyright (C) 2000, 2001, 2002 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
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
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
22 #ifndef GCC_DIAGNOSTIC_H
23 #define GCC_DIAGNOSTIC_H
27 /* Forward declarations. */
28 typedef struct output_buffer output_buffer;
29 typedef struct diagnostic_context diagnostic_context;
30 typedef void (*diagnostic_starter_fn) PARAMS ((output_buffer *,
31 diagnostic_context *));
32 typedef diagnostic_starter_fn diagnostic_finalizer_fn;
36 #define DEFINE_DIAGNOSTIC_KIND(K, M) K,
37 #include "diagnostic.def"
38 #undef DEFINE_DIAGNOSTIC_KIND
39 DK_LAST_DIAGNOSTIC_KIND
42 #define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
44 /* How often diagnostics are prefixed by their locations:
45 o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
46 o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit only once;
47 o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit each time a physical
51 DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0,
52 DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1,
53 DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2
54 } diagnostic_prefixing_rule_t;
56 /* The type of front-end specific hook that formats trees into an
57 output_buffer. A language specific printer returns a truth value if
58 everything goes well. */
59 typedef int (*printer_fn) PARAMS ((output_buffer *));
61 /* This data structure encapsulates an output_buffer's state. */
64 /* The prefix for each new line. */
67 /* The real upper bound of number of characters per line, taking into
68 account the case of a very very looong prefix. */
71 /* The ideal upper bound of number of characters per line, as suggested
73 int ideal_maximum_length;
75 /* Indentation count. */
78 /* Nonzero if current PREFIX was emitted at least once. */
79 bool emitted_prefix_p;
81 /* Nonzero means one should emit a newline before outputing anything. */
84 /* Current prefixing rule. */
85 diagnostic_prefixing_rule_t prefixing_rule;
87 /* The current char to output. Updated by front-end (*format_map) when
88 it is called to report front-end printer for a specified format. */
91 /* A pointer to the variable argument-list for formatting. */
95 /* The output buffer datatype. This is best seen as an abstract datatype
96 whose fields should not be accessed directly by clients. */
99 /* The current state of the buffer. */
102 /* Where to output formatted text. */
105 /* The obstack where the text is built up. */
106 struct obstack obstack;
108 /* The amount of characters output so far. */
111 /* This must be large enough to hold any printed integer or
112 floating-point value. */
113 char digit_buffer[128];
115 /* If non-NULL, this function formats data in the BUFFER. When called,
116 output_buffer_text_cursor (BUFFER) points to a format code.
117 FORMAT_DECODER should call output_add_string (and related functions)
118 to add data to the BUFFER. FORMAT_DECODER can read arguments from
119 output_buffer_format_args (BUFFER) using VA_ARG. If the BUFFER needs
120 additional characters from the format string, it should advance
121 the output_buffer_text_cursor (BUFFER) as it goes. When FORMAT_DECODER
122 returns, output_buffer_text_cursor (BUFFER) should point to the last
123 character processed. */
125 printer_fn format_decoder;
128 /* Current state of an output_buffer. */
129 #define output_buffer_state(BUFFER) (BUFFER)->state
131 /* The stream attached to the output_buffer, where the formatted
132 diagnostics will ultimately go. Works only on `output_buffer *'. */
133 #define output_buffer_attached_stream(BUFFER) (BUFFER)->stream
135 /* This points to the beginning of the rest of the diagnostic message
136 to be formatted. Accepts only `output_buffer *'s. */
137 #define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor
139 /* The rest of the `variable argument list' not yet processed.
140 This macro works on both `output_state *' and `output_buffer *'. */
141 #define output_buffer_format_args(BUFFER) \
142 *(((output_state *)(BUFFER))->format_args)
144 /* In line-wrapping mode, whether we should start a new line. */
145 #define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
147 /* The amount of whitespace to be emitted when starting a new line. */
148 #define output_indentation(BUFFER) (BUFFER)->state.indent_skip
150 /* A pointer to the formatted diagnostic message. */
151 #define output_message_text(BUFFER) \
152 ((const char *) obstack_base (&(BUFFER)->obstack))
154 /* Client supplied function used to decode formats. */
155 #define output_format_decoder(BUFFER) (BUFFER)->format_decoder
157 /* Prefixing rule used in formatting a diagnostic message. */
158 #define output_prefixing_rule(BUFFER) (BUFFER)->state.prefixing_rule
160 /* Maximum characters per line in automatic line wrapping mode.
161 Zero means don't wrap lines. */
162 #define output_line_cutoff(BUFFER) (BUFFER)->state.ideal_maximum_length
164 /* This data structure bundles altogether any information relevant to
165 the context of a diagnostic message. */
166 struct diagnostic_context
168 /* Where most of the diagnostic formatting work is done. In Object
169 Oriented terms, we'll say that diagnostic_context is a sub-class of
171 output_buffer buffer;
173 /* The diagnostic message to output. */
176 /* A pointer to a variable list of the arguments necessary for the
177 purpose of message formatting. */
180 /* The name of the source file involved in the diagnostic. */
183 /* The line-location in the source file. */
186 /* Is this message a warning? */
189 /* The number of times we have issued diagnostics. */
190 int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
192 /* This function is called before any message is printed out. It is
193 responsible for preparing message prefix and such. For example, it
195 In file included from "/usr/local/include/curses.h:5:
196 from "/home/gdr/src/nifty_printer.h:56:
199 void (*begin_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
201 /* This function is called after the diagnostic message is printed. */
202 void (*end_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
204 /* Client hook to report an internal error. */
205 void (*internal_error) PARAMS ((const char *, va_list *));
207 /* Hook for front-end extensions. */
211 /* The diagnostic message being formatted. */
212 #define diagnostic_message(DC) (DC)->message
214 /* A pointer to the variable argument list used in a call
215 to a diagonstic routine. */
216 #define diagnostic_argument_list(DC) (DC)->args_ptr
218 /* The program file to which the diagnostic is referring to. */
219 #define diagnostic_file_location(DC) (DC)->file
221 /* The program source line referred to in the diagnostic message. */
222 #define diagnostic_line_location(DC) (DC)->line
224 /* Tell whether the diagnostic message is to be treated as a warning. */
225 #define diagnostic_is_warning(DC) (DC)->warn
227 /* Client supplied function to announce a diagnostic. */
228 #define diagnostic_starter(DC) (DC)->begin_diagnostic
230 /* Client supplied function called after a diagnostic message is
232 #define diagnostic_finalizer(DC) (DC)->end_diagnostic
234 /* Extension hook for client. */
235 #define diagnostic_auxiliary_data(DC) (DC)->x_data
237 /* Same as output_format_decoder. Works on 'diagnostic_context *'. */
238 #define diagnostic_format_decoder(DC) output_format_decoder (&(DC)->buffer)
240 /* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */
241 #define diagnostic_prefixing_rule(DC) output_prefixing_rule (&(DC)->buffer)
243 /* Maximum characters per line in automatic line wrapping mode.
244 Zero means don't wrap lines. */
245 #define diagnostic_line_cutoff(DC) output_line_cutoff (&(DC)->buffer)
247 /* Same as output_buffer_state, but works on 'diagnostic_context *'. */
248 #define diagnostic_state(DC) output_buffer_state (&(DC)->buffer)
250 #define diagnostic_buffer (&global_dc->buffer)
252 /* This diagnostic_context is used by front-ends that directly output
253 diagnostic messages without going through `error', `warning',
254 and similar functions. */
255 extern diagnostic_context *global_dc;
257 /* The total count of a KIND of diagnostics meitted so far. */
258 #define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)]
260 /* The number of errors that have been issued so far. Ideally, these
261 would take a diagnostic_context as an argument. */
262 #define errorcount diagnostic_kind_count (global_dc, DK_ERROR)
263 /* Similarly, but for warnings. */
264 #define warningcount diagnostic_kind_count (global_dc, DK_WARNING)
265 /* Similarly, but for sorrys. */
266 #define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
268 /* Returns non-zero if warnings should be emitted. */
269 #define diagnostic_report_warnings_p() \
271 && !(in_system_header && !warn_system_headers))
275 extern void set_diagnostic_context PARAMS ((diagnostic_context *,
276 const char *, va_list *,
277 const char *, int, int));
278 extern void report_diagnostic PARAMS ((diagnostic_context *));
279 extern void diagnostic_initialize PARAMS ((diagnostic_context *));
280 extern void init_output_buffer PARAMS ((output_buffer *,
282 extern void flush_diagnostic_buffer PARAMS ((void));
283 extern void output_clear PARAMS ((output_buffer *));
284 extern const char *output_get_prefix PARAMS ((const output_buffer *));
285 extern const char *output_last_position PARAMS ((const output_buffer *));
286 extern void output_set_prefix PARAMS ((output_buffer *,
288 extern void output_destroy_prefix PARAMS ((output_buffer *));
289 extern void output_set_maximum_length PARAMS ((output_buffer *, int));
290 extern void output_emit_prefix PARAMS ((output_buffer *));
291 extern void output_add_newline PARAMS ((output_buffer *));
292 extern void output_add_space PARAMS ((output_buffer *));
293 extern int output_space_left PARAMS ((const output_buffer *));
294 extern void output_append PARAMS ((output_buffer *, const char *,
296 extern void output_add_character PARAMS ((output_buffer *, int));
297 extern void output_decimal PARAMS ((output_buffer *, int));
298 extern void output_add_string PARAMS ((output_buffer *,
300 extern const char *output_finalize_message PARAMS ((output_buffer *));
301 extern void output_clear_message_text PARAMS ((output_buffer *));
302 extern void output_printf PARAMS ((output_buffer *, const char *,
303 ...)) ATTRIBUTE_PRINTF_2;
304 extern int output_is_line_wrapping PARAMS ((output_buffer *));
305 extern void output_verbatim PARAMS ((output_buffer *, const char *,
306 ...)) ATTRIBUTE_PRINTF_2;
307 extern void verbatim PARAMS ((const char *, ...))
309 extern char *context_as_prefix PARAMS ((const char *, int, int));
310 extern char *file_name_as_prefix PARAMS ((const char *));
311 extern int error_module_changed PARAMS ((void));
312 extern void record_last_error_module PARAMS ((void));
313 extern int error_function_changed PARAMS ((void));
314 extern void record_last_error_function PARAMS ((void));
315 extern void report_problematic_module PARAMS ((output_buffer *));
317 #endif /* ! GCC_DIAGNOSTIC_H */