OSDN Git Service

wchar_t now gets wrapped inside "ifndef __cplusplus",
[pf3gnuchains/gcc-fork.git] / gcc / diagnostic.h
1 /* Various declarations for language-independent diagnostics subroutines.
2    Copyright (C) 2000, 2001 Free Software Foundation, Inc.
3    Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22 #ifndef GCC_DIAGNOSTIC_H
23 #define GCC_DIAGNOSTIC_H
24
25 #include "obstack.h"
26
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;
33
34 typedef 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 #define DIAGNOSTICS_SHOW_PREFIX_ONCE       0x0
45 #define DIAGNOSTICS_SHOW_PREFIX_NEVER      0x1
46 #define DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE 0x2
47
48 /* The type of front-end specific hook that formats trees into an
49    output_buffer.  A language specific printer returns a truth value if
50    everything goes well. */
51 typedef int (*printer_fn) PARAMS ((output_buffer *));
52
53 /* This data structure encapsulates an output_buffer's state.  */
54 typedef struct
55 {
56   /* The prefix for each new line.   */
57   const char *prefix;
58   /* The real upper bound of number of characters per line, taking into
59      account the case of a very very looong prefix.  */  
60   int maximum_length;
61   /* The ideal upper bound of number of characters per line, as suggested
62      by front-end. */  
63   int ideal_maximum_length;
64
65   /* Indentation count.  */
66   int indent_skip;
67
68   /* Nonzero if current PREFIX was emitted at least once.  */
69   int emitted_prefix_p;
70
71   /* Nonzero means one should emit a newline before outputing anything.  */
72   int need_newline_p;
73
74   /* Tells how often current PREFIX should be emitted:
75      o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
76      o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit current PREFIX only once;
77      o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit current PREFIX each time
78        a physical line is started.  */
79   int prefixing_rule;
80   /* The current char to output.  Updated by front-end (*format_map) when
81      it is called to report front-end printer for a specified format.  */  
82   const char *cursor;
83   /* A pointer to the variable argument-list for formatting.  */  
84   va_list *format_args;
85 } output_state;
86
87 /* The output buffer datatype.  This is best seen as an abstract datatype.  */
88 struct output_buffer
89 {
90   /* Internal data.  These fields should not be accessed directly by
91      front-ends.  */
92
93   /* Where to output formatted text.  */
94   FILE* stream;
95   /* The obstack where the text is built up.  */  
96   struct obstack obstack;
97   /* The amount of characters output so far.  */  
98   int line_length;
99   /* The current state of the buffer.  */
100   output_state state;
101 };
102
103 #define output_buffer_attached_stream(BUFFER) (BUFFER)->stream
104 #define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor
105 #define output_buffer_format_args(BUFFER) *((BUFFER)->state.format_args)
106 #define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
107 #define output_buffer_state(BUFFER) (BUFFER)->state
108 #define output_indentation(BUFFER) (BUFFER)->state.indent_skip
109 #define output_message_text(BUFFER) \
110    ((const char *) obstack_base (&(BUFFER)->obstack))
111
112 /* This data structure bundles altogether any information relevant to
113    the context of a diagnostic message.  */
114 struct diagnostic_context
115 {
116   /* The diagnostic message to output.  */
117   const char *message;
118
119   /* A pointer to a variable list of the arguments necessary for the
120      purpose of message formatting.  */
121   va_list *args_ptr;
122
123   /* The name of the source file involved in the diiagnostic.  */     
124   const char *file;
125
126   /* The line-location in the source file.  */
127   int line;
128
129   /* Is this message a warning?  */
130   int warn;
131
132   /* This function is called before any message is printed out.  It is
133      responsible for preparing message prefix and such.  For example, it
134      might say:
135      In file included from "/usr/local/include/curses.h:5:
136                       from "/home/gdr/src/nifty_printer.h:56:
137                       ...
138   */
139   void (*begin_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
140
141   /* This function is called after the diagnostic message is printed.   */
142   void (*end_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
143
144   /* Hook for front-end extensions.  */
145   void *x_data;
146 };
147
148 #define diagnostic_message(DC) (DC)->message
149 #define diagnostic_argument_list(DC) (DC)->args_ptr
150 #define diagnostic_file_location(DC) (DC)->file
151 #define diagnostic_line_location(DC) (DC)->line
152 #define diagnostic_is_warning(DC) (DC)->warn
153 #define diagnostic_starter(DC) (DC)->begin_diagnostic
154 #define diagnostic_finalizer(DC) (DC)->end_diagnostic
155 #define diagnostic_auxiliary_data(DC) (DC)->x_data
156
157 /* If non-NULL, this function formats data in the BUFFER. When called,
158    output_buffer_text_cursor (BUFFER) points to a format code.  LANG_PRINTER
159    should call output_add_string (and related functions) to add data to
160    the BUFFER.  LANG_PRINTER can read arguments from
161    output_buffer_format_args (BUFFER) using VA_ARG.  If the BUFFER needs
162    additional characters from the format string, it should advance
163    the output_buffer_text_cursor (BUFFER) as it goes.  When LANG_PRINTER
164    returns, output_buffer_text_cursor (BUFFER) should point to the last
165    character processed.  */
166
167 extern printer_fn lang_printer;
168
169 extern diagnostic_starter_fn lang_diagnostic_starter;
170 extern diagnostic_finalizer_fn lang_diagnostic_finalizer;
171
172 extern int diagnostic_message_length_per_line;
173
174 /* This output buffer is used by front-ends that directly output
175    diagnostic messages without going through `error', `warning',
176    and similar functions.  In general, such usage should be
177    avoided.  This global buffer will go away, once all such usage
178    has been removed.  */
179 extern output_buffer *diagnostic_buffer;
180
181 /* Prototypes */
182 extern void set_diagnostic_context      PARAMS ((diagnostic_context *,
183                                                  const char *, va_list *,
184                                                  const char *, int, int));
185 extern void set_internal_error_function PARAMS ((void (*)
186                                                  PARAMS ((const char *,
187                                                           va_list *))));
188 extern void report_diagnostic           PARAMS ((diagnostic_context *));
189 extern void initialize_diagnostics      PARAMS ((void));
190 extern void reshape_diagnostic_buffer   PARAMS ((void));
191 extern void default_initialize_buffer   PARAMS ((output_buffer *));
192 extern void init_output_buffer          PARAMS ((output_buffer *,
193                                                  const char *, int));
194 extern void flush_diagnostic_buffer     PARAMS ((void));
195 extern void output_clear                PARAMS ((output_buffer *));
196 extern const char *output_get_prefix    PARAMS ((const output_buffer *));
197 extern const char *output_last_position PARAMS ((const output_buffer *));
198 extern void output_set_prefix           PARAMS ((output_buffer *,
199                                                  const char *));
200 extern void output_destroy_prefix       PARAMS ((output_buffer *));
201 extern void output_set_maximum_length   PARAMS ((output_buffer *, int));
202 extern void output_emit_prefix          PARAMS ((output_buffer *));
203 extern void output_add_newline          PARAMS ((output_buffer *));
204 extern void output_add_space            PARAMS ((output_buffer *));
205 extern int output_space_left            PARAMS ((const output_buffer *));
206 extern void output_append               PARAMS ((output_buffer *, const char *,
207                                                  const char *));
208 extern void output_add_character        PARAMS ((output_buffer *, int));
209 extern void output_decimal              PARAMS ((output_buffer *, int));
210 extern void output_add_string           PARAMS ((output_buffer *,
211                                                  const char *));
212 extern const char *output_finalize_message PARAMS ((output_buffer *));
213 extern void output_clear_message_text   PARAMS ((output_buffer *));
214 extern void output_printf               PARAMS ((output_buffer *, const char *,
215                                                  ...)) ATTRIBUTE_PRINTF_2;
216 extern int output_is_line_wrapping      PARAMS ((output_buffer *));
217 extern void set_message_prefixing_rule  PARAMS ((int));
218 extern void output_verbatim             PARAMS ((output_buffer *, const char *,
219                                                  ...)) ATTRIBUTE_PRINTF_2;
220 extern void verbatim                    PARAMS ((const char *, ...))
221      ATTRIBUTE_PRINTF_1;
222 extern char *context_as_prefix          PARAMS ((const char *, int, int));
223 extern char *file_name_as_prefix        PARAMS ((const char *));
224 extern int error_module_changed         PARAMS ((void));
225 extern void record_last_error_module    PARAMS ((void));
226 extern int error_function_changed       PARAMS ((void));
227 extern void record_last_error_function  PARAMS ((void));
228 extern void report_problematic_module   PARAMS ((output_buffer *));     
229
230 #endif /* ! GCC_DIAGNOSTIC_H */