]>
Commit | Line | Data |
---|---|---|
345ed1fe | 1 | /* Various declarations for language-independent diagnostics subroutines. |
a945c346 | 2 | Copyright (C) 2000-2024 Free Software Foundation, Inc. |
345ed1fe GDR |
3 | Contributed by Gabriel Dos Reis <gdr@codesourcery.com> |
4 | ||
1322177d | 5 | This file is part of GCC. |
345ed1fe | 6 | |
1322177d LB |
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 | |
9dcd6f09 | 9 | Software Foundation; either version 3, or (at your option) any later |
1322177d | 10 | version. |
345ed1fe | 11 | |
1322177d LB |
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. | |
345ed1fe GDR |
16 | |
17 | You should have received a copy of the GNU General Public License | |
9dcd6f09 NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
345ed1fe | 20 | |
88657302 RH |
21 | #ifndef GCC_DIAGNOSTIC_H |
22 | #define GCC_DIAGNOSTIC_H | |
345ed1fe | 23 | |
29ee5881 | 24 | #include "unique-argv.h" |
78d132d7 | 25 | #include "rich-location.h" |
b6fe0bb8 | 26 | #include "pretty-print.h" |
1da2ed5f | 27 | #include "diagnostic-core.h" |
d0e66dbb | 28 | |
4f01ae37 DM |
29 | namespace text_art |
30 | { | |
31 | class theme; | |
32 | } // namespace text_art | |
33 | ||
004bb936 LH |
34 | /* An enum for controlling what units to use for the column number |
35 | when diagnostics are output, used by the -fdiagnostics-column-unit option. | |
36 | Tabs will be expanded or not according to the value of -ftabstop. The origin | |
37 | (default 1) is controlled by -fdiagnostics-column-origin. */ | |
38 | ||
39 | enum diagnostics_column_unit | |
40 | { | |
41 | /* The default from GCC 11 onwards: display columns. */ | |
42 | DIAGNOSTICS_COLUMN_UNIT_DISPLAY, | |
43 | ||
44 | /* The behavior in GCC 10 and earlier: simple bytes. */ | |
45 | DIAGNOSTICS_COLUMN_UNIT_BYTE | |
46 | }; | |
47 | ||
bd5e882c DM |
48 | /* An enum for controlling how to print non-ASCII characters/bytes when |
49 | a diagnostic suggests escaping the source code on output. */ | |
50 | ||
51 | enum diagnostics_escape_format | |
52 | { | |
53 | /* Escape non-ASCII Unicode characters in the form <U+XXXX> and | |
54 | non-UTF-8 bytes in the form <XX>. */ | |
55 | DIAGNOSTICS_ESCAPE_FORMAT_UNICODE, | |
56 | ||
57 | /* Escape non-ASCII bytes in the form <XX> (thus showing the underlying | |
58 | encoding of non-ASCII Unicode characters). */ | |
59 | DIAGNOSTICS_ESCAPE_FORMAT_BYTES | |
60 | }; | |
61 | ||
478dd60d DM |
62 | /* Enum for overriding the standard output format. */ |
63 | ||
64 | enum diagnostics_output_format | |
65 | { | |
66 | /* The default: textual output. */ | |
67 | DIAGNOSTICS_OUTPUT_FORMAT_TEXT, | |
68 | ||
5ab73173 DM |
69 | /* JSON-based output, to stderr. */ |
70 | DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR, | |
71 | ||
72 | /* JSON-based output, to a file. */ | |
6cf276dd DM |
73 | DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE, |
74 | ||
75 | /* SARIF-based output, to stderr. */ | |
76 | DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR, | |
77 | ||
78 | /* SARIF-based output, to a file. */ | |
79 | DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE | |
478dd60d DM |
80 | }; |
81 | ||
4bc1899b DM |
82 | /* An enum for controlling how diagnostic_paths should be printed. */ |
83 | enum diagnostic_path_format | |
84 | { | |
85 | /* Don't print diagnostic_paths. */ | |
86 | DPF_NONE, | |
87 | ||
88 | /* Print diagnostic_paths by emitting a separate "note" for every event | |
89 | in the path. */ | |
90 | DPF_SEPARATE_EVENTS, | |
91 | ||
92 | /* Print diagnostic_paths by consolidating events together where they | |
93 | are close enough, and printing such runs of events with multiple | |
94 | calls to diagnostic_show_locus, showing the individual events in | |
95 | each run via labels in the source. */ | |
96 | DPF_INLINE_EVENTS | |
97 | }; | |
98 | ||
f1096055 DM |
99 | /* An enum for capturing values of GCC_EXTRA_DIAGNOSTIC_OUTPUT, |
100 | and for -fdiagnostics-parseable-fixits. */ | |
101 | ||
102 | enum diagnostics_extra_output_kind | |
103 | { | |
104 | /* No extra output, or an unrecognized value. */ | |
105 | EXTRA_DIAGNOSTIC_OUTPUT_none, | |
106 | ||
107 | /* Emit fix-it hints using the "fixits-v1" format, equivalent to | |
108 | -fdiagnostics-parseable-fixits. */ | |
109 | EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1, | |
110 | ||
111 | /* Emit fix-it hints using the "fixits-v2" format. */ | |
112 | EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2 | |
113 | }; | |
114 | ||
8200cd97 DM |
115 | /* Values for -fdiagnostics-text-art-charset=. */ |
116 | ||
117 | enum diagnostic_text_art_charset | |
118 | { | |
119 | /* No text art diagrams shall be emitted. */ | |
120 | DIAGNOSTICS_TEXT_ART_CHARSET_NONE, | |
121 | ||
122 | /* Use pure ASCII for text art diagrams. */ | |
123 | DIAGNOSTICS_TEXT_ART_CHARSET_ASCII, | |
124 | ||
125 | /* Use ASCII + conservative use of other unicode characters | |
126 | in text art diagrams. */ | |
127 | DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE, | |
128 | ||
129 | /* Use Emoji. */ | |
130 | DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI | |
131 | }; | |
132 | ||
47b69537 GDR |
133 | /* A diagnostic is described by the MESSAGE to send, the FILE and LINE of |
134 | its context and its KIND (ice, error, warning, note, ...) See complete | |
135 | list in diagnostic.def. */ | |
84562394 | 136 | struct diagnostic_info |
47b69537 | 137 | { |
6feb628a | 138 | diagnostic_info () |
89991f31 | 139 | : message (), richloc (), metadata (), x_data (), kind (), option_id (), |
6feb628a MS |
140 | m_iinfo () |
141 | { } | |
142 | ||
8a645150 | 143 | /* Text to be formatted. */ |
47b69537 | 144 | text_info message; |
8a645150 DM |
145 | |
146 | /* The location at which the diagnostic is to be reported. */ | |
147 | rich_location *richloc; | |
148 | ||
6d4a35ca DM |
149 | /* An optional bundle of metadata associated with the diagnostic |
150 | (or NULL). */ | |
151 | const diagnostic_metadata *metadata; | |
152 | ||
cf835838 JM |
153 | /* Auxiliary data for client. */ |
154 | void *x_data; | |
47b69537 GDR |
155 | /* The kind of diagnostic it is about. */ |
156 | diagnostic_t kind; | |
ccf08a6e | 157 | /* Which OPT_* directly controls this diagnostic. */ |
89991f31 | 158 | diagnostic_option_id option_id; |
6feb628a MS |
159 | |
160 | /* Inlining context containing locations for each call site along | |
161 | the inlining stack. */ | |
162 | struct inlining_info | |
163 | { | |
164 | /* Locations along the inlining stack. */ | |
165 | auto_vec<location_t, 8> m_ilocs; | |
166 | /* The abstract origin of the location. */ | |
167 | void *m_ao; | |
168 | /* Set if every M_ILOCS element is in a system header. */ | |
169 | bool m_allsyslocs; | |
170 | } m_iinfo; | |
84562394 | 171 | }; |
47b69537 | 172 | |
47b69537 | 173 | /* Forward declarations. */ |
7da682c8 DM |
174 | typedef void (*diagnostic_text_starter_fn) (diagnostic_text_output_format &, |
175 | const diagnostic_info *); | |
876217ae DM |
176 | |
177 | typedef void (*diagnostic_start_span_fn) (diagnostic_context *, | |
178 | expanded_location); | |
179 | ||
7da682c8 DM |
180 | typedef void (*diagnostic_text_finalizer_fn) (diagnostic_text_output_format &, |
181 | const diagnostic_info *, | |
182 | diagnostic_t); | |
47b69537 | 183 | |
a97448e9 DM |
184 | /* Abstract base class for the diagnostic subsystem to make queries |
185 | about command-line options. */ | |
186 | ||
187 | class diagnostic_option_manager | |
188 | { | |
189 | public: | |
190 | virtual ~diagnostic_option_manager () {} | |
191 | ||
89991f31 | 192 | /* Return 1 if option OPTION_ID is enabled, 0 if it is disabled, |
a97448e9 DM |
193 | or -1 if it isn't a simple on-off switch |
194 | (or if the value is unknown, typically set later in target). */ | |
89991f31 | 195 | virtual int option_enabled_p (diagnostic_option_id option_id) const = 0; |
a97448e9 | 196 | |
89991f31 | 197 | /* Return malloced memory for the name of the option OPTION_ID |
a97448e9 DM |
198 | which enabled a diagnostic, originally of type ORIG_DIAG_KIND but |
199 | possibly converted to DIAG_KIND by options such as -Werror. | |
200 | May return NULL if no name is to be printed. | |
201 | May be passed 0 as well as the index of a particular option. */ | |
89991f31 | 202 | virtual char *make_option_name (diagnostic_option_id option_id, |
a97448e9 DM |
203 | diagnostic_t orig_diag_kind, |
204 | diagnostic_t diag_kind) const = 0; | |
205 | ||
206 | /* Return malloced memory for a URL describing the option that controls | |
207 | a diagnostic. | |
208 | May return NULL if no URL is available. | |
209 | May be passed 0 as well as the index of a particular option. */ | |
89991f31 | 210 | virtual char *make_option_url (diagnostic_option_id option_id) const = 0; |
a97448e9 | 211 | }; |
353f146c | 212 | |
717ebe91 | 213 | class edit_context; |
4bc1899b | 214 | namespace json { class value; } |
6cf276dd DM |
215 | class diagnostic_client_data_hooks; |
216 | class logical_location; | |
4f01ae37 | 217 | class diagnostic_diagram; |
770657d0 | 218 | class diagnostic_source_effect_info; |
92c5265d DM |
219 | class diagnostic_output_format; |
220 | class diagnostic_text_output_format; | |
14082026 | 221 | |
38763e2c DM |
222 | /* A stack of sets of classifications: each entry in the stack is |
223 | a mapping from option index to diagnostic severity that can be changed | |
224 | via pragmas. The stack can be pushed and popped. */ | |
225 | ||
226 | class diagnostic_option_classifier | |
227 | { | |
228 | public: | |
229 | void init (int n_opts); | |
230 | void fini (); | |
231 | ||
232 | /* Save all diagnostic classifications in a stack. */ | |
233 | void push (); | |
234 | ||
235 | /* Restore the topmost classification set off the stack. If the stack | |
236 | is empty, revert to the state based on command line parameters. */ | |
237 | void pop (location_t where); | |
238 | ||
89991f31 | 239 | bool option_unspecified_p (diagnostic_option_id option_id) const |
38763e2c | 240 | { |
89991f31 | 241 | return get_current_override (option_id) == DK_UNSPECIFIED; |
38763e2c DM |
242 | } |
243 | ||
89991f31 | 244 | diagnostic_t get_current_override (diagnostic_option_id option_id) const |
38763e2c | 245 | { |
89991f31 DM |
246 | gcc_assert (option_id.m_idx < m_n_opts); |
247 | return m_classify_diagnostic[option_id.m_idx]; | |
38763e2c DM |
248 | } |
249 | ||
250 | diagnostic_t | |
251 | classify_diagnostic (const diagnostic_context *context, | |
89991f31 | 252 | diagnostic_option_id option_id, |
38763e2c DM |
253 | diagnostic_t new_kind, |
254 | location_t where); | |
255 | ||
256 | diagnostic_t | |
257 | update_effective_level_from_pragmas (diagnostic_info *diagnostic) const; | |
258 | ||
259 | private: | |
260 | /* Each time a diagnostic's classification is changed with a pragma, | |
261 | we record the change and the location of the change in an array of | |
262 | these structs. */ | |
263 | struct diagnostic_classification_change_t | |
264 | { | |
265 | location_t location; | |
89991f31 DM |
266 | |
267 | /* For DK_POP, this is the index of the corresponding push (as stored | |
268 | in m_push_list). | |
269 | Otherwise, this is an option index. */ | |
38763e2c | 270 | int option; |
89991f31 | 271 | |
38763e2c DM |
272 | diagnostic_t kind; |
273 | }; | |
274 | ||
275 | int m_n_opts; | |
276 | ||
277 | /* For each option index that can be passed to warning() et al | |
278 | (OPT_* from options.h when using this code with the core GCC | |
279 | options), this array may contain a new kind that the diagnostic | |
280 | should be changed to before reporting, or DK_UNSPECIFIED to leave | |
281 | it as the reported kind, or DK_IGNORED to not report it at | |
282 | all. */ | |
283 | diagnostic_t *m_classify_diagnostic; | |
284 | ||
285 | /* History of all changes to the classifications above. This list | |
286 | is stored in location-order, so we can search it, either | |
287 | binary-wise or end-to-front, to find the most recent | |
288 | classification for a given diagnostic, given the location of the | |
289 | diagnostic. */ | |
290 | diagnostic_classification_change_t *m_classification_history; | |
291 | ||
292 | /* The size of the above array. */ | |
293 | int m_n_classification_history; | |
294 | ||
295 | /* For pragma push/pop. */ | |
296 | int *m_push_list; | |
297 | int m_n_push; | |
298 | }; | |
299 | ||
54da47f9 DM |
300 | /* A bundle of options relating to printing the user's source code |
301 | (potentially with a margin, underlining, labels, etc). */ | |
302 | ||
303 | struct diagnostic_source_printing_options | |
304 | { | |
305 | /* True if we should print the source line with a caret indicating | |
306 | the location. | |
307 | Corresponds to -fdiagnostics-show-caret. */ | |
308 | bool enabled; | |
309 | ||
310 | /* Maximum width of the source line printed. */ | |
311 | int max_width; | |
312 | ||
313 | /* Character used at the caret when printing source locations. */ | |
314 | char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES]; | |
315 | ||
316 | /* When printing source code, should the characters at carets and ranges | |
317 | be colorized? (assuming colorization is on at all). | |
318 | This should be true for frontends that generate range information | |
319 | (so that the ranges of code are colorized), | |
320 | and false for frontends that merely specify points within the | |
321 | source code (to avoid e.g. colorizing just the first character in | |
322 | a token, which would look strange). */ | |
323 | bool colorize_source_p; | |
324 | ||
325 | /* When printing source code, should labelled ranges be printed? | |
326 | Corresponds to -fdiagnostics-show-labels. */ | |
327 | bool show_labels_p; | |
328 | ||
329 | /* When printing source code, should there be a left-hand margin | |
330 | showing line numbers? | |
331 | Corresponds to -fdiagnostics-show-line-numbers. */ | |
332 | bool show_line_numbers_p; | |
333 | ||
334 | /* If printing source code, what should the minimum width of the margin | |
335 | be? Line numbers will be right-aligned, and padded to this width. | |
336 | Corresponds to -fdiagnostics-minimum-margin-width=VALUE. */ | |
337 | int min_margin_width; | |
338 | ||
339 | /* Usable by plugins; if true, print a debugging ruler above the | |
340 | source output. */ | |
341 | bool show_ruler_p; | |
770657d0 DM |
342 | |
343 | /* When printing events in an inline path, should we print lines | |
344 | visualizing links between related events (e.g. for CFG paths)? | |
345 | Corresponds to -fdiagnostics-show-event-links. */ | |
346 | bool show_event_links_p; | |
54da47f9 DM |
347 | }; |
348 | ||
c4765d18 | 349 | /* This data structure bundles altogether any information relevant to |
e2840263 | 350 | the context of a diagnostic message. */ |
8200cd97 | 351 | class diagnostic_context |
e2840263 | 352 | { |
ae8abcb8 | 353 | public: |
07e568d7 | 354 | /* Give access to m_text_callbacks. */ |
7da682c8 DM |
355 | friend diagnostic_text_starter_fn & |
356 | diagnostic_text_starter (diagnostic_context *context); | |
07e568d7 DM |
357 | friend diagnostic_start_span_fn & |
358 | diagnostic_start_span (diagnostic_context *context); | |
7da682c8 DM |
359 | friend diagnostic_text_finalizer_fn & |
360 | diagnostic_text_finalizer (diagnostic_context *context); | |
07e568d7 | 361 | |
ac707d30 DM |
362 | friend class diagnostic_text_output_format; |
363 | ||
8200cd97 DM |
364 | typedef void (*ice_handler_callback_t) (diagnostic_context *); |
365 | typedef void (*set_locations_callback_t) (diagnostic_context *, | |
366 | diagnostic_info *); | |
367 | ||
368 | void initialize (int n_opts); | |
369 | void color_init (int value); | |
370 | void urls_init (int value); | |
371 | ||
8200cd97 DM |
372 | void finish (); |
373 | ||
77f36e80 DM |
374 | bool execution_failed_p () const; |
375 | ||
29ee5881 DM |
376 | void set_original_argv (unique_argv original_argv); |
377 | const char * const *get_original_argv () | |
378 | { | |
379 | return const_cast<const char * const *> (m_original_argv); | |
380 | } | |
381 | ||
8200cd97 DM |
382 | void set_set_locations_callback (set_locations_callback_t cb) |
383 | { | |
384 | m_set_locations_cb = cb; | |
385 | } | |
386 | ||
387 | void | |
388 | initialize_input_context (diagnostic_input_charset_callback ccb, | |
389 | bool should_skip_bom); | |
390 | ||
ae8abcb8 DM |
391 | void begin_group (); |
392 | void end_group (); | |
393 | ||
89991f31 | 394 | bool warning_enabled_at (location_t loc, diagnostic_option_id option_id); |
ae8abcb8 | 395 | |
89991f31 | 396 | bool option_unspecified_p (diagnostic_option_id option_id) const |
8200cd97 | 397 | { |
89991f31 | 398 | return m_option_classifier.option_unspecified_p (option_id); |
8200cd97 DM |
399 | } |
400 | ||
401 | bool report_diagnostic (diagnostic_info *); | |
402 | ||
8200cd97 DM |
403 | void check_max_errors (bool flush); |
404 | void action_after_output (diagnostic_t diag_kind); | |
405 | ||
406 | diagnostic_t | |
89991f31 | 407 | classify_diagnostic (diagnostic_option_id option_id, |
8200cd97 | 408 | diagnostic_t new_kind, |
38763e2c DM |
409 | location_t where) |
410 | { | |
411 | return m_option_classifier.classify_diagnostic (this, | |
89991f31 | 412 | option_id, |
38763e2c DM |
413 | new_kind, |
414 | where); | |
415 | } | |
416 | ||
417 | void push_diagnostics (location_t where ATTRIBUTE_UNUSED) | |
418 | { | |
419 | m_option_classifier.push (); | |
420 | } | |
421 | void pop_diagnostics (location_t where) | |
422 | { | |
423 | m_option_classifier.pop (where); | |
424 | } | |
8200cd97 | 425 | |
8625aa24 DM |
426 | void maybe_show_locus (const rich_location &richloc, |
427 | diagnostic_t diagnostic_kind, | |
770657d0 DM |
428 | pretty_printer *pp, |
429 | diagnostic_source_effect_info *effect_info); | |
8625aa24 | 430 | |
8200cd97 DM |
431 | void emit_diagram (const diagnostic_diagram &diagram); |
432 | ||
0bf99b1b DM |
433 | const diagnostic_output_format *get_output_format () const |
434 | { | |
435 | return m_output_format; | |
436 | } | |
437 | ||
8200cd97 DM |
438 | /* Various setters for use by option-handling logic. */ |
439 | void set_output_format (diagnostic_output_format *output_format); | |
440 | void set_text_art_charset (enum diagnostic_text_art_charset charset); | |
441 | void set_client_data_hooks (diagnostic_client_data_hooks *hooks); | |
a526cc6f | 442 | void set_urlifier (urlifier *); |
8200cd97 DM |
443 | void create_edit_context (); |
444 | void set_warning_as_error_requested (bool val) | |
445 | { | |
446 | m_warning_as_error_requested = val; | |
447 | } | |
448 | void set_report_bug (bool val) { m_report_bug = val; } | |
449 | void set_extra_output_kind (enum diagnostics_extra_output_kind kind) | |
450 | { | |
451 | m_extra_output_kind = kind; | |
452 | } | |
453 | void set_show_cwe (bool val) { m_show_cwe = val; } | |
454 | void set_show_rules (bool val) { m_show_rules = val; } | |
7d73c01c DM |
455 | void set_show_highlight_colors (bool val) |
456 | { | |
19363bf5 | 457 | pp_show_highlight_colors (m_printer) = val; |
7d73c01c | 458 | } |
8200cd97 DM |
459 | void set_path_format (enum diagnostic_path_format val) |
460 | { | |
461 | m_path_format = val; | |
462 | } | |
463 | void set_show_path_depths (bool val) { m_show_path_depths = val; } | |
464 | void set_show_option_requested (bool val) { m_show_option_requested = val; } | |
465 | void set_max_errors (int val) { m_max_errors = val; } | |
466 | void set_escape_format (enum diagnostics_escape_format val) | |
467 | { | |
468 | m_escape_format = val; | |
469 | } | |
470 | void set_ice_handler_callback (ice_handler_callback_t cb) | |
471 | { | |
472 | m_ice_handler_cb = cb; | |
473 | } | |
474 | ||
475 | /* Various accessors. */ | |
476 | bool warning_as_error_requested_p () const | |
477 | { | |
478 | return m_warning_as_error_requested; | |
479 | } | |
480 | bool show_path_depths_p () const { return m_show_path_depths; } | |
481 | enum diagnostic_path_format get_path_format () const { return m_path_format; } | |
482 | enum diagnostics_escape_format get_escape_format () const | |
483 | { | |
484 | return m_escape_format; | |
485 | } | |
486 | ||
1bdd665a | 487 | file_cache & |
8200cd97 DM |
488 | get_file_cache () const |
489 | { | |
1bdd665a DM |
490 | gcc_assert (m_file_cache); |
491 | return *m_file_cache; | |
8200cd97 DM |
492 | } |
493 | ||
494 | edit_context *get_edit_context () const | |
495 | { | |
496 | return m_edit_context_ptr; | |
497 | } | |
725231e1 | 498 | const diagnostic_client_data_hooks *get_client_data_hooks () const |
8200cd97 DM |
499 | { |
500 | return m_client_data_hooks; | |
501 | } | |
ac707d30 | 502 | urlifier *get_urlifier () const { return m_urlifier; } |
8200cd97 DM |
503 | text_art::theme *get_diagram_theme () const { return m_diagrams.m_theme; } |
504 | ||
505 | int converted_column (expanded_location s) const; | |
506 | ||
507 | int &diagnostic_count (diagnostic_t kind) | |
508 | { | |
509 | return m_diagnostic_count[kind]; | |
510 | } | |
511 | ||
353f146c | 512 | /* Option-related member functions. */ |
89991f31 | 513 | inline bool option_enabled_p (diagnostic_option_id option_id) const |
353f146c | 514 | { |
a97448e9 | 515 | if (!m_option_mgr) |
353f146c | 516 | return true; |
89991f31 | 517 | return m_option_mgr->option_enabled_p (option_id); |
353f146c DM |
518 | } |
519 | ||
89991f31 DM |
520 | inline char *make_option_name (diagnostic_option_id option_id, |
521 | diagnostic_t orig_diag_kind, | |
522 | diagnostic_t diag_kind) const | |
353f146c | 523 | { |
a97448e9 | 524 | if (!m_option_mgr) |
353f146c | 525 | return nullptr; |
89991f31 | 526 | return m_option_mgr->make_option_name (option_id, |
a97448e9 DM |
527 | orig_diag_kind, |
528 | diag_kind); | |
353f146c DM |
529 | } |
530 | ||
89991f31 | 531 | inline char *make_option_url (diagnostic_option_id option_id) const |
353f146c | 532 | { |
a97448e9 | 533 | if (!m_option_mgr) |
353f146c | 534 | return nullptr; |
89991f31 | 535 | return m_option_mgr->make_option_url (option_id); |
353f146c DM |
536 | } |
537 | ||
538 | void | |
a97448e9 DM |
539 | set_option_manager (diagnostic_option_manager *mgr, |
540 | unsigned lang_mask); | |
4547c271 DM |
541 | |
542 | unsigned get_lang_mask () const | |
543 | { | |
a97448e9 | 544 | return m_lang_mask; |
4547c271 | 545 | } |
353f146c | 546 | |
7da682c8 DM |
547 | label_text get_location_text (const expanded_location &s, |
548 | bool colorize) const; | |
93096d3c | 549 | |
d681c521 | 550 | bool diagnostic_impl (rich_location *, const diagnostic_metadata *, |
89991f31 | 551 | diagnostic_option_id, const char *, |
d681c521 DM |
552 | va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0); |
553 | bool diagnostic_n_impl (rich_location *, const diagnostic_metadata *, | |
89991f31 | 554 | diagnostic_option_id, unsigned HOST_WIDE_INT, |
d681c521 DM |
555 | const char *, const char *, va_list *, |
556 | diagnostic_t) ATTRIBUTE_GCC_DIAG(7,0); | |
557 | ||
8200cd97 | 558 | private: |
8200cd97 DM |
559 | void error_recursion () ATTRIBUTE_NORETURN; |
560 | ||
561 | bool diagnostic_enabled (diagnostic_info *diagnostic); | |
562 | ||
563 | void get_any_inlining_info (diagnostic_info *diagnostic); | |
8200cd97 | 564 | |
8625aa24 DM |
565 | void show_locus (const rich_location &richloc, |
566 | diagnostic_t diagnostic_kind, | |
770657d0 DM |
567 | pretty_printer *pp, |
568 | diagnostic_source_effect_info *effect_info); | |
8625aa24 | 569 | |
8200cd97 | 570 | /* Data members. |
19363bf5 | 571 | Ideally, all of these would be private. */ |
8200cd97 DM |
572 | |
573 | public: | |
2b72593e | 574 | /* Where most of the diagnostic formatting work is done. */ |
19363bf5 | 575 | pretty_printer *m_printer; |
f68fc4db | 576 | |
8200cd97 | 577 | private: |
b544c348 DM |
578 | /* Cache of source code. */ |
579 | file_cache *m_file_cache; | |
580 | ||
4fcc2065 | 581 | /* The number of times we have issued diagnostics. */ |
8200cd97 | 582 | int m_diagnostic_count[DK_LAST_DIAGNOSTIC_KIND]; |
4fcc2065 | 583 | |
7783b402 | 584 | /* True if it has been requested that warnings be treated as errors. */ |
8200cd97 | 585 | bool m_warning_as_error_requested; |
13f0d49c | 586 | |
5f0f4a3b JM |
587 | /* The number of option indexes that can be passed to warning() et |
588 | al. */ | |
8200cd97 | 589 | int m_n_opts; |
5f0f4a3b | 590 | |
38763e2c DM |
591 | /* The stack of sets of overridden diagnostic option severities. */ |
592 | diagnostic_option_classifier m_option_classifier; | |
cd7fe53b | 593 | |
6d4a35ca DM |
594 | /* True if we should print any CWE identifiers associated with |
595 | diagnostics. */ | |
8200cd97 | 596 | bool m_show_cwe; |
6d4a35ca | 597 | |
0b14f590 | 598 | /* True if we should print any rules associated with diagnostics. */ |
8200cd97 | 599 | bool m_show_rules; |
0b14f590 | 600 | |
4bc1899b | 601 | /* How should diagnostic_path objects be printed. */ |
8200cd97 | 602 | enum diagnostic_path_format m_path_format; |
4bc1899b DM |
603 | |
604 | /* True if we should print stack depths when printing diagnostic paths. */ | |
8200cd97 | 605 | bool m_show_path_depths; |
4bc1899b | 606 | |
2098fe9e DD |
607 | /* True if we should print the command line option which controls |
608 | each diagnostic, if known. */ | |
8200cd97 | 609 | bool m_show_option_requested; |
2098fe9e | 610 | |
8200cd97 | 611 | public: |
886e0865 | 612 | /* True if we should raise a SIGABRT on errors. */ |
8200cd97 | 613 | bool m_abort_on_error; |
886e0865 | 614 | |
243fbddd | 615 | /* True if we should show the column number on diagnostics. */ |
8200cd97 | 616 | bool m_show_column; |
243fbddd JM |
617 | |
618 | /* True if pedwarns are errors. */ | |
8200cd97 | 619 | bool m_pedantic_errors; |
243fbddd JM |
620 | |
621 | /* True if permerrors are warnings. */ | |
8200cd97 | 622 | bool m_permissive; |
243fbddd | 623 | |
5f0f4a3b JM |
624 | /* The index of the option to associate with turning permerrors into |
625 | warnings. */ | |
8200cd97 | 626 | int m_opt_permissive; |
5f0f4a3b | 627 | |
243fbddd | 628 | /* True if errors are fatal. */ |
8200cd97 | 629 | bool m_fatal_errors; |
243fbddd | 630 | |
5f0f4a3b | 631 | /* True if all warnings should be disabled. */ |
8200cd97 | 632 | bool m_inhibit_warnings; |
5f0f4a3b JM |
633 | |
634 | /* True if warnings should be given in system headers. */ | |
8200cd97 | 635 | bool m_warn_system_headers; |
5f0f4a3b | 636 | |
8200cd97 | 637 | private: |
3a789837 | 638 | /* Maximum number of errors to report. */ |
8200cd97 | 639 | int m_max_errors; |
3a789837 | 640 | |
14082026 DM |
641 | /* Client-supplied callbacks for use in text output. */ |
642 | struct { | |
643 | /* This function is called before any message is printed out. It is | |
644 | responsible for preparing message prefix and such. For example, it | |
645 | might say: | |
646 | In file included from "/usr/local/include/curses.h:5: | |
647 | from "/home/gdr/src/nifty_printer.h:56: | |
648 | ... | |
649 | */ | |
7da682c8 | 650 | diagnostic_text_starter_fn m_begin_diagnostic; |
14082026 DM |
651 | |
652 | /* This function is called by diagnostic_show_locus in between | |
653 | disjoint spans of source code, so that the context can print | |
654 | something to indicate that a new span of source code has begun. */ | |
07e568d7 | 655 | diagnostic_start_span_fn m_start_span; |
14082026 DM |
656 | |
657 | /* This function is called after the diagnostic message is printed. */ | |
7da682c8 | 658 | diagnostic_text_finalizer_fn m_end_diagnostic; |
14082026 | 659 | } m_text_callbacks; |
e2840263 | 660 | |
07e568d7 | 661 | public: |
27e511e0 | 662 | /* Client hook to report an internal error. */ |
8200cd97 | 663 | void (*m_internal_error) (diagnostic_context *, const char *, va_list *); |
27e511e0 | 664 | |
596d1ed9 PP |
665 | /* Client hook to adjust properties of the given diagnostic that we're |
666 | about to issue, such as its kind. */ | |
667 | void (*m_adjust_diagnostic_info)(diagnostic_context *, diagnostic_info *); | |
668 | ||
a526cc6f | 669 | private: |
a97448e9 DM |
670 | diagnostic_option_manager *m_option_mgr; |
671 | unsigned m_lang_mask; | |
353f146c | 672 | |
c5db4d8b DM |
673 | /* An optional hook for adding URLs to quoted text strings in |
674 | diagnostics. Only used for the main diagnostic message. */ | |
675 | urlifier *m_urlifier; | |
676 | ||
a526cc6f | 677 | public: |
cf835838 | 678 | /* Auxiliary data for client. */ |
8200cd97 | 679 | void *m_client_aux_data; |
47b69537 | 680 | |
1b8b126f | 681 | /* Used to detect that the last caret was printed at the same location. */ |
8200cd97 | 682 | location_t m_last_location; |
1b8b126f | 683 | |
8200cd97 | 684 | private: |
8200cd97 | 685 | int m_lock; |
0e94b750 | 686 | |
8200cd97 | 687 | public: |
8200cd97 | 688 | bool m_inhibit_notes_p; |
8a645150 | 689 | |
54da47f9 | 690 | diagnostic_source_printing_options m_source_printing; |
a93eac6a | 691 | |
8200cd97 | 692 | private: |
76ef38e3 | 693 | /* True if -freport-bug option is used. */ |
8200cd97 | 694 | bool m_report_bug; |
76ef38e3 | 695 | |
f1096055 DM |
696 | /* Used to specify additional diagnostic output to be emitted after the |
697 | rest of the diagnostic. This is for implementing | |
698 | -fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT. */ | |
8200cd97 | 699 | enum diagnostics_extra_output_kind m_extra_output_kind; |
717ebe91 | 700 | |
8200cd97 | 701 | public: |
004bb936 | 702 | /* What units to use when outputting the column number. */ |
8200cd97 | 703 | enum diagnostics_column_unit m_column_unit; |
004bb936 LH |
704 | |
705 | /* The origin for the column number (1-based or 0-based typically). */ | |
8200cd97 | 706 | int m_column_origin; |
004bb936 LH |
707 | |
708 | /* The size of the tabstop for tab expansion. */ | |
8200cd97 | 709 | int m_tabstop; |
004bb936 | 710 | |
8200cd97 | 711 | private: |
bd5e882c DM |
712 | /* How should non-ASCII/non-printable bytes be escaped when |
713 | a diagnostic suggests escaping the source code on output. */ | |
8200cd97 | 714 | enum diagnostics_escape_format m_escape_format; |
bd5e882c | 715 | |
717ebe91 DM |
716 | /* If non-NULL, an edit_context to which fix-it hints should be |
717 | applied, for generating patches. */ | |
8200cd97 | 718 | edit_context *m_edit_context_ptr; |
097f82ec | 719 | |
ae8abcb8 DM |
720 | /* Fields relating to diagnostic groups. */ |
721 | struct { | |
722 | /* How many diagnostic_group instances are currently alive. */ | |
723 | int m_nesting_depth; | |
097f82ec | 724 | |
ae8abcb8 DM |
725 | /* How many diagnostics have been emitted since the bottommost |
726 | diagnostic_group was pushed. */ | |
727 | int m_emission_count; | |
728 | } m_diagnostic_groups; | |
097f82ec | 729 | |
14082026 DM |
730 | /* How to output diagnostics (text vs a structured format such as JSON). |
731 | Must be non-NULL; owned by context. */ | |
732 | diagnostic_output_format *m_output_format; | |
6feb628a MS |
733 | |
734 | /* Callback to set the locations of call sites along the inlining | |
735 | stack corresponding to a diagnostic location. Needed to traverse | |
736 | the BLOCK_SUPERCONTEXT() chain hanging off the LOCATION_BLOCK() | |
737 | of a diagnostic's location. */ | |
8200cd97 | 738 | set_locations_callback_t m_set_locations_cb; |
d3a57993 | 739 | |
79aaba0a | 740 | /* Optional callback for attempting to handle ICEs gracefully. */ |
8200cd97 | 741 | ice_handler_callback_t m_ice_handler_cb; |
79aaba0a | 742 | |
6cf276dd DM |
743 | /* A bundle of hooks for providing data to the context about its client |
744 | e.g. version information, plugins, etc. | |
745 | Used by SARIF output to give metadata about the client that's | |
746 | producing diagnostics. */ | |
747 | diagnostic_client_data_hooks *m_client_data_hooks; | |
4f01ae37 DM |
748 | |
749 | /* Support for diagrams. */ | |
750 | struct | |
751 | { | |
752 | /* Theme to use when generating diagrams. | |
753 | Can be NULL (if text art is disabled). */ | |
754 | text_art::theme *m_theme; | |
755 | ||
4f01ae37 | 756 | } m_diagrams; |
29ee5881 DM |
757 | |
758 | /* Owned by the context. */ | |
759 | char **m_original_argv; | |
e2840263 GDR |
760 | }; |
761 | ||
cb3e0eac | 762 | inline void |
0e94b750 MLI |
763 | diagnostic_inhibit_notes (diagnostic_context * context) |
764 | { | |
8200cd97 | 765 | context->m_inhibit_notes_p = true; |
0e94b750 MLI |
766 | } |
767 | ||
768 | ||
14082026 DM |
769 | /* Client supplied function to announce a diagnostic |
770 | (for text-based diagnostic output). */ | |
7da682c8 DM |
771 | inline diagnostic_text_starter_fn & |
772 | diagnostic_text_starter (diagnostic_context *context) | |
07e568d7 DM |
773 | { |
774 | return context->m_text_callbacks.m_begin_diagnostic; | |
775 | } | |
776 | ||
777 | /* Client supplied function called between disjoint spans of source code, | |
778 | so that the context can print | |
779 | something to indicate that a new span of source code has begun. */ | |
780 | inline diagnostic_start_span_fn & | |
781 | diagnostic_start_span (diagnostic_context *context) | |
782 | { | |
783 | return context->m_text_callbacks.m_start_span; | |
784 | } | |
6b67c26e GDR |
785 | |
786 | /* Client supplied function called after a diagnostic message is | |
14082026 | 787 | displayed (for text-based diagnostic output). */ |
7da682c8 DM |
788 | inline diagnostic_text_finalizer_fn & |
789 | diagnostic_text_finalizer (diagnostic_context *context) | |
07e568d7 DM |
790 | { |
791 | return context->m_text_callbacks.m_end_diagnostic; | |
792 | } | |
6b67c26e | 793 | |
cf835838 | 794 | /* Extension hooks for client. */ |
8200cd97 | 795 | #define diagnostic_context_auxiliary_data(DC) (DC)->m_client_aux_data |
cf835838 | 796 | #define diagnostic_info_auxiliary_data(DI) (DI)->x_data |
6b67c26e | 797 | |
b6fe0bb8 | 798 | /* Same as pp_format_decoder. Works on 'diagnostic_context *'. */ |
19363bf5 | 799 | #define diagnostic_format_decoder(DC) pp_format_decoder ((DC)->m_printer) |
6b67c26e | 800 | |
c5e3be45 | 801 | /* Same as pp_prefixing_rule. Works on 'diagnostic_context *'. */ |
19363bf5 | 802 | #define diagnostic_prefixing_rule(DC) pp_prefixing_rule ((DC)->m_printer) |
e2840263 | 803 | |
886e0865 | 804 | /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */ |
8200cd97 DM |
805 | inline void |
806 | diagnostic_abort_on_error (diagnostic_context *context) | |
807 | { | |
808 | context->m_abort_on_error = true; | |
809 | } | |
886e0865 | 810 | |
4fcc2065 | 811 | /* This diagnostic_context is used by front-ends that directly output |
764dbbf2 | 812 | diagnostic messages without going through `error', `warning', |
6b67c26e | 813 | and similar functions. */ |
f68fc4db | 814 | extern diagnostic_context *global_dc; |
764dbbf2 | 815 | |
f622a56b TC |
816 | /* Returns whether the diagnostic framework has been intialized already and is |
817 | ready for use. */ | |
d0bfd6ba DM |
818 | inline bool |
819 | diagnostic_ready_p () | |
820 | { | |
19363bf5 | 821 | return global_dc->m_printer != nullptr; |
d0bfd6ba | 822 | } |
f622a56b | 823 | |
2a2b2d43 | 824 | /* The number of errors that have been issued so far. Ideally, these |
4fcc2065 | 825 | would take a diagnostic_context as an argument. */ |
579bb65c | 826 | #define errorcount global_dc->diagnostic_count (DK_ERROR) |
2a2b2d43 | 827 | /* Similarly, but for warnings. */ |
579bb65c | 828 | #define warningcount global_dc->diagnostic_count (DK_WARNING) |
37e99116 | 829 | /* Similarly, but for warnings promoted to errors. */ |
579bb65c | 830 | #define werrorcount global_dc->diagnostic_count (DK_WERROR) |
2a2b2d43 | 831 | /* Similarly, but for sorrys. */ |
579bb65c | 832 | #define sorrycount global_dc->diagnostic_count (DK_SORRY) |
2a2b2d43 | 833 | |
cc2902df | 834 | /* Returns nonzero if warnings should be emitted. */ |
5f0f4a3b | 835 | #define diagnostic_report_warnings_p(DC, LOC) \ |
8200cd97 DM |
836 | (!(DC)->m_inhibit_warnings \ |
837 | && !(in_system_header_at (LOC) && !(DC)->m_warn_system_headers)) | |
2a2b2d43 | 838 | |
87cf0651 SB |
839 | /* Override the option index to be used for reporting a |
840 | diagnostic. */ | |
62a77bdf | 841 | |
cb3e0eac | 842 | inline void |
89991f31 DM |
843 | diagnostic_set_option_id (diagnostic_info *info, |
844 | diagnostic_option_id option_id) | |
62a77bdf | 845 | { |
89991f31 | 846 | info->option_id = option_id; |
62a77bdf | 847 | } |
87cf0651 | 848 | |
95bd1dd7 | 849 | /* Diagnostic related functions. */ |
8200cd97 DM |
850 | |
851 | inline void | |
852 | diagnostic_initialize (diagnostic_context *context, int n_opts) | |
853 | { | |
854 | context->initialize (n_opts); | |
855 | } | |
856 | ||
857 | inline void | |
858 | diagnostic_color_init (diagnostic_context *context, int value = -1) | |
859 | { | |
860 | context->color_init (value); | |
861 | } | |
862 | ||
863 | inline void | |
864 | diagnostic_urls_init (diagnostic_context *context, int value = -1) | |
865 | { | |
866 | context->urls_init (value); | |
867 | } | |
868 | ||
869 | inline void | |
870 | diagnostic_finish (diagnostic_context *context) | |
871 | { | |
872 | context->finish (); | |
873 | } | |
874 | ||
8625aa24 DM |
875 | inline void |
876 | diagnostic_show_locus (diagnostic_context *context, | |
877 | rich_location *richloc, | |
878 | diagnostic_t diagnostic_kind, | |
770657d0 DM |
879 | pretty_printer *pp = nullptr, |
880 | diagnostic_source_effect_info *effect_info = nullptr) | |
8625aa24 DM |
881 | { |
882 | gcc_assert (richloc); | |
770657d0 | 883 | context->maybe_show_locus (*richloc, diagnostic_kind, pp, effect_info); |
8625aa24 | 884 | } |
79cf5994 | 885 | |
3ac6b5cf LH |
886 | /* Because we read source files a second time after the frontend did it the |
887 | first time, we need to know how the frontend handled things like character | |
888 | set conversion and UTF-8 BOM stripping, in order to make everything | |
889 | consistent. This function needs to be called by each frontend that requires | |
890 | non-default behavior, to inform the diagnostics infrastructure how input is | |
891 | to be processed. The default behavior is to do no conversion and not to | |
892 | strip a UTF-8 BOM. | |
893 | ||
894 | The callback should return the input charset to be used to convert the given | |
895 | file's contents to UTF-8, or it should return NULL if no conversion is needed | |
896 | for this file. SHOULD_SKIP_BOM only applies in case no conversion was | |
897 | performed, and if true, it will cause a UTF-8 BOM to be skipped at the | |
898 | beginning of the file. (In case a conversion was performed, the BOM is | |
899 | rather skipped as part of the conversion process.) */ | |
900 | ||
8200cd97 DM |
901 | inline void |
902 | diagnostic_initialize_input_context (diagnostic_context *context, | |
903 | diagnostic_input_charset_callback ccb, | |
904 | bool should_skip_bom) | |
905 | { | |
906 | context->initialize_input_context (ccb, should_skip_bom); | |
907 | } | |
3ac6b5cf | 908 | |
79cf5994 | 909 | /* Force diagnostics controlled by OPTIDX to be kind KIND. */ |
8200cd97 DM |
910 | inline diagnostic_t |
911 | diagnostic_classify_diagnostic (diagnostic_context *context, | |
89991f31 | 912 | diagnostic_option_id option_id, |
8200cd97 DM |
913 | diagnostic_t kind, |
914 | location_t where) | |
915 | { | |
89991f31 | 916 | return context->classify_diagnostic (option_id, kind, where); |
8200cd97 DM |
917 | } |
918 | ||
919 | inline void | |
920 | diagnostic_push_diagnostics (diagnostic_context *context, | |
921 | location_t where) | |
922 | { | |
923 | context->push_diagnostics (where); | |
924 | } | |
925 | inline void | |
926 | diagnostic_pop_diagnostics (diagnostic_context *context, | |
927 | location_t where) | |
928 | { | |
929 | context->pop_diagnostics (where); | |
930 | } | |
931 | ||
932 | /* Report a diagnostic message (an error or a warning) as specified by | |
933 | DC. This function is *the* subroutine in terms of which front-ends | |
934 | should implement their specific diagnostic handling modules. The | |
935 | front-end independent format specifiers are exactly those described | |
936 | in the documentation of output_format. | |
937 | Return true if a diagnostic was printed, false otherwise. */ | |
938 | ||
939 | inline bool | |
940 | diagnostic_report_diagnostic (diagnostic_context *context, | |
941 | diagnostic_info *diagnostic) | |
942 | { | |
4d1f71d4 DM |
943 | context->begin_group (); |
944 | bool warned = context->report_diagnostic (diagnostic); | |
945 | context->end_group (); | |
946 | return warned; | |
8200cd97 DM |
947 | } |
948 | ||
db857e7d | 949 | #ifdef ATTRIBUTE_GCC_DIAG |
79a490a9 | 950 | extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *, |
8a645150 | 951 | rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0); |
178b58b5 | 952 | extern void diagnostic_set_info_translated (diagnostic_info *, const char *, |
8a645150 | 953 | va_list *, rich_location *, |
178b58b5 JM |
954 | diagnostic_t) |
955 | ATTRIBUTE_GCC_DIAG(2,0); | |
db857e7d | 956 | #endif |
7da682c8 DM |
957 | void default_diagnostic_text_starter (diagnostic_text_output_format &, |
958 | const diagnostic_info *); | |
876217ae DM |
959 | void default_diagnostic_start_span_fn (diagnostic_context *, |
960 | expanded_location); | |
7da682c8 DM |
961 | void default_diagnostic_text_finalizer (diagnostic_text_output_format &, |
962 | const diagnostic_info *, | |
963 | diagnostic_t); | |
9fec0042 MLI |
964 | void diagnostic_set_caret_max_width (diagnostic_context *context, int value); |
965 | ||
8200cd97 DM |
966 | inline void |
967 | diagnostic_action_after_output (diagnostic_context *context, | |
968 | diagnostic_t diag_kind) | |
969 | { | |
970 | context->action_after_output (diag_kind); | |
971 | } | |
972 | ||
973 | inline void | |
974 | diagnostic_check_max_errors (diagnostic_context *context, bool flush = false) | |
975 | { | |
976 | context->check_max_errors (flush); | |
977 | } | |
47b69537 | 978 | |
c9db45aa TB |
979 | int get_terminal_width (void); |
980 | ||
2a2703a2 MLI |
981 | /* Return the location associated to this diagnostic. Parameter WHICH |
982 | specifies which location. By default, expand the first one. */ | |
983 | ||
cb3e0eac | 984 | inline location_t |
2a2703a2 MLI |
985 | diagnostic_location (const diagnostic_info * diagnostic, int which = 0) |
986 | { | |
987 | return diagnostic->message.get_location (which); | |
988 | } | |
989 | ||
8a645150 DM |
990 | /* Return the number of locations to be printed in DIAGNOSTIC. */ |
991 | ||
cb3e0eac | 992 | inline unsigned int |
8a645150 DM |
993 | diagnostic_num_locations (const diagnostic_info * diagnostic) |
994 | { | |
995 | return diagnostic->message.m_richloc->get_num_locations (); | |
996 | } | |
997 | ||
2a2703a2 MLI |
998 | /* Expand the location of this diagnostic. Use this function for |
999 | consistency. Parameter WHICH specifies which location. By default, | |
1000 | expand the first one. */ | |
99abe958 | 1001 | |
cb3e0eac | 1002 | inline expanded_location |
2a2703a2 | 1003 | diagnostic_expand_location (const diagnostic_info * diagnostic, int which = 0) |
99abe958 | 1004 | { |
40499f81 | 1005 | return diagnostic->richloc->get_expanded_location (which); |
99abe958 MLI |
1006 | } |
1007 | ||
2a2703a2 MLI |
1008 | /* This is somehow the right-side margin of a caret line, that is, we |
1009 | print at least these many characters after the position pointed at | |
1010 | by the caret. */ | |
ba82e6b5 | 1011 | const int CARET_LINE_MARGIN = 10; |
2a2703a2 MLI |
1012 | |
1013 | /* Return true if the two locations can be represented within the same | |
1014 | caret line. This is used to build a prefix and also to determine | |
1015 | whether to print one or two caret lines. */ | |
1016 | ||
cb3e0eac | 1017 | inline bool |
2a2703a2 MLI |
1018 | diagnostic_same_line (const diagnostic_context *context, |
1019 | expanded_location s1, expanded_location s2) | |
1020 | { | |
c5c565ef DM |
1021 | return (s2.column && s1.line == s2.line |
1022 | && (context->m_source_printing.max_width - CARET_LINE_MARGIN | |
1023 | > abs (s1.column - s2.column))); | |
2a2703a2 MLI |
1024 | } |
1025 | ||
8a645150 | 1026 | extern const char *diagnostic_get_color_for_kind (diagnostic_t kind); |
2a2703a2 | 1027 | |
47b69537 | 1028 | /* Pure text formatting support functions. */ |
345ed1fe | 1029 | |
8e54f6d3 MLI |
1030 | extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1; |
1031 | ||
bc65bad2 MG |
1032 | /* Compute the number of digits in the decimal representation of an integer. */ |
1033 | extern int num_digits (int); | |
1034 | ||
8200cd97 | 1035 | inline bool |
89991f31 | 1036 | warning_enabled_at (location_t loc, diagnostic_option_id option_id) |
8200cd97 | 1037 | { |
89991f31 | 1038 | return global_dc->warning_enabled_at (loc, option_id); |
8200cd97 DM |
1039 | } |
1040 | ||
1041 | inline bool | |
89991f31 | 1042 | option_unspecified_p (diagnostic_option_id option_id) |
8200cd97 | 1043 | { |
89991f31 | 1044 | return global_dc->option_unspecified_p (option_id); |
8200cd97 | 1045 | } |
620cd786 | 1046 | |
6cf276dd DM |
1047 | extern char *get_cwe_url (int cwe); |
1048 | ||
ccbcde5e DM |
1049 | extern const char *get_diagnostic_kind_text (diagnostic_t kind); |
1050 | ||
7da682c8 DM |
1051 | const char *maybe_line_and_column (int line, int col); |
1052 | ||
88657302 | 1053 | #endif /* ! GCC_DIAGNOSTIC_H */ |