diagnostic.h revision 1.1 1 1.1 mrg /* Various declarations for language-independent diagnostics subroutines.
2 1.1 mrg Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
3 1.1 mrg 2010, Free Software Foundation, Inc.
4 1.1 mrg Contributed by Gabriel Dos Reis <gdr (at) codesourcery.com>
5 1.1 mrg
6 1.1 mrg This file is part of GCC.
7 1.1 mrg
8 1.1 mrg GCC is free software; you can redistribute it and/or modify it under
9 1.1 mrg the terms of the GNU General Public License as published by the Free
10 1.1 mrg Software Foundation; either version 3, or (at your option) any later
11 1.1 mrg version.
12 1.1 mrg
13 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 1.1 mrg for more details.
17 1.1 mrg
18 1.1 mrg You should have received a copy of the GNU General Public License
19 1.1 mrg along with GCC; see the file COPYING3. If not see
20 1.1 mrg <http://www.gnu.org/licenses/>. */
21 1.1 mrg
22 1.1 mrg #ifndef GCC_DIAGNOSTIC_H
23 1.1 mrg #define GCC_DIAGNOSTIC_H
24 1.1 mrg
25 1.1 mrg #include "pretty-print.h"
26 1.1 mrg #include "options.h"
27 1.1 mrg
28 1.1 mrg /* Constants used to discriminate diagnostics. */
29 1.1 mrg typedef enum
30 1.1 mrg {
31 1.1 mrg #define DEFINE_DIAGNOSTIC_KIND(K, msgid) K,
32 1.1 mrg #include "diagnostic.def"
33 1.1 mrg #undef DEFINE_DIAGNOSTIC_KIND
34 1.1 mrg DK_LAST_DIAGNOSTIC_KIND
35 1.1 mrg } diagnostic_t;
36 1.1 mrg
37 1.1 mrg /* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
38 1.1 mrg its context and its KIND (ice, error, warning, note, ...) See complete
39 1.1 mrg list in diagnostic.def. */
40 1.1 mrg typedef struct diagnostic_info
41 1.1 mrg {
42 1.1 mrg text_info message;
43 1.1 mrg location_t location;
44 1.1 mrg unsigned int override_column;
45 1.1 mrg /* TREE_BLOCK if the diagnostic is to be reported in some inline
46 1.1 mrg function inlined into other function, otherwise NULL. */
47 1.1 mrg tree abstract_origin;
48 1.1 mrg /* The kind of diagnostic it is about. */
49 1.1 mrg diagnostic_t kind;
50 1.1 mrg /* Which OPT_* directly controls this diagnostic. */
51 1.1 mrg int option_index;
52 1.1 mrg } diagnostic_info;
53 1.1 mrg
54 1.1 mrg /* Forward declarations. */
55 1.1 mrg typedef struct diagnostic_context diagnostic_context;
56 1.1 mrg typedef void (*diagnostic_starter_fn) (diagnostic_context *,
57 1.1 mrg diagnostic_info *);
58 1.1 mrg typedef diagnostic_starter_fn diagnostic_finalizer_fn;
59 1.1 mrg
60 1.1 mrg /* This data structure bundles altogether any information relevant to
61 1.1 mrg the context of a diagnostic message. */
62 1.1 mrg struct diagnostic_context
63 1.1 mrg {
64 1.1 mrg /* Where most of the diagnostic formatting work is done. */
65 1.1 mrg pretty_printer *printer;
66 1.1 mrg
67 1.1 mrg /* The number of times we have issued diagnostics. */
68 1.1 mrg int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
69 1.1 mrg
70 1.1 mrg /* True if we should display the "warnings are being tread as error"
71 1.1 mrg message, usually displayed once per compiler run. */
72 1.1 mrg bool issue_warnings_are_errors_message;
73 1.1 mrg
74 1.1 mrg /* True if it has been requested that warnings be treated as errors. */
75 1.1 mrg bool warning_as_error_requested;
76 1.1 mrg
77 1.1 mrg /* For each option index that can be passed to warning() et all
78 1.1 mrg (OPT_* from options.h), this array may contain a new kind that
79 1.1 mrg the diagnostic should be changed to before reporting, or
80 1.1 mrg DK_UNSPECIFIED to leave it as the reported kind, or DK_IGNORED to
81 1.1 mrg not report it at all. N_OPTS is from <options.h>. */
82 1.1 mrg diagnostic_t classify_diagnostic[N_OPTS];
83 1.1 mrg
84 1.1 mrg /* True if we should print the command line option which controls
85 1.1 mrg each diagnostic, if known. */
86 1.1 mrg bool show_option_requested;
87 1.1 mrg
88 1.1 mrg /* True if we should raise a SIGABRT on errors. */
89 1.1 mrg bool abort_on_error;
90 1.1 mrg
91 1.1 mrg /* This function is called before any message is printed out. It is
92 1.1 mrg responsible for preparing message prefix and such. For example, it
93 1.1 mrg might say:
94 1.1 mrg In file included from "/usr/local/include/curses.h:5:
95 1.1 mrg from "/home/gdr/src/nifty_printer.h:56:
96 1.1 mrg ...
97 1.1 mrg */
98 1.1 mrg diagnostic_starter_fn begin_diagnostic;
99 1.1 mrg
100 1.1 mrg /* This function is called after the diagnostic message is printed. */
101 1.1 mrg diagnostic_finalizer_fn end_diagnostic;
102 1.1 mrg
103 1.1 mrg /* Client hook to report an internal error. */
104 1.1 mrg void (*internal_error) (const char *, va_list *);
105 1.1 mrg
106 1.1 mrg /* Function of last diagnostic message; more generally, function such that
107 1.1 mrg if next diagnostic message is in it then we don't have to mention the
108 1.1 mrg function name. */
109 1.1 mrg tree last_function;
110 1.1 mrg
111 1.1 mrg /* Used to detect when the input file stack has changed since last
112 1.1 mrg described. */
113 1.1 mrg const struct line_map *last_module;
114 1.1 mrg
115 1.1 mrg int lock;
116 1.1 mrg
117 1.1 mrg bool inhibit_notes_p;
118 1.1 mrg };
119 1.1 mrg
120 1.1 mrg static inline void
121 1.1 mrg diagnostic_inhibit_notes (diagnostic_context * context)
122 1.1 mrg {
123 1.1 mrg context->inhibit_notes_p = true;
124 1.1 mrg }
125 1.1 mrg
126 1.1 mrg
127 1.1 mrg /* Client supplied function to announce a diagnostic. */
128 1.1 mrg #define diagnostic_starter(DC) (DC)->begin_diagnostic
129 1.1 mrg
130 1.1 mrg /* Client supplied function called after a diagnostic message is
131 1.1 mrg displayed. */
132 1.1 mrg #define diagnostic_finalizer(DC) (DC)->end_diagnostic
133 1.1 mrg
134 1.1 mrg /* Extension hook for client. */
135 1.1 mrg #define diagnostic_auxiliary_data(DC) (DC)->x_data
136 1.1 mrg
137 1.1 mrg /* Same as pp_format_decoder. Works on 'diagnostic_context *'. */
138 1.1 mrg #define diagnostic_format_decoder(DC) ((DC)->printer->format_decoder)
139 1.1 mrg
140 1.1 mrg /* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */
141 1.1 mrg #define diagnostic_prefixing_rule(DC) ((DC)->printer->wrapping.rule)
142 1.1 mrg
143 1.1 mrg /* Maximum characters per line in automatic line wrapping mode.
144 1.1 mrg Zero means don't wrap lines. */
145 1.1 mrg #define diagnostic_line_cutoff(DC) ((DC)->printer->wrapping.line_cutoff)
146 1.1 mrg
147 1.1 mrg #define diagnostic_flush_buffer(DC) pp_base_flush ((DC)->printer)
148 1.1 mrg
149 1.1 mrg /* True if the last function in which a diagnostic was reported is
150 1.1 mrg different from the current one. */
151 1.1 mrg #define diagnostic_last_function_changed(DC, DI) \
152 1.1 mrg ((DC)->last_function != ((DI)->abstract_origin \
153 1.1 mrg ? (DI)->abstract_origin : current_function_decl))
154 1.1 mrg
155 1.1 mrg /* Remember the current function as being the last one in which we report
156 1.1 mrg a diagnostic. */
157 1.1 mrg #define diagnostic_set_last_function(DC, DI) \
158 1.1 mrg (DC)->last_function = (((DI) && (DI)->abstract_origin) \
159 1.1 mrg ? (DI)->abstract_origin : current_function_decl)
160 1.1 mrg
161 1.1 mrg /* True if the last module or file in which a diagnostic was reported is
162 1.1 mrg different from the current one. */
163 1.1 mrg #define diagnostic_last_module_changed(DC, MAP) \
164 1.1 mrg ((DC)->last_module != MAP)
165 1.1 mrg
166 1.1 mrg /* Remember the current module or file as being the last one in which we
167 1.1 mrg report a diagnostic. */
168 1.1 mrg #define diagnostic_set_last_module(DC, MAP) \
169 1.1 mrg (DC)->last_module = MAP
170 1.1 mrg
171 1.1 mrg /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
172 1.1 mrg #define diagnostic_abort_on_error(DC) \
173 1.1 mrg (DC)->abort_on_error = true
174 1.1 mrg
175 1.1 mrg /* This diagnostic_context is used by front-ends that directly output
176 1.1 mrg diagnostic messages without going through `error', `warning',
177 1.1 mrg and similar functions. */
178 1.1 mrg extern diagnostic_context *global_dc;
179 1.1 mrg
180 1.1 mrg /* The total count of a KIND of diagnostics emitted so far. */
181 1.1 mrg #define diagnostic_kind_count(DC, DK) (DC)->diagnostic_count[(int) (DK)]
182 1.1 mrg
183 1.1 mrg /* The number of errors that have been issued so far. Ideally, these
184 1.1 mrg would take a diagnostic_context as an argument. */
185 1.1 mrg #define errorcount diagnostic_kind_count (global_dc, DK_ERROR)
186 1.1 mrg /* Similarly, but for warnings. */
187 1.1 mrg #define warningcount diagnostic_kind_count (global_dc, DK_WARNING)
188 1.1 mrg /* Similarly, but for sorrys. */
189 1.1 mrg #define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
190 1.1 mrg
191 1.1 mrg /* Returns nonzero if warnings should be emitted. */
192 1.1 mrg #define diagnostic_report_warnings_p(LOC) \
193 1.1 mrg (!inhibit_warnings \
194 1.1 mrg && !(in_system_header_at (LOC) && !warn_system_headers))
195 1.1 mrg
196 1.1 mrg #define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D)
197 1.1 mrg
198 1.1 mrg /* Override the column number to be used for reporting a
199 1.1 mrg diagnostic. */
200 1.1 mrg #define diagnostic_override_column(DI, COL) (DI)->override_column = (COL)
201 1.1 mrg
202 1.1 mrg /* Diagnostic related functions. */
203 1.1 mrg extern void diagnostic_initialize (diagnostic_context *);
204 1.1 mrg extern void diagnostic_report_current_module (diagnostic_context *);
205 1.1 mrg extern void diagnostic_report_current_function (diagnostic_context *,
206 1.1 mrg diagnostic_info *);
207 1.1 mrg
208 1.1 mrg /* Force diagnostics controlled by OPTIDX to be kind KIND. */
209 1.1 mrg extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
210 1.1 mrg int /* optidx */,
211 1.1 mrg diagnostic_t /* kind */);
212 1.1 mrg extern bool diagnostic_report_diagnostic (diagnostic_context *,
213 1.1 mrg diagnostic_info *);
214 1.1 mrg #ifdef ATTRIBUTE_GCC_DIAG
215 1.1 mrg extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
216 1.1 mrg location_t, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
217 1.1 mrg extern void diagnostic_set_info_translated (diagnostic_info *, const char *,
218 1.1 mrg va_list *, location_t,
219 1.1 mrg diagnostic_t)
220 1.1 mrg ATTRIBUTE_GCC_DIAG(2,0);
221 1.1 mrg extern bool emit_diagnostic (diagnostic_t, location_t, int,
222 1.1 mrg const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
223 1.1 mrg #endif
224 1.1 mrg extern char *diagnostic_build_prefix (diagnostic_info *);
225 1.1 mrg void default_diagnostic_starter (diagnostic_context *, diagnostic_info *);
226 1.1 mrg void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *);
227 1.1 mrg
228 1.1 mrg /* Pure text formatting support functions. */
229 1.1 mrg extern char *file_name_as_prefix (const char *);
230 1.1 mrg
231 1.1 mrg /* In tree-pretty-print.c */
232 1.1 mrg extern void print_declaration (pretty_printer *, tree, int, int);
233 1.1 mrg extern int dump_generic_node (pretty_printer *, tree, int, int, bool);
234 1.1 mrg extern void print_generic_stmt (FILE *, tree, int);
235 1.1 mrg extern void print_generic_stmt_indented (FILE *, tree, int, int);
236 1.1 mrg extern void print_generic_expr (FILE *, tree, int);
237 1.1 mrg extern void print_generic_decl (FILE *, tree, int);
238 1.1 mrg extern void debug_c_tree (tree);
239 1.1 mrg extern void dump_omp_clauses (pretty_printer *, tree, int, int);
240 1.1 mrg extern void print_call_name (pretty_printer *, tree, int);
241 1.1 mrg
242 1.1 mrg /* In gimple-pretty-print.c */
243 1.1 mrg extern void debug_generic_expr (tree);
244 1.1 mrg extern void debug_generic_stmt (tree);
245 1.1 mrg extern void debug_tree_chain (tree);
246 1.1 mrg extern void debug_gimple_stmt (gimple);
247 1.1 mrg extern void debug_gimple_seq (gimple_seq);
248 1.1 mrg extern void print_gimple_seq (FILE *, gimple_seq, int, int);
249 1.1 mrg extern void print_gimple_stmt (FILE *, gimple, int, int);
250 1.1 mrg extern void print_gimple_expr (FILE *, gimple, int, int);
251 1.1 mrg extern void dump_gimple_stmt (pretty_printer *, gimple, int, int);
252 1.1 mrg
253 1.1 mrg /* In toplev.c */
254 1.1 mrg extern bool default_tree_printer (pretty_printer *, text_info *, const char *,
255 1.1 mrg int, bool, bool, bool);
256 1.1 mrg
257 1.1 mrg #endif /* ! GCC_DIAGNOSTIC_H */
258