source: trunk/src/gcc/gcc/diagnostic.h@ 2

Last change on this file since 2 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 12.2 KB
Line 
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>
4
5This file is part of GCC.
6
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.
11
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.
16
17You should have received a copy of the GNU General Public License
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. */
21
22#ifndef GCC_DIAGNOSTIC_H
23#define GCC_DIAGNOSTIC_H
24
25#include "obstack.h"
26
27/* Forward declarations. */
28typedef struct output_buffer output_buffer;
29typedef struct diagnostic_context diagnostic_context;
30typedef void (*diagnostic_starter_fn) PARAMS ((output_buffer *,
31 diagnostic_context *));
32typedef diagnostic_starter_fn diagnostic_finalizer_fn;
33
34typedef enum
35{
36#define DEFINE_DIAGNOSTIC_KIND(K, M) K,
37#include "diagnostic.def"
38#undef DEFINE_DIAGNOSTIC_KIND
39 DK_LAST_DIAGNOSTIC_KIND
40} diagnostic_t;
41
42#define pedantic_error_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
43
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
48 line is started. */
49typedef enum
50{
51 DIAGNOSTICS_SHOW_PREFIX_ONCE = 0x0,
52 DIAGNOSTICS_SHOW_PREFIX_NEVER = 0x1,
53 DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE = 0x2
54} diagnostic_prefixing_rule_t;
55
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. */
59typedef int (*printer_fn) PARAMS ((output_buffer *));
60
61/* This data structure encapsulates an output_buffer's state. */
62typedef struct
63{
64 /* The prefix for each new line. */
65 const char *prefix;
66
67 /* The real upper bound of number of characters per line, taking into
68 account the case of a very very looong prefix. */
69 int maximum_length;
70
71 /* The ideal upper bound of number of characters per line, as suggested
72 by front-end. */
73 int ideal_maximum_length;
74
75 /* Indentation count. */
76 int indent_skip;
77
78 /* Nonzero if current PREFIX was emitted at least once. */
79 bool emitted_prefix_p;
80
81 /* Nonzero means one should emit a newline before outputing anything. */
82 bool need_newline_p;
83
84 /* Current prefixing rule. */
85 diagnostic_prefixing_rule_t prefixing_rule;
86
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. */
89 const char *cursor;
90
91 /* A pointer to the variable argument-list for formatting. */
92 va_list *format_args;
93
94 /* The number of times we have issued diagnostics. */
95 int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
96} output_state;
97
98/* The output buffer datatype. This is best seen as an abstract datatype. */
99struct output_buffer
100{
101 /* Internal data. These fields should not be accessed directly by
102 front-ends. */
103
104 /* The current state of the buffer. */
105 output_state state;
106
107 /* Where to output formatted text. */
108 FILE* stream;
109
110 /* The obstack where the text is built up. */
111 struct obstack obstack;
112
113 /* The amount of characters output so far. */
114 int line_length;
115
116 /* This must be large enough to hold any printed integer or
117 floating-point value. */
118 char digit_buffer[128];
119
120/* If non-NULL, this function formats data in the BUFFER. When called,
121 output_buffer_text_cursor (BUFFER) points to a format code.
122 FORMAT_DECODER should call output_add_string (and related functions)
123 to add data to the BUFFER. FORMAT_DECODER can read arguments from
124 output_buffer_format_args (BUFFER) using VA_ARG. If the BUFFER needs
125 additional characters from the format string, it should advance
126 the output_buffer_text_cursor (BUFFER) as it goes. When FORMAT_DECODER
127 returns, output_buffer_text_cursor (BUFFER) should point to the last
128 character processed. */
129
130 printer_fn format_decoder;
131};
132
133/* Current state of the diagnostic_context' output_buffer. This macro
134 accepts both `diagnostic_context *' and `output_buffer *'. */
135#define output_buffer_state(BUFFER) ((output_buffer *)(BUFFER))->state
136
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
140
141/* This points to the beginning of the rest of the diagnostic message
142 to be formatted. Accepts only `output_buffer *'s. */
143#define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor
144
145/* The rest of the `variable argument list' not yet processed.
146 This macro works on both `output_state *' and `output_buffer *'. */
147#define output_buffer_format_args(BUFFER) \
148 *(((output_state *)(BUFFER))->format_args)
149
150/* In line-wrapping mode, whether we should start a new line. */
151#define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
152
153/* The amount of whitespace to be emitted when starting a new line. */
154#define output_indentation(BUFFER) (BUFFER)->state.indent_skip
155
156/* A pointer to the formatted diagonstic message. */
157#define output_message_text(BUFFER) \
158 ((const char *) obstack_base (&(BUFFER)->obstack))
159
160/* This data structure bundles altogether any information relevant to
161 the context of a diagnostic message. */
162struct diagnostic_context
163{
164 /* Where most of the diagnostic formatting work is done. In Object
165 Oriented terms, we'll say that diagnostic_context is a sub-class of
166 output_buffer. */
167 output_buffer buffer;
168
169 /* The diagnostic message to output. */
170 const char *message;
171
172 /* A pointer to a variable list of the arguments necessary for the
173 purpose of message formatting. */
174 va_list *args_ptr;
175
176 /* The name of the source file involved in the diiagnostic. */
177 const char *file;
178
179 /* The line-location in the source file. */
180 int line;
181
182 /* Is this message a warning? */
183 int warn;
184
185 /* This function is called before any message is printed out. It is
186 responsible for preparing message prefix and such. For example, it
187 might say:
188 In file included from "/usr/local/include/curses.h:5:
189 from "/home/gdr/src/nifty_printer.h:56:
190 ...
191 */
192 void (*begin_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
193
194 /* This function is called after the diagnostic message is printed. */
195 void (*end_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
196
197 /* Hook for front-end extensions. */
198 void *x_data;
199};
200
201/* The diagnostic message being formatted. */
202#define diagnostic_message(DC) (DC)->message
203
204/* A pointer to the variable argument list used in a call
205 to a diagonstic routine. */
206#define diagnostic_argument_list(DC) (DC)->args_ptr
207
208/* The program file to which the diagnostic is referring to. */
209#define diagnostic_file_location(DC) (DC)->file
210
211/* The program source line referred to in the diagnostic message. */
212#define diagnostic_line_location(DC) (DC)->line
213
214/* Tell whether the diagnostic message is to be treated as a warning. */
215#define diagnostic_is_warning(DC) (DC)->warn
216
217/* Client supplied function to announce a diagnostic. */
218#define diagnostic_starter(DC) (DC)->begin_diagnostic
219
220/* Client supplied function called after a diagnostic message is
221 displayed. */
222#define diagnostic_finalizer(DC) (DC)->end_diagnostic
223
224/* Extension hook for client. */
225#define diagnostic_auxiliary_data(DC) (DC)->x_data
226
227/* Client supplied function used to decode formats. Can operate on both
228 `output_buffer *' and `diagnostic_context *'. */
229#define diagnostic_format_decoder(DC) ((output_buffer *)(DC))->format_decoder
230
231/* Prefixing rule used in formatting a diagnostic message. Accepts both
232 `output_buffer *' and `diagnostic_context *'. */
233#define diagnostic_prefixing_rule(DC) \
234 ((output_buffer *)(DC))->state.prefixing_rule
235
236/* Maximum characters per line in automatic line wrapping mode.
237 Zero means don't wrap lines. */
238#define diagnostic_line_cutoff(DC) \
239 ((output_buffer *)(DC))->state.ideal_maximum_length
240
241/* This diagnostic context is used by front-ends that directly output
242 diagnostic messages without going through `error', `warning',
243 and similar functions. */
244extern diagnostic_context *global_dc;
245
246/* This will be removed shortly. */
247extern output_buffer *diagnostic_buffer;
248
249/* The total count of a KIND of diagnostics meitted so far. */
250#define diagnostic_kind_count(DC, DK) \
251 ((output_buffer *)(DC))->state.diagnostic_count[(int) (DK)]
252
253/* The number of errors that have been issued so far. Ideally, these
254 would take an output_buffer as an argument. */
255#define errorcount diagnostic_kind_count (global_dc, DK_ERROR)
256/* Similarly, but for warnings. */
257#define warningcount diagnostic_kind_count (global_dc, DK_WARNING)
258/* Similarly, but for sorrys. */
259#define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
260
261/* Returns non-zero if warnings should be emitted. */
262#define diagnostic_report_warnings_p() \
263 (!inhibit_warnings \
264 && !(in_system_header && !warn_system_headers))
265
266
267/* Prototypes */
268extern void set_diagnostic_context PARAMS ((diagnostic_context *,
269 const char *, va_list *,
270 const char *, int, int));
271extern void set_internal_error_function PARAMS ((void (*)
272 PARAMS ((const char *,
273 va_list *))));
274extern void report_diagnostic PARAMS ((diagnostic_context *));
275extern void diagnostic_initialize PARAMS ((diagnostic_context *));
276extern void init_output_buffer PARAMS ((output_buffer *,
277 const char *, int));
278extern void flush_diagnostic_buffer PARAMS ((void));
279extern void output_clear PARAMS ((output_buffer *));
280extern const char *output_get_prefix PARAMS ((const output_buffer *));
281extern const char *output_last_position PARAMS ((const output_buffer *));
282extern void output_set_prefix PARAMS ((output_buffer *,
283 const char *));
284extern void output_destroy_prefix PARAMS ((output_buffer *));
285extern void output_set_maximum_length PARAMS ((output_buffer *, int));
286extern void output_emit_prefix PARAMS ((output_buffer *));
287extern void output_add_newline PARAMS ((output_buffer *));
288extern void output_add_space PARAMS ((output_buffer *));
289extern int output_space_left PARAMS ((const output_buffer *));
290extern void output_append PARAMS ((output_buffer *, const char *,
291 const char *));
292extern void output_add_character PARAMS ((output_buffer *, int));
293extern void output_decimal PARAMS ((output_buffer *, int));
294extern void output_add_string PARAMS ((output_buffer *,
295 const char *));
296extern const char *output_finalize_message PARAMS ((output_buffer *));
297extern void output_clear_message_text PARAMS ((output_buffer *));
298extern void output_printf PARAMS ((output_buffer *, const char *,
299 ...)) ATTRIBUTE_PRINTF_2;
300extern int output_is_line_wrapping PARAMS ((output_buffer *));
301extern void output_verbatim PARAMS ((output_buffer *, const char *,
302 ...)) ATTRIBUTE_PRINTF_2;
303extern void verbatim PARAMS ((const char *, ...))
304 ATTRIBUTE_PRINTF_1;
305extern char *context_as_prefix PARAMS ((const char *, int, int));
306extern char *file_name_as_prefix PARAMS ((const char *));
307extern int error_module_changed PARAMS ((void));
308extern void record_last_error_module PARAMS ((void));
309extern int error_function_changed PARAMS ((void));
310extern void record_last_error_function PARAMS ((void));
311extern void report_problematic_module PARAMS ((output_buffer *));
312
313/* Called by report_error_function to print out function name.
314 * Default may be overridden by language front-ends. */
315extern void (*print_error_function) PARAMS ((diagnostic_context *,
316 const char *));
317
318extern void default_print_error_function PARAMS ((diagnostic_context *,
319 const char *));
320
321#endif /* ! GCC_DIAGNOSTIC_H */
Note: See TracBrowser for help on using the repository browser.