* config/i386/i386.md (mmx_pinsrw): Output operands in correct
[official-gcc.git] / gcc / diagnostic.h
blob6d693fc24c1951717cfaf72a8b98b771e421830c
1 /* Various declarations for language-independent diagnostics subroutines.
2 Copyright (C) 2000 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
5 This file is part of GNU CC.
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.
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.
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. */
22 #ifndef __GCC_DIAGNOSTIC_H__
23 #define __GCC_DIAGNOSTIC_H__
25 #include "obstack.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;
34 #define DIAGNOSTICS_SHOW_PREFIX_ONCE 0x0
35 #define DIAGNOSTICS_SHOW_PREFIX_NEVER 0x1
36 #define DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE 0x2
38 /* The type of front-end specific hook that formats trees into an
39 output_buffer. A language specific printer returns a truth value if
40 everything goes well. */
41 typedef int (*printer_fn) PARAMS ((output_buffer *));
43 /* This data structure encapulates an output_buffer's state. */
44 typedef struct
46 /* The prefix for each new line. */
47 const char *prefix;
48 /* The real upper bound of number of characters per line, taking into
49 accompt the case of a very very looong prefix. */
50 int maximum_length;
51 /* The ideal upper bound of number of characters per line, as suggested
52 by front-end. */
53 int ideal_maximum_length;
55 /* Indentation count. */
56 int indent_skip;
58 /* Nonzero if current PREFIX was emitted at least once. */
59 int emitted_prefix_p;
61 /* Nonzero means one should emit a newline before outputing anything. */
62 int need_newline_p;
64 /* Tells how often current PREFIX should be emitted:
65 o DIAGNOSTICS_SHOW_PREFIX_NEVER: never - not yet supported;
66 o DIAGNOSTICS_SHOW_PREFIX_ONCE: emit current PREFIX only once;
67 o DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE: emit current PREFIX each time
68 a physical line is started. */
69 int prefixing_rule;
70 /* The current char to output. Updated by front-end (*format_map) when
71 it is called to report front-end printer for a specified format. */
72 const char *cursor;
73 /* A pointer to the variable argument-list for formatting. */
74 va_list *format_args;
75 } output_state;
77 /* The output buffer datatype. This is best seen as an abstract datatype. */
78 struct output_buffer
80 /* Internal data. These fields should not be accessed directly by
81 front-ends. */
83 /* The obstack where the text is built up. */
84 struct obstack obstack;
85 /* The amount of characters output so far. */
86 int line_length;
87 /* The current state of the buffer. */
88 output_state state;
91 #define output_buffer_text_cursor(BUFFER) (BUFFER)->state.cursor
92 #define output_buffer_format_args(BUFFER) *((BUFFER)->state.format_args)
93 #define output_needs_newline(BUFFER) (BUFFER)->state.need_newline_p
94 #define output_buffer_state(BUFFER) (BUFFER)->state
95 #define output_indentation(BUFFER) (BUFFER)->state.indent_skip
96 #define output_message_text(BUFFER) \
97 ((const char *) obstack_base (&(BUFFER)->obstack))
99 /* This data structure bundles altogether any information relevent to
100 the context of a diagnostic message. */
101 struct diagnostic_context
103 /* The diagnostic message to output. */
104 const char *message;
106 /* A pointer to a variable list of the arguments necessary for the
107 purpose of message formatting. */
108 va_list *args_ptr;
110 /* The name of the source file involved in the diiagnostic. */
111 const char *file;
113 /* The line-location in the source file. */
114 int line;
116 /* Is it message a warning? */
117 int warn;
119 /* This function is called before any message is printed out. It is
120 respondible for preparing message prefix and such. For example, it
121 might say:
122 In file included from "/usr/local/include/curses.h:5:
123 from "/home/gdr/src/nifty_printer.h:56:
126 void (*begin_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
128 /* This function is called after the diagnostic message is printed. */
129 void (*end_diagnostic) PARAMS ((output_buffer *, diagnostic_context *));
131 /* Hook for front-end extensions. */
132 void *x_data;
135 #define diagnostic_message(DC) (DC)->message
136 #define diagnostic_argument_list(DC) (DC)->args_ptr
137 #define diagnostic_file_location(DC) (DC)->file
138 #define diagnostic_line_location(DC) (DC)->line
139 #define diagnostic_is_warning(DC) (DC)->warn
140 #define diagnostic_starter(DC) (DC)->begin_diagnostic
141 #define diagnostic_finalizer(DC) (DC)->end_diagnostic
142 #define diagnostic_auxiliary_data(DC) (DC)->x_data
144 /* If non-NULL, this function formats data in the BUFFER. When called,
145 output_buffer_text_cursor (BUFFER) points to a format code. LANG_PRINTER
146 should call output_add_string (and related functions) to add data to
147 the BUFFER. LANG_PRINTER can read arguments from
148 output_buffer_format_args (BUFFER) using VA_ARG. If the BUFFER needs
149 additional characters from the format string, it should advance
150 the output_buffer_text_cursor (BUFFER) as it goes. When LANG_PRINTER
151 returns, output_buffer_text_cursor (BUFFER) should point to the last
152 character processed. */
154 extern printer_fn lang_printer;
156 extern diagnostic_starter_fn lang_diagnostic_starter;
157 extern diagnostic_finalizer_fn lang_diagnostic_finalizer;
159 extern int diagnostic_message_length_per_line;
161 /* This output buffer is used by front-ends that directly output
162 diagnostic messages without going through `error', `warning',
163 and simillar functions. In general, such usage should be
164 avoided. This global buffer will go away, once all such usage
165 has been removed. */
166 extern output_buffer *diagnostic_buffer;
168 /* Prototypes */
169 void set_diagnostic_context PARAMS ((diagnostic_context *, const char *,
170 va_list *, const char *, int, int));
171 void set_fatal_function PARAMS ((void (*) PARAMS ((const char *,
172 va_list *))));
173 void report_diagnostic PARAMS ((diagnostic_context *));
174 void initialize_diagnostics PARAMS ((void));
175 void reshape_diagnostic_buffer PARAMS ((void));
176 void default_initialize_buffer PARAMS ((output_buffer *));
177 void init_output_buffer PARAMS ((output_buffer *, const char *, int));
178 void flush_diagnostic_buffer PARAMS ((void));
179 void output_clear PARAMS ((output_buffer *));
180 const char *output_get_prefix PARAMS ((const output_buffer *));
181 const char *output_last_position PARAMS ((const output_buffer *));
182 void output_set_prefix PARAMS ((output_buffer *, const char *));
183 void output_destroy_prefix PARAMS ((output_buffer *));
184 void output_set_maximum_length PARAMS ((output_buffer *, int));
185 void output_emit_prefix PARAMS ((output_buffer *));
186 void output_add_newline PARAMS ((output_buffer *));
187 void output_add_space PARAMS ((output_buffer *));
188 int output_space_left PARAMS ((const output_buffer *));
189 void output_append PARAMS ((output_buffer *, const char *,
190 const char *));
191 void output_add_character PARAMS ((output_buffer *, int));
192 void output_decimal PARAMS ((output_buffer *, int));
193 void output_add_string PARAMS ((output_buffer *, const char *));
194 const char *output_finalize_message PARAMS ((output_buffer *));
195 void output_clear_message_text PARAMS ((output_buffer *));
196 void output_printf PARAMS ((output_buffer *, const char *,
197 ...)) ATTRIBUTE_PRINTF_2;
198 int output_is_line_wrapping PARAMS ((output_buffer *));
199 void set_message_prefixing_rule PARAMS ((int));
200 void output_verbatim PARAMS ((output_buffer *, const char *, ...))
201 ATTRIBUTE_PRINTF_2;
202 void verbatim PARAMS ((const char *, ...)) ATTRIBUTE_PRINTF_1;
203 char *context_as_prefix PARAMS ((const char *, int, int));
204 char *file_name_as_prefix PARAMS ((const char *));
205 int error_module_changed PARAMS ((void));
206 void record_last_error_module PARAMS ((void));
207 int error_function_changed PARAMS ((void));
208 void record_last_error_function PARAMS ((void));
209 void report_problematic_module PARAMS ((output_buffer *));
211 #endif /* __GCC_DIAGNOSTIC_H__ */