OSDN Git Service

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