comparison gcc/diagnostic.h @ 16:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
15:561a7518be6b 16:04ced10e8804
1 /* Various declarations for language-independent diagnostics subroutines. 1 /* Various declarations for language-independent diagnostics subroutines.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 2 Copyright (C) 2000-2017 Free Software Foundation, Inc.
3 2010, Free Software Foundation, Inc.
4 Contributed by Gabriel Dos Reis <gdr@codesourcery.com> 3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
5 4
6 This file is part of GCC. 5 This file is part of GCC.
7 6
8 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
26 #include "diagnostic-core.h" 25 #include "diagnostic-core.h"
27 26
28 /* A diagnostic is described by the MESSAGE to send, the FILE and LINE of 27 /* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
29 its context and its KIND (ice, error, warning, note, ...) See complete 28 its context and its KIND (ice, error, warning, note, ...) See complete
30 list in diagnostic.def. */ 29 list in diagnostic.def. */
31 typedef struct diagnostic_info 30 struct diagnostic_info
32 { 31 {
32 /* Text to be formatted. */
33 text_info message; 33 text_info message;
34 location_t location; 34
35 unsigned int override_column; 35 /* The location at which the diagnostic is to be reported. */
36 rich_location *richloc;
37
36 /* Auxiliary data for client. */ 38 /* Auxiliary data for client. */
37 void *x_data; 39 void *x_data;
38 /* The kind of diagnostic it is about. */ 40 /* The kind of diagnostic it is about. */
39 diagnostic_t kind; 41 diagnostic_t kind;
40 /* Which OPT_* directly controls this diagnostic. */ 42 /* Which OPT_* directly controls this diagnostic. */
41 int option_index; 43 int option_index;
42 } diagnostic_info; 44 };
43 45
44 /* Each time a diagnostic's classification is changed with a pragma, 46 /* Each time a diagnostic's classification is changed with a pragma,
45 we record the change and the location of the change in an array of 47 we record the change and the location of the change in an array of
46 these structs. */ 48 these structs. */
47 typedef struct diagnostic_classification_change_t 49 struct diagnostic_classification_change_t
48 { 50 {
49 location_t location; 51 location_t location;
50 int option; 52 int option;
51 diagnostic_t kind; 53 diagnostic_t kind;
52 } diagnostic_classification_change_t; 54 };
53 55
54 /* Forward declarations. */ 56 /* Forward declarations. */
55 typedef void (*diagnostic_starter_fn) (diagnostic_context *, 57 typedef void (*diagnostic_starter_fn) (diagnostic_context *,
56 diagnostic_info *); 58 diagnostic_info *);
59
60 typedef void (*diagnostic_start_span_fn) (diagnostic_context *,
61 expanded_location);
62
57 typedef diagnostic_starter_fn diagnostic_finalizer_fn; 63 typedef diagnostic_starter_fn diagnostic_finalizer_fn;
64
65 class edit_context;
58 66
59 /* This data structure bundles altogether any information relevant to 67 /* This data structure bundles altogether any information relevant to
60 the context of a diagnostic message. */ 68 the context of a diagnostic message. */
61 struct diagnostic_context 69 struct diagnostic_context
62 { 70 {
63 /* Where most of the diagnostic formatting work is done. */ 71 /* Where most of the diagnostic formatting work is done. */
64 pretty_printer *printer; 72 pretty_printer *printer;
65 73
66 /* The number of times we have issued diagnostics. */ 74 /* The number of times we have issued diagnostics. */
67 int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND]; 75 int diagnostic_count[DK_LAST_DIAGNOSTIC_KIND];
68
69 /* True if we should display the "warnings are being tread as error"
70 message, usually displayed once per compiler run. */
71 bool some_warnings_are_errors;
72 76
73 /* True if it has been requested that warnings be treated as errors. */ 77 /* True if it has been requested that warnings be treated as errors. */
74 bool warning_as_error_requested; 78 bool warning_as_error_requested;
75 79
76 /* The number of option indexes that can be passed to warning() et 80 /* The number of option indexes that can be passed to warning() et
97 101
98 /* For pragma push/pop. */ 102 /* For pragma push/pop. */
99 int *push_list; 103 int *push_list;
100 int n_push; 104 int n_push;
101 105
106 /* True if we should print the source line with a caret indicating
107 the location. */
108 bool show_caret;
109
110 /* Maximum width of the source line printed. */
111 int caret_max_width;
112
113 /* Character used for caret diagnostics. */
114 char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
115
102 /* True if we should print the command line option which controls 116 /* True if we should print the command line option which controls
103 each diagnostic, if known. */ 117 each diagnostic, if known. */
104 bool show_option_requested; 118 bool show_option_requested;
105 119
106 /* True if we should raise a SIGABRT on errors. */ 120 /* True if we should raise a SIGABRT on errors. */
127 141
128 /* True if warnings should be given in system headers. */ 142 /* True if warnings should be given in system headers. */
129 bool dc_warn_system_headers; 143 bool dc_warn_system_headers;
130 144
131 /* Maximum number of errors to report. */ 145 /* Maximum number of errors to report. */
132 unsigned int max_errors; 146 int max_errors;
133 147
134 /* This function is called before any message is printed out. It is 148 /* This function is called before any message is printed out. It is
135 responsible for preparing message prefix and such. For example, it 149 responsible for preparing message prefix and such. For example, it
136 might say: 150 might say:
137 In file included from "/usr/local/include/curses.h:5: 151 In file included from "/usr/local/include/curses.h:5:
138 from "/home/gdr/src/nifty_printer.h:56: 152 from "/home/gdr/src/nifty_printer.h:56:
139 ... 153 ...
140 */ 154 */
141 diagnostic_starter_fn begin_diagnostic; 155 diagnostic_starter_fn begin_diagnostic;
142 156
157 /* This function is called by diagnostic_show_locus in between
158 disjoint spans of source code, so that the context can print
159 something to indicate that a new span of source code has begun. */
160 diagnostic_start_span_fn start_span;
161
143 /* This function is called after the diagnostic message is printed. */ 162 /* This function is called after the diagnostic message is printed. */
144 diagnostic_finalizer_fn end_diagnostic; 163 diagnostic_finalizer_fn end_diagnostic;
145 164
146 /* Client hook to report an internal error. */ 165 /* Client hook to report an internal error. */
147 void (*internal_error) (diagnostic_context *, const char *, va_list *); 166 void (*internal_error) (diagnostic_context *, const char *, va_list *);
163 char *(*option_name) (diagnostic_context *, int, diagnostic_t, diagnostic_t); 182 char *(*option_name) (diagnostic_context *, int, diagnostic_t, diagnostic_t);
164 183
165 /* Auxiliary data for client. */ 184 /* Auxiliary data for client. */
166 void *x_data; 185 void *x_data;
167 186
187 /* Used to detect that the last caret was printed at the same location. */
188 location_t last_location;
189
168 /* Used to detect when the input file stack has changed since last 190 /* Used to detect when the input file stack has changed since last
169 described. */ 191 described. */
170 const struct line_map *last_module; 192 const line_map_ordinary *last_module;
171 193
172 int lock; 194 int lock;
173 195
174 bool inhibit_notes_p; 196 bool inhibit_notes_p;
197
198 /* When printing source code, should the characters at carets and ranges
199 be colorized? (assuming colorization is on at all).
200 This should be true for frontends that generate range information
201 (so that the ranges of code are colorized),
202 and false for frontends that merely specify points within the
203 source code (to avoid e.g. colorizing just the first character in
204 a token, which would look strange). */
205 bool colorize_source_p;
206
207 /* Usable by plugins; if true, print a debugging ruler above the
208 source output. */
209 bool show_ruler_p;
210
211 /* If true, print fixits in machine-parseable form after the
212 rest of the diagnostic. */
213 bool parseable_fixits_p;
214
215 /* If non-NULL, an edit_context to which fix-it hints should be
216 applied, for generating patches. */
217 edit_context *edit_context_ptr;
175 }; 218 };
176 219
177 static inline void 220 static inline void
178 diagnostic_inhibit_notes (diagnostic_context * context) 221 diagnostic_inhibit_notes (diagnostic_context * context)
179 { 222 {
195 /* Same as pp_format_decoder. Works on 'diagnostic_context *'. */ 238 /* Same as pp_format_decoder. Works on 'diagnostic_context *'. */
196 #define diagnostic_format_decoder(DC) ((DC)->printer->format_decoder) 239 #define diagnostic_format_decoder(DC) ((DC)->printer->format_decoder)
197 240
198 /* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */ 241 /* Same as output_prefixing_rule. Works on 'diagnostic_context *'. */
199 #define diagnostic_prefixing_rule(DC) ((DC)->printer->wrapping.rule) 242 #define diagnostic_prefixing_rule(DC) ((DC)->printer->wrapping.rule)
200
201 /* Maximum characters per line in automatic line wrapping mode.
202 Zero means don't wrap lines. */
203 #define diagnostic_line_cutoff(DC) ((DC)->printer->wrapping.line_cutoff)
204
205 #define diagnostic_flush_buffer(DC) pp_base_flush ((DC)->printer)
206
207 /* True if the last module or file in which a diagnostic was reported is
208 different from the current one. */
209 #define diagnostic_last_module_changed(DC, MAP) \
210 ((DC)->last_module != MAP)
211
212 /* Remember the current module or file as being the last one in which we
213 report a diagnostic. */
214 #define diagnostic_set_last_module(DC, MAP) \
215 (DC)->last_module = MAP
216 243
217 /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */ 244 /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
218 #define diagnostic_abort_on_error(DC) \ 245 #define diagnostic_abort_on_error(DC) \
219 (DC)->abort_on_error = true 246 (DC)->abort_on_error = true
220 247
229 /* The number of errors that have been issued so far. Ideally, these 256 /* The number of errors that have been issued so far. Ideally, these
230 would take a diagnostic_context as an argument. */ 257 would take a diagnostic_context as an argument. */
231 #define errorcount diagnostic_kind_count (global_dc, DK_ERROR) 258 #define errorcount diagnostic_kind_count (global_dc, DK_ERROR)
232 /* Similarly, but for warnings. */ 259 /* Similarly, but for warnings. */
233 #define warningcount diagnostic_kind_count (global_dc, DK_WARNING) 260 #define warningcount diagnostic_kind_count (global_dc, DK_WARNING)
261 /* Similarly, but for warnings promoted to errors. */
262 #define werrorcount diagnostic_kind_count (global_dc, DK_WERROR)
234 /* Similarly, but for sorrys. */ 263 /* Similarly, but for sorrys. */
235 #define sorrycount diagnostic_kind_count (global_dc, DK_SORRY) 264 #define sorrycount diagnostic_kind_count (global_dc, DK_SORRY)
236 265
237 /* Returns nonzero if warnings should be emitted. */ 266 /* Returns nonzero if warnings should be emitted. */
238 #define diagnostic_report_warnings_p(DC, LOC) \ 267 #define diagnostic_report_warnings_p(DC, LOC) \
239 (!(DC)->dc_inhibit_warnings \ 268 (!(DC)->dc_inhibit_warnings \
240 && !(in_system_header_at (LOC) && !(DC)->dc_warn_system_headers)) 269 && !(in_system_header_at (LOC) && !(DC)->dc_warn_system_headers))
241 270
242 #define report_diagnostic(D) diagnostic_report_diagnostic (global_dc, D)
243
244 /* Override the column number to be used for reporting a
245 diagnostic. */
246 #define diagnostic_override_column(DI, COL) (DI)->override_column = (COL)
247
248 /* Override the option index to be used for reporting a 271 /* Override the option index to be used for reporting a
249 diagnostic. */ 272 diagnostic. */
250 #define diagnostic_override_option_index(DI, OPTIDX) \ 273
251 ((DI)->option_index = (OPTIDX)) 274 static inline void
275 diagnostic_override_option_index (diagnostic_info *info, int optidx)
276 {
277 info->option_index = optidx;
278 }
252 279
253 /* Diagnostic related functions. */ 280 /* Diagnostic related functions. */
254 extern void diagnostic_initialize (diagnostic_context *, int); 281 extern void diagnostic_initialize (diagnostic_context *, int);
282 extern void diagnostic_color_init (diagnostic_context *, int value = -1);
255 extern void diagnostic_finish (diagnostic_context *); 283 extern void diagnostic_finish (diagnostic_context *);
256 extern void diagnostic_report_current_module (diagnostic_context *); 284 extern void diagnostic_report_current_module (diagnostic_context *, location_t);
285 extern void diagnostic_show_locus (diagnostic_context *,
286 rich_location *richloc,
287 diagnostic_t diagnostic_kind);
257 288
258 /* Force diagnostics controlled by OPTIDX to be kind KIND. */ 289 /* Force diagnostics controlled by OPTIDX to be kind KIND. */
259 extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *, 290 extern diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *,
260 int /* optidx */, 291 int /* optidx */,
261 diagnostic_t /* kind */, 292 diagnostic_t /* kind */,
264 extern void diagnostic_pop_diagnostics (diagnostic_context *, location_t); 295 extern void diagnostic_pop_diagnostics (diagnostic_context *, location_t);
265 extern bool diagnostic_report_diagnostic (diagnostic_context *, 296 extern bool diagnostic_report_diagnostic (diagnostic_context *,
266 diagnostic_info *); 297 diagnostic_info *);
267 #ifdef ATTRIBUTE_GCC_DIAG 298 #ifdef ATTRIBUTE_GCC_DIAG
268 extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *, 299 extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
269 location_t, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); 300 rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
270 extern void diagnostic_set_info_translated (diagnostic_info *, const char *, 301 extern void diagnostic_set_info_translated (diagnostic_info *, const char *,
271 va_list *, location_t, 302 va_list *, rich_location *,
272 diagnostic_t) 303 diagnostic_t)
273 ATTRIBUTE_GCC_DIAG(2,0); 304 ATTRIBUTE_GCC_DIAG(2,0);
305 extern void diagnostic_append_note (diagnostic_context *, location_t,
306 const char *, ...) ATTRIBUTE_GCC_DIAG(3,4);
274 #endif 307 #endif
275 extern char *diagnostic_build_prefix (diagnostic_context *, diagnostic_info *); 308 extern char *diagnostic_build_prefix (diagnostic_context *, const diagnostic_info *);
276 void default_diagnostic_starter (diagnostic_context *, diagnostic_info *); 309 void default_diagnostic_starter (diagnostic_context *, diagnostic_info *);
310 void default_diagnostic_start_span_fn (diagnostic_context *,
311 expanded_location);
277 void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *); 312 void default_diagnostic_finalizer (diagnostic_context *, diagnostic_info *);
313 void diagnostic_set_caret_max_width (diagnostic_context *context, int value);
314 void diagnostic_action_after_output (diagnostic_context *, diagnostic_t);
315 void diagnostic_check_max_errors (diagnostic_context *, bool flush = false);
316
317 void diagnostic_file_cache_fini (void);
318
319 int get_terminal_width (void);
320
321 /* Return the location associated to this diagnostic. Parameter WHICH
322 specifies which location. By default, expand the first one. */
323
324 static inline location_t
325 diagnostic_location (const diagnostic_info * diagnostic, int which = 0)
326 {
327 return diagnostic->message.get_location (which);
328 }
329
330 /* Return the number of locations to be printed in DIAGNOSTIC. */
331
332 static inline unsigned int
333 diagnostic_num_locations (const diagnostic_info * diagnostic)
334 {
335 return diagnostic->message.m_richloc->get_num_locations ();
336 }
337
338 /* Expand the location of this diagnostic. Use this function for
339 consistency. Parameter WHICH specifies which location. By default,
340 expand the first one. */
341
342 static inline expanded_location
343 diagnostic_expand_location (const diagnostic_info * diagnostic, int which = 0)
344 {
345 return diagnostic->richloc->get_expanded_location (which);
346 }
347
348 /* This is somehow the right-side margin of a caret line, that is, we
349 print at least these many characters after the position pointed at
350 by the caret. */
351 const int CARET_LINE_MARGIN = 10;
352
353 /* Return true if the two locations can be represented within the same
354 caret line. This is used to build a prefix and also to determine
355 whether to print one or two caret lines. */
356
357 static inline bool
358 diagnostic_same_line (const diagnostic_context *context,
359 expanded_location s1, expanded_location s2)
360 {
361 return s2.column && s1.line == s2.line
362 && context->caret_max_width - CARET_LINE_MARGIN > abs (s1.column - s2.column);
363 }
364
365 extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
278 366
279 /* Pure text formatting support functions. */ 367 /* Pure text formatting support functions. */
280 extern char *file_name_as_prefix (const char *); 368 extern char *file_name_as_prefix (diagnostic_context *, const char *);
369
370 extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
371
281 372
282 #endif /* ! GCC_DIAGNOSTIC_H */ 373 #endif /* ! GCC_DIAGNOSTIC_H */