GCC Middle and Back End API Reference
diagnostic.h
Go to the documentation of this file.
1/* Various declarations for language-independent diagnostics subroutines.
2 Copyright (C) 2000-2025 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_DIAGNOSTIC_H
22#define GCC_DIAGNOSTIC_H
23
24#include "unique-argv.h"
25#include "rich-location.h"
26#include "pretty-print.h"
27#include "diagnostic-core.h"
28
29namespace diagnostics {
30 namespace digraphs {
31 class lazy_digraph;
32 } // namespace digraphs
33} // namespace diagnostics
34
35namespace text_art
36{
37 class theme;
38} // namespace text_art
39
40namespace xml
41{
42 class printer;
43} // namespace xml
44
45/* An enum for controlling what units to use for the column number
46 when diagnostics are output, used by the -fdiagnostics-column-unit option.
47 Tabs will be expanded or not according to the value of -ftabstop. The origin
48 (default 1) is controlled by -fdiagnostics-column-origin. */
49
51{
52 /* The default from GCC 11 onwards: display columns. */
54
55 /* The behavior in GCC 10 and earlier: simple bytes. */
57};
58
59/* An enum for controlling how to print non-ASCII characters/bytes when
60 a diagnostic suggests escaping the source code on output. */
61
63{
64 /* Escape non-ASCII Unicode characters in the form <U+XXXX> and
65 non-UTF-8 bytes in the form <XX>. */
67
68 /* Escape non-ASCII bytes in the form <XX> (thus showing the underlying
69 encoding of non-ASCII Unicode characters). */
71};
72
73/* Enum for overriding the standard output format. */
74
76{
77 /* The default: textual output. */
79
80 /* SARIF-based output, as JSON to stderr. */
82
83 /* SARIF-based output, to a JSON file. */
85};
86
87/* An enum for controlling how diagnostic_paths should be printed. */
89{
90 /* Don't print diagnostic_paths. */
92
93 /* Print diagnostic_paths by emitting a separate "note" for every event
94 in the path. */
96
97 /* Print diagnostic_paths by consolidating events together where they
98 are close enough, and printing such runs of events with multiple
99 calls to diagnostic_show_locus, showing the individual events in
100 each run via labels in the source. */
102};
103
104/* An enum for capturing values of GCC_EXTRA_DIAGNOSTIC_OUTPUT,
105 and for -fdiagnostics-parseable-fixits. */
106
108{
109 /* No extra output, or an unrecognized value. */
111
112 /* Emit fix-it hints using the "fixits-v1" format, equivalent to
113 -fdiagnostics-parseable-fixits. */
115
116 /* Emit fix-it hints using the "fixits-v2" format. */
118};
119
120/* Values for -fdiagnostics-text-art-charset=. */
121
123{
124 /* No text art diagrams shall be emitted. */
126
127 /* Use pure ASCII for text art diagrams. */
129
130 /* Use ASCII + conservative use of other unicode characters
131 in text art diagrams. */
133
134 /* Use Emoji. */
136};
137
138/* A diagnostic is described by the MESSAGE to send, the FILE and LINE of
139 its context and its KIND (ice, error, warning, note, ...) See complete
140 list in diagnostic.def. */
142{
144 : message (), richloc (), metadata (), x_data (), kind (), option_id (),
145 m_iinfo ()
146 { }
147
148 /* Text to be formatted. */
150
151 /* The location at which the diagnostic is to be reported. */
152 rich_location *richloc;
153
154 /* An optional bundle of metadata associated with the diagnostic
155 (or NULL). */
157
158 /* Auxiliary data for client. */
159 void *x_data;
160 /* The kind of diagnostic it is about. */
162 /* Which OPT_* directly controls this diagnostic. */
164
165 /* Inlining context containing locations for each call site along
166 the inlining stack. */
168 {
169 /* Locations along the inlining stack. */
171 /* The abstract origin of the location. */
172 void *m_ao;
173 /* Set if every M_ILOCS element is in a system header. */
176};
177
178/* Forward declarations. */
181
183 const diagnostic_info *);
184
185struct to_text;
186struct to_html;
187
189
190template <typename Sink>
192 Sink &sink,
193 expanded_location);
194
196 const diagnostic_info *,
198
199/* Abstract base class for the diagnostic subsystem to make queries
200 about command-line options. */
201
203{
204public:
206
207 /* Return 1 if option OPTION_ID is enabled, 0 if it is disabled,
208 or -1 if it isn't a simple on-off switch
209 (or if the value is unknown, typically set later in target). */
210 virtual int option_enabled_p (diagnostic_option_id option_id) const = 0;
211
212 /* Return malloced memory for the name of the option OPTION_ID
213 which enabled a diagnostic, originally of type ORIG_DIAG_KIND but
214 possibly converted to DIAG_KIND by options such as -Werror.
215 May return NULL if no name is to be printed.
216 May be passed 0 as well as the index of a particular option. */
217 virtual char *make_option_name (diagnostic_option_id option_id,
218 diagnostic_t orig_diag_kind,
219 diagnostic_t diag_kind) const = 0;
220
221 /* Return malloced memory for a URL describing the option that controls
222 a diagnostic.
223 May return NULL if no URL is available.
224 May be passed 0 as well as the index of a particular option. */
225 virtual char *make_option_url (diagnostic_option_id option_id) const = 0;
226};
227
228class edit_context;
236
237/* A stack of sets of classifications: each entry in the stack is
238 a mapping from option index to diagnostic severity that can be changed
239 via pragmas. The stack can be pushed and popped. */
240
242{
243public:
244 void init (int n_opts);
245 void fini ();
246
247 /* Save all diagnostic classifications in a stack. */
248 void push ();
249
250 /* Restore the topmost classification set off the stack. If the stack
251 is empty, revert to the state based on command line parameters. */
252 void pop (location_t where);
253
255 {
256 return get_current_override (option_id) == DK_UNSPECIFIED;
257 }
258
260 {
261 gcc_assert (option_id.m_idx < m_n_opts);
262 return m_classify_diagnostic[option_id.m_idx];
263 }
264
267 diagnostic_option_id option_id,
268 diagnostic_t new_kind,
269 location_t where);
270
273
274 int pch_save (FILE *);
275 int pch_restore (FILE *);
276
277private:
278 /* Each time a diagnostic's classification is changed with a pragma,
279 we record the change and the location of the change in an array of
280 these structs. */
282 {
283 location_t location;
284
285 /* For DK_POP, this is the index of the corresponding push (as stored
286 in m_push_list).
287 Otherwise, this is an option index. */
289
291 };
292
294
295 /* For each option index that can be passed to warning() et al
296 (OPT_* from options.h when using this code with the core GCC
297 options), this array may contain a new kind that the diagnostic
298 should be changed to before reporting, or DK_UNSPECIFIED to leave
299 it as the reported kind, or DK_IGNORED to not report it at
300 all. */
302
303 /* History of all changes to the classifications above. This list
304 is stored in location-order, so we can search it, either
305 binary-wise or end-to-front, to find the most recent
306 classification for a given diagnostic, given the location of the
307 diagnostic. */
309
310 /* For diagnostic_context::get_classification_history, declared later. */
311 friend class diagnostic_context;
312
313 /* For pragma push/pop. */
315};
316
317/* A bundle of options relating to printing the user's source code
318 (potentially with a margin, underlining, labels, etc). */
319
321{
322 /* True if we should print the source line with a caret indicating
323 the location.
324 Corresponds to -fdiagnostics-show-caret. */
326
327 /* Maximum width of the source line printed. */
329
330 /* Character used at the caret when printing source locations. */
331 char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
332
333 /* When printing source code, should the characters at carets and ranges
334 be colorized? (assuming colorization is on at all).
335 This should be true for frontends that generate range information
336 (so that the ranges of code are colorized),
337 and false for frontends that merely specify points within the
338 source code (to avoid e.g. colorizing just the first character in
339 a token, which would look strange). */
341
342 /* When printing source code, should labelled ranges be printed?
343 Corresponds to -fdiagnostics-show-labels. */
345
346 /* When printing source code, should there be a left-hand margin
347 showing line numbers?
348 Corresponds to -fdiagnostics-show-line-numbers. */
350
351 /* If printing source code, what should the minimum width of the margin
352 be? Line numbers will be right-aligned, and padded to this width.
353 Corresponds to -fdiagnostics-minimum-margin-width=VALUE. */
355
356 /* Usable by plugins; if true, print a debugging ruler above the
357 source output. */
359
360 /* When printing events in an inline path, should we print lines
361 visualizing links between related events (e.g. for CFG paths)?
362 Corresponds to -fdiagnostics-show-event-links. */
364};
365
366/* A bundle of state for determining column numbers in diagnostics
367 (tab stops, whether to start at 0 or 1, etc).
368 Uses a file_cache to handle tabs. */
369
371{
372public:
374
375 int converted_column (expanded_location s) const;
376
377 label_text get_location_text (const expanded_location &s,
378 bool show_column,
379 bool colorize) const;
380
381 int get_tabstop () const { return m_tabstop; }
382
383private:
388};
389
390/* A bundle of state for printing locations within diagnostics
391 (e.g. "FILENAME:LINE:COLUMN"), to isolate the interactions between
392 diagnostic_context and the start_span callbacks. */
393
395{
396public:
399
400 bool show_column_p () const { return m_show_column; }
401
404
405 void
407 pretty_printer &pp,
408 const expanded_location &exploc);
409
410 void
412 xml::printer &xp,
413 const expanded_location &exploc);
414
415private:
418};
419
420/* Abstract base class for optionally supplying extra tags when writing
421 out annotation labels in HTML output. */
422
424{
425public:
426 virtual ~html_label_writer () {}
427 virtual void begin_label () = 0;
428 virtual void end_label () = 0;
429};
430
431/* A bundle of state for printing source within a diagnostic,
432 to isolate the interactions between diagnostic_context and the
433 implementation of diagnostic_show_locus. */
434
436{
437public:
441
442 void
444 const rich_location &richloc,
445 diagnostic_t diagnostic_kind,
446 diagnostic_source_effect_info *effect_info) const;
447
448 void
450 const rich_location &richloc,
451 diagnostic_t diagnostic_kind,
453 html_label_writer *label_writer) const;
454
456 get_options () const { return m_options; }
457
460
463
464 file_cache &
465 get_file_cache () const { return m_file_cache; }
466
469 {
470 return m_escape_format;
471 }
472
475
477 {
478 return m_location_policy.get_column_policy ();
479 }
480
485
486private:
492
493 /* Other data copied from diagnostic_context. */
496};
497
498/* A collection of counters of diagnostics, per-kind
499 (e.g. "3 errors and 1 warning"), for use by both diagnostic_context
500 and by diagnostic_buffer. */
501
503{
505
506 void dump (FILE *out, int indent) const;
507 void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
508
509 int get_count (diagnostic_t kind) const { return m_count_for_kind[kind]; }
510
511 void move_to (diagnostic_counters &dest);
512 void clear ();
513
515};
516
517/* This class encapsulates the state of the diagnostics subsystem
518 as a whole (either directly, or via owned objects of other classes, to
519 avoid global variables).
520
521 It has responsibility for:
522 - being a central place for clients to report diagnostics
523 - reporting those diagnostics to zero or more output sinks
524 (e.g. text vs SARIF)
525 - providing a "dump" member function for a debug dump of the state of
526 the diagnostics subsytem
527 - direct vs buffered diagnostics (see class diagnostic_buffer)
528 - tracking the original argv of the program (for SARIF output)
529 - crash-handling
530
531 It delegates responsibility to various other classes:
532 - the various output sinks (instances of diagnostic_output_format
533 subclasses)
534 - formatting of messages (class pretty_printer)
535 - an optional urlifier to inject URLs into formatted messages
536 - counting the number of diagnostics reported of each kind
537 (class diagnostic_counters)
538 - calling out to a diagnostic_option_manager to determine if
539 a particular warning is enabled or disabled
540 - tracking pragmas that enable/disable warnings in a range of
541 source code
542 - a cache for use when quoting the user's source code (class file_cache)
543 - a text_art::theme
544 - an edit_context for generating patches from fix-it hints
545 - diagnostic_client_data_hooks for metadata.
546
547 Try to avoid adding new responsibilities to this class itself, to avoid
548 the "blob" anti-pattern. */
549
551{
552public:
553 /* Give access to m_text_callbacks. */
560
563 friend class diagnostic_buffer;
564
567
568 void initialize (int n_opts);
569 void color_init (int value);
570 void urls_init (int value);
571 void set_pretty_printer (std::unique_ptr<pretty_printer> pp);
572 void refresh_output_sinks ();
573
574 void finish ();
575
576 void dump (FILE *out) const;
577 void DEBUG_FUNCTION dump () const { dump (stderr); }
578
579 bool execution_failed_p () const;
580
581 void set_original_argv (unique_argv original_argv);
582 const char * const *get_original_argv ()
583 {
584 return const_cast<const char * const *> (m_original_argv);
585 }
586
591
592 void
594 bool should_skip_bom);
595
596 void begin_group ();
597 void end_group ();
598
599 void push_nesting_level ();
600 void pop_nesting_level ();
601
602 bool warning_enabled_at (location_t loc, diagnostic_option_id option_id);
603
605 {
606 return m_option_classifier.option_unspecified_p (option_id);
607 }
608
610 rich_location &richloc,
611 const diagnostic_metadata *metadata,
612 diagnostic_option_id option_id,
613 const char *gmsgid, ...)
616 rich_location &richloc,
617 const diagnostic_metadata *metadata,
618 diagnostic_option_id option_id,
619 const char *gmsgid, va_list *ap)
621
623 void report_verbatim (text_info &);
624
625 /* Report a directed graph associated with the run as a whole
626 to any sinks that support directed graphs. */
627 void
628 report_global_digraph (const diagnostics::digraphs::lazy_digraph &);
629
632 diagnostic_t new_kind,
633 location_t where)
634 {
635 return m_option_classifier.classify_diagnostic (this,
636 option_id,
637 new_kind,
638 where);
639 }
640
641 void push_diagnostics (location_t where ATTRIBUTE_UNUSED)
642 {
643 m_option_classifier.push ();
644 }
645 void pop_diagnostics (location_t where)
646 {
647 m_option_classifier.pop (where);
648 }
649
650 void maybe_show_locus (const rich_location &richloc,
652 diagnostic_t diagnostic_kind,
653 pretty_printer &pp,
654 diagnostic_source_effect_info *effect_info);
655 void maybe_show_locus_as_html (const rich_location &richloc,
657 diagnostic_t diagnostic_kind,
658 xml::printer &xp,
660 html_label_writer *label_writer);
661
662 void emit_diagram (const diagnostic_diagram &diagram);
663
664 /* Various setters for use by option-handling logic. */
665 void set_output_format (std::unique_ptr<diagnostic_output_format> output_format);
667 void set_client_data_hooks (std::unique_ptr<diagnostic_client_data_hooks> hooks);
668
669 void push_owned_urlifier (std::unique_ptr<urlifier>);
670 void push_borrowed_urlifier (const urlifier &);
671 void pop_urlifier ();
672
673 void create_edit_context ();
675 {
677 }
678 void set_report_bug (bool val) { m_report_bug = val; }
683 void set_show_cwe (bool val) { m_show_cwe = val; }
684 void set_show_rules (bool val) { m_show_rules = val; }
685 void set_show_highlight_colors (bool val);
687 {
688 m_path_format = val;
689 }
690 void set_show_path_depths (bool val) { m_show_path_depths = val; }
692 void set_max_errors (int val) { m_max_errors = val; }
694 {
695 m_escape_format = val;
696 }
697
698 void set_format_decoder (printer_fn format_decoder);
700
701 /* Various accessors. */
703 {
705 }
706 bool show_path_depths_p () const { return m_show_path_depths; }
710 {
711 return m_escape_format;
712 }
713
714 file_cache &
716 {
718 return *m_file_cache;
719 }
720
722 {
723 return m_edit_context_ptr;
724 }
729
732
733 const urlifier *get_urlifier () const;
734
735 text_art::theme *get_diagram_theme () const { return m_diagrams.m_theme; }
736
738 {
739 return m_diagnostic_counters.m_count_for_kind[kind];
740 }
742 {
743 return m_diagnostic_counters.get_count (kind);
744 }
745
746 /* Option-related member functions. */
747 inline bool option_enabled_p (diagnostic_option_id option_id) const
748 {
749 if (!m_option_mgr)
750 return true;
751 return m_option_mgr->option_enabled_p (option_id);
752 }
753
754 inline char *make_option_name (diagnostic_option_id option_id,
755 diagnostic_t orig_diag_kind,
756 diagnostic_t diag_kind) const
757 {
758 if (!m_option_mgr)
759 return nullptr;
760 return m_option_mgr->make_option_name (option_id,
761 orig_diag_kind,
762 diag_kind);
763 }
764
765 inline char *make_option_url (diagnostic_option_id option_id) const
766 {
767 if (!m_option_mgr)
768 return nullptr;
769 return m_option_mgr->make_option_url (option_id);
770 }
771
772 void
773 set_option_manager (std::unique_ptr<diagnostic_option_manager> mgr,
774 unsigned lang_mask);
775
776 unsigned get_lang_mask () const
777 {
778 return m_lang_mask;
779 }
780
781 bool diagnostic_impl (rich_location *, const diagnostic_metadata *,
782 diagnostic_option_id, const char *,
783 va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
784 bool diagnostic_n_impl (rich_location *, const diagnostic_metadata *,
785 diagnostic_option_id, unsigned HOST_WIDE_INT,
786 const char *, const char *, va_list *,
788
790 {
791 return m_diagnostic_groups.m_diagnostic_nesting_level;
792 }
793
794 char *build_indent_prefix () const;
795
796 int
797 pch_save (FILE *f)
798 {
799 return m_option_classifier.pch_save (f);
800 }
801
802 int
803 pch_restore (FILE *f)
804 {
805 return m_option_classifier.pch_restore (f);
806 }
807
808
816
817 std::unique_ptr<pretty_printer> clone_printer () const
818 {
819 return m_reference_printer->clone ();
820 }
821
826
827 void
828 add_sink (std::unique_ptr<diagnostic_output_format>);
829
831
832 bool supports_fnotice_on_stderr_p () const;
833
834 /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
835 void
837 {
838 m_abort_on_error = val;
839 }
840
841 /* Accessor for use in serialization, e.g. by C++ modules. */
842 auto &
844 {
845 return m_option_classifier.m_classification_history;
846 }
847
848 void set_main_input_filename (const char *filename);
849
850 void
852 {
853 m_opt_permissive = opt_permissive;
854 }
855
856 void
857 set_fatal_errors (bool fatal_errors)
858 {
859 m_fatal_errors = fatal_errors;
860 }
861
862 void
864 const char *,
865 va_list *))
866 {
867 m_internal_error = cb;
868 }
869
870 void
876
877 void
879
880private:
882
884
886
887 void check_max_errors (bool flush);
888 void action_after_output (diagnostic_t diag_kind);
889
890 /* Data members.
891 Ideally, all of these would be private. */
892
893private:
894 /* A reference instance of pretty_printer created by the client
895 and owned by the context. Used for cloning when creating/adding
896 output formats.
897 Owned by the context; this would be a std::unique_ptr if
898 diagnostic_context had a proper ctor. */
900
901 /* Cache of source code.
902 Owned by the context; this would be a std::unique_ptr if
903 diagnostic_context had a proper ctor. */
905
906 /* The number of times we have issued diagnostics. */
908
909 /* True if it has been requested that warnings be treated as errors. */
911
912 /* The number of option indexes that can be passed to warning() et
913 al. */
915
916 /* The stack of sets of overridden diagnostic option severities. */
918
919 /* True if we should print any CWE identifiers associated with
920 diagnostics. */
922
923 /* True if we should print any rules associated with diagnostics. */
925
926 /* How should diagnostic_path objects be printed. */
928
929 /* True if we should print stack depths when printing diagnostic paths. */
931
932 /* True if we should print the command line option which controls
933 each diagnostic, if known. */
935
936 /* True if we should raise a SIGABRT on errors. */
938
939public:
940 /* True if we should show the column number on diagnostics. */
942
943 /* True if pedwarns are errors. */
945
946 /* True if permerrors are warnings. */
948
949private:
950 /* The option to associate with turning permerrors into warnings,
951 if any. */
953
954 /* True if errors are fatal. */
956
957public:
958 /* True if all warnings should be disabled. */
960
961 /* True if warnings should be given in system headers. */
963
964private:
965 /* Maximum number of errors to report. */
967
968 /* Client-supplied callbacks for use in text output. */
969 struct {
970 /* This function is called before any message is printed out. It is
971 responsible for preparing message prefix and such. For example, it
972 might say:
973 In file included from "/usr/local/include/curses.h:5:
974 from "/home/gdr/src/nifty_printer.h:56:
975 ...
976 */
978
979 /* This function is called by diagnostic_show_locus in between
980 disjoint spans of source code, so that the context can print
981 something to indicate that a new span of source code has begun. */
984
985 /* This function is called after the diagnostic message is printed. */
988
989 /* Client hook to report an internal error. */
990 void (*m_internal_error) (diagnostic_context *, const char *, va_list *);
991
992 /* Client hook to adjust properties of the given diagnostic that we're
993 about to issue, such as its kind. */
995
996 /* Owned by the context; this would be a std::unique_ptr if
997 diagnostic_context had a proper ctor. */
999 unsigned m_lang_mask;
1000
1001 /* A stack of optional hooks for adding URLs to quoted text strings in
1002 diagnostics. Only used for the main diagnostic message.
1003 Typically a single one owner by the context, but can be temporarily
1004 overridden by a borrowed urlifier (e.g. on-stack). */
1011
1012public:
1013 /* Auxiliary data for client. */
1015
1016 /* Used to detect that the last caret was printed at the same location. */
1018
1019private:
1021
1023
1024public:
1026
1027private:
1028 /* True if -freport-bug option is used. */
1030
1031 /* Used to specify additional diagnostic output to be emitted after the
1032 rest of the diagnostic. This is for implementing
1033 -fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT. */
1035
1036public:
1037 /* What units to use when outputting the column number. */
1039
1040 /* The origin for the column number (1-based or 0-based typically). */
1042
1043 /* The size of the tabstop for tab expansion. */
1045
1046private:
1047 /* How should non-ASCII/non-printable bytes be escaped when
1048 a diagnostic suggests escaping the source code on output. */
1050
1051 /* If non-NULL, an edit_context to which fix-it hints should be
1052 applied, for generating patches.
1053 Owned by the context; this would be a std::unique_ptr if
1054 diagnostic_context had a proper ctor. */
1056
1057 /* Fields relating to diagnostic groups. */
1058 struct {
1059 /* How many diagnostic_group instances are currently alive. */
1061
1062 /* How many nesting levels have been pushed within this group. */
1064
1065 /* How many diagnostics have been emitted since the bottommost
1066 diagnostic_group was pushed. */
1068
1069 /* The "group+diagnostic" nesting depth from which to inhibit notes. */
1072
1073 void inhibit_notes_in_group (bool inhibit = true);
1074 bool notes_inhibited_in_group () const;
1075
1076 /* The various sinks to which diagnostics are to be outputted
1077 (text vs structured formats such as SARIF).
1078 The sinks are owned by the context; this would be a
1079 std::vector<std::unique_ptr> if diagnostic_context had a
1080 proper ctor. */
1082
1083 /* Callback to set the locations of call sites along the inlining
1084 stack corresponding to a diagnostic location. Needed to traverse
1085 the BLOCK_SUPERCONTEXT() chain hanging off the LOCATION_BLOCK()
1086 of a diagnostic's location. */
1088
1089 /* A bundle of hooks for providing data to the context about its client
1090 e.g. version information, plugins, etc.
1091 Used by SARIF output to give metadata about the client that's
1092 producing diagnostics.
1093 Owned by the context; this would be a std::unique_ptr if
1094 diagnostic_context had a proper ctor. */
1096
1097 /* Support for diagrams. */
1098 struct
1099 {
1100 /* Theme to use when generating diagrams.
1101 Can be NULL (if text art is disabled).
1102 Owned by the context; this would be a std::unique_ptr if
1103 diagnostic_context had a proper ctor. */
1105
1107
1108 /* Owned by the context. */
1110
1111 /* Borrowed pointer to the active diagnostic_buffer, if any.
1112 If null (the default), then diagnostics that are reported to the
1113 context are immediately issued to the output format.
1114 If non-null, then diagnostics that are reported to the context
1115 are buffered in the buffer, and may be issued to the output format
1116 later (if the buffer is flushed), moved to other buffers, or
1117 discarded (if the buffer is cleared). */
1119};
1120
1121/* Client supplied function to announce a diagnostic
1122 (for text-based diagnostic output). */
1128
1129/* Client supplied function called between disjoint spans of source code,
1130 so that the context can print
1131 something to indicate that a new span of source code has begun. */
1137
1138/* Client supplied function called after a diagnostic message is
1139 displayed (for text-based diagnostic output). */
1145
1146/* Extension hooks for client. */
1147#define diagnostic_context_auxiliary_data(DC) (DC)->m_client_aux_data
1148#define diagnostic_info_auxiliary_data(DI) (DI)->x_data
1149
1150/* This diagnostic_context is used by front-ends that directly output
1151 diagnostic messages without going through `error', `warning',
1152 and similar functions. */
1154
1155/* The number of errors that have been issued so far. Ideally, these
1156 would take a diagnostic_context as an argument. */
1157#define errorcount global_dc->diagnostic_count (DK_ERROR)
1158/* Similarly, but for warnings. */
1159#define warningcount global_dc->diagnostic_count (DK_WARNING)
1160/* Similarly, but for warnings promoted to errors. */
1161#define werrorcount global_dc->diagnostic_count (DK_WERROR)
1162/* Similarly, but for sorrys. */
1163#define sorrycount global_dc->diagnostic_count (DK_SORRY)
1164
1165/* Returns nonzero if warnings should be emitted. */
1166#define diagnostic_report_warnings_p(DC, LOC) \
1167 (!(DC)->m_inhibit_warnings \
1168 && !(in_system_header_at (LOC) && !(DC)->m_warn_system_headers))
1169
1170/* Override the option index to be used for reporting a
1171 diagnostic. */
1172
1173inline void
1175 diagnostic_option_id option_id)
1176{
1177 info->option_id = option_id;
1178}
1179
1180/* Diagnostic related functions. */
1181
1182inline void
1184{
1185 context->initialize (n_opts);
1186}
1187
1188inline void
1190{
1191 context->color_init (value);
1192}
1193
1194inline void
1196{
1197 context->urls_init (value);
1198}
1199
1200inline void
1202{
1203 context->finish ();
1204}
1205
1206inline void
1209 rich_location *richloc,
1210 diagnostic_t diagnostic_kind,
1211 pretty_printer *pp,
1212 diagnostic_source_effect_info *effect_info = nullptr)
1213{
1214 gcc_assert (context);
1215 gcc_assert (richloc);
1216 gcc_assert (pp);
1217 context->maybe_show_locus (*richloc, opts, diagnostic_kind, *pp, effect_info);
1218}
1219
1220inline void
1223 rich_location *richloc,
1224 diagnostic_t diagnostic_kind,
1225 xml::printer &xp,
1226 diagnostic_source_effect_info *effect_info = nullptr,
1227 html_label_writer *label_writer = nullptr)
1228{
1229 gcc_assert (context);
1230 gcc_assert (richloc);
1231 context->maybe_show_locus_as_html (*richloc, opts, diagnostic_kind, xp,
1232 effect_info, label_writer);
1233}
1234
1235/* Because we read source files a second time after the frontend did it the
1236 first time, we need to know how the frontend handled things like character
1237 set conversion and UTF-8 BOM stripping, in order to make everything
1238 consistent. This function needs to be called by each frontend that requires
1239 non-default behavior, to inform the diagnostics infrastructure how input is
1240 to be processed. The default behavior is to do no conversion and not to
1241 strip a UTF-8 BOM.
1242
1243 The callback should return the input charset to be used to convert the given
1244 file's contents to UTF-8, or it should return NULL if no conversion is needed
1245 for this file. SHOULD_SKIP_BOM only applies in case no conversion was
1246 performed, and if true, it will cause a UTF-8 BOM to be skipped at the
1247 beginning of the file. (In case a conversion was performed, the BOM is
1248 rather skipped as part of the conversion process.) */
1249
1250inline void
1253 bool should_skip_bom)
1254{
1255 context->initialize_input_context (ccb, should_skip_bom);
1256}
1257
1258/* Force diagnostics controlled by OPTIDX to be kind KIND. */
1259inline diagnostic_t
1261 diagnostic_option_id option_id,
1262 diagnostic_t kind,
1263 location_t where)
1264{
1265 return context->classify_diagnostic (option_id, kind, where);
1266}
1267
1268inline void
1270 location_t where)
1271{
1272 context->push_diagnostics (where);
1273}
1274inline void
1276 location_t where)
1277{
1278 context->pop_diagnostics (where);
1279}
1280
1281/* Report a diagnostic message (an error or a warning) as specified by
1282 DC. This function is *the* subroutine in terms of which front-ends
1283 should implement their specific diagnostic handling modules. The
1284 front-end independent format specifiers are exactly those described
1285 in the documentation of output_format.
1286 Return true if a diagnostic was printed, false otherwise. */
1287
1288inline bool
1291{
1292 context->begin_group ();
1293 bool warned = context->report_diagnostic (diagnostic);
1294 context->end_group ();
1295 return warned;
1296}
1297
1298#ifdef ATTRIBUTE_GCC_DIAG
1299extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
1300 rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
1302 va_list *, rich_location *,
1304 ATTRIBUTE_GCC_DIAG(2,0);
1305#endif
1307 const diagnostic_info *);
1308template <typename Sink>
1310 Sink &sink,
1311 expanded_location);
1313 const diagnostic_info *,
1314 diagnostic_t);
1316
1317int get_terminal_width (void);
1318
1319/* Return the location associated to this diagnostic. Parameter WHICH
1320 specifies which location. By default, expand the first one. */
1321
1322inline location_t
1324{
1325 return diagnostic->message.get_location (which);
1326}
1327
1328/* Return the number of locations to be printed in DIAGNOSTIC. */
1329
1330inline unsigned int
1332{
1333 return diagnostic->message.m_richloc->get_num_locations ();
1334}
1335
1336/* Expand the location of this diagnostic. Use this function for
1337 consistency. Parameter WHICH specifies which location. By default,
1338 expand the first one. */
1339
1340inline expanded_location
1342{
1343 return diagnostic->richloc->get_expanded_location (which);
1344}
1345
1346/* This is somehow the right-side margin of a caret line, that is, we
1347 print at least these many characters after the position pointed at
1348 by the caret. */
1349const int CARET_LINE_MARGIN = 10;
1350
1351/* Return true if the two locations can be represented within the same
1352 caret line. This is used to build a prefix and also to determine
1353 whether to print one or two caret lines. */
1354
1355inline bool
1357 expanded_location s1, expanded_location s2)
1358{
1359 return (s2.column && s1.line == s2.line
1361 > abs (s1.column - s2.column)));
1362}
1363
1364extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
1365
1366/* Pure text formatting support functions. */
1367
1368extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
1369
1370/* Compute the number of digits in the decimal representation of an integer. */
1371extern int num_digits (int);
1372
1373inline bool
1374warning_enabled_at (location_t loc, diagnostic_option_id option_id)
1375{
1376 return global_dc->warning_enabled_at (loc, option_id);
1377}
1378
1379inline bool
1381{
1382 return global_dc->option_unspecified_p (option_id);
1383}
1384
1385extern char *get_cwe_url (int cwe);
1386
1387extern const char *get_diagnostic_kind_text (diagnostic_t kind);
1388
1389const char *maybe_line_and_column (int line, int col);
1390
1391#endif /* ! GCC_DIAGNOSTIC_H */
Definition vec.h:1667
Definition diagnostic-buffer.h:57
Definition diagnostic-client-data-hooks.h:33
Definition diagnostic.h:371
label_text get_location_text(const expanded_location &s, bool show_column, bool colorize) const
Definition diagnostic.cc:768
enum diagnostics_column_unit m_column_unit
Definition diagnostic.h:385
int m_column_origin
Definition diagnostic.h:386
diagnostic_column_policy(const diagnostic_context &dc)
Definition diagnostic.cc:744
int converted_column(expanded_location s) const
Definition diagnostic.cc:756
int m_tabstop
Definition diagnostic.h:387
int get_tabstop() const
Definition diagnostic.h:381
file_cache & m_file_cache
Definition diagnostic.h:384
Definition diagnostic.h:551
struct diagnostic_context::@012375117275062000312167204021321243213276373064 m_diagnostic_groups
void action_after_output(diagnostic_t diag_kind)
Definition diagnostic.cc:941
void push_owned_urlifier(std::unique_ptr< urlifier >)
Definition diagnostic.cc:567
friend class diagnostic_source_print_policy
Definition diagnostic.h:561
int diagnostic_count(diagnostic_t kind) const
Definition diagnostic.h:741
bool bool emit_diagnostic_with_group_va(diagnostic_t kind, rich_location &richloc, const diagnostic_metadata *metadata, diagnostic_option_id option_id, const char *gmsgid, va_list *ap) ATTRIBUTE_GCC_DIAG(6
Definition diagnostic.cc:1396
int m_tabstop
Definition diagnostic.h:1044
void initialize(int n_opts)
Definition diagnostic.cc:221
bool notes_inhibited_in_group() const
Definition diagnostic.cc:1048
file_cache * m_file_cache
Definition diagnostic.h:904
bool execution_failed_p() const
Definition diagnostic.cc:478
void set_show_rules(bool val)
Definition diagnostic.h:684
void get_any_inlining_info(diagnostic_info *diagnostic)
Definition diagnostic.cc:1226
enum diagnostic_path_format m_path_format
Definition diagnostic.h:927
void finish()
Definition diagnostic.cc:386
void set_main_input_filename(const char *filename)
Definition diagnostic.cc:528
pretty_printer * get_reference_printer() const
Definition diagnostic.h:822
void end_group()
Definition diagnostic.cc:1830
void error_recursion() ATTRIBUTE_NORETURN
Definition diagnostic.cc:1762
int m_diagnostic_nesting_level
Definition diagnostic.h:1063
void set_escape_format(enum diagnostics_escape_format val)
Definition diagnostic.h:693
bool diagnostic_enabled(diagnostic_info *diagnostic)
Definition diagnostic.cc:1310
struct diagnostic_context::@025320134223110177324072134063066351130257375203 m_text_callbacks
void maybe_show_locus_as_html(const rich_location &richloc, const diagnostic_source_printing_options &opts, diagnostic_t diagnostic_kind, xml::printer &xp, diagnostic_source_effect_info *effect_info, html_label_writer *label_writer)
Definition diagnostic-show-locus.cc:3877
void(* set_locations_callback_t)(diagnostic_context *, diagnostic_info *)
Definition diagnostic.h:565
bool m_show_option_requested
Definition diagnostic.h:934
void set_set_locations_callback(set_locations_callback_t cb)
Definition diagnostic.h:587
void DEBUG_FUNCTION dump() const
Definition diagnostic.h:577
bool m_report_bug
Definition diagnostic.h:1029
void inhibit_notes_in_group(bool inhibit=true)
Definition diagnostic.cc:1018
void remove_all_output_sinks()
Definition diagnostic.cc:488
void refresh_output_sinks()
Definition diagnostic.cc:626
void set_fatal_errors(bool fatal_errors)
Definition diagnostic.h:857
edit_context * get_edit_context() const
Definition diagnostic.h:721
void push_nesting_level()
Definition diagnostic.cc:1847
void set_format_decoder(printer_fn format_decoder)
Definition diagnostic.cc:636
void set_path_format(enum diagnostic_path_format val)
Definition diagnostic.h:686
friend diagnostic_text_starter_fn & diagnostic_text_starter(diagnostic_context *context)
Definition diagnostic.h:1124
void set_diagnostic_buffer(diagnostic_buffer *)
Definition diagnostic.cc:1948
void set_max_errors(int val)
Definition diagnostic.h:692
friend class diagnostic_text_output_format
Definition diagnostic.h:562
int pch_restore(FILE *f)
Definition diagnostic.h:803
void set_option_manager(std::unique_ptr< diagnostic_option_manager > mgr, unsigned lang_mask)
Definition diagnostic.cc:558
enum diagnostics_extra_output_kind m_extra_output_kind
Definition diagnostic.h:1034
bool m_inhibit_warnings
Definition diagnostic.h:959
int m_emission_count
Definition diagnostic.h:1067
friend diagnostic_text_finalizer_fn & diagnostic_text_finalizer(diagnostic_context *context)
Definition diagnostic.h:1141
diagnostic_output_format & get_output_format(size_t idx) const
Definition diagnostic.cc:503
bool m_show_column
Definition diagnostic.h:941
void add_sink(std::unique_ptr< diagnostic_output_format >)
Definition diagnostic.cc:511
bool bool diagnostic_n_impl(rich_location *, const diagnostic_metadata *, diagnostic_option_id, unsigned HOST_WIDE_INT, const char *, const char *, va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(7
Definition diagnostic.cc:1716
struct diagnostic_context::@144115345167042231333361231316114173002254305105 m_diagrams
diagnostic_option_classifier m_option_classifier
Definition diagnostic.h:917
diagnostic_option_id m_opt_permissive
Definition diagnostic.h:952
void report_verbatim(text_info &)
Definition diagnostic.cc:1614
bool m_show_path_depths
Definition diagnostic.h:930
int & diagnostic_count(diagnostic_t kind)
Definition diagnostic.h:737
char * make_option_url(diagnostic_option_id option_id) const
Definition diagnostic.h:765
void push_diagnostics(location_t where)
Definition diagnostic.h:641
void begin_group()
Definition diagnostic.cc:1824
enum diagnostics_escape_format m_escape_format
Definition diagnostic.h:1049
set_locations_callback_t m_set_locations_cb
Definition diagnostic.h:1087
void set_internal_error_callback(void(*cb)(diagnostic_context *, const char *, va_list *))
Definition diagnostic.h:863
void set_output_format(std::unique_ptr< diagnostic_output_format > output_format)
Definition diagnostic.cc:496
void set_show_path_depths(bool val)
Definition diagnostic.h:690
diagnostic_start_span_fn< to_text > m_text_start_span
Definition diagnostic.h:982
char * make_option_name(diagnostic_option_id option_id, diagnostic_t orig_diag_kind, diagnostic_t diag_kind) const
Definition diagnostic.h:754
diagnostic_counters m_diagnostic_counters
Definition diagnostic.h:907
std::unique_ptr< pretty_printer > clone_printer() const
Definition diagnostic.h:817
const char *const * get_original_argv()
Definition diagnostic.h:582
void set_pretty_printer(std::unique_ptr< pretty_printer > pp)
Definition diagnostic.cc:616
bool m_warn_system_headers
Definition diagnostic.h:962
char * build_indent_prefix() const
void flush_diagnostic_buffer(diagnostic_buffer &)
Definition diagnostic.cc:1998
diagnostic_text_starter_fn m_begin_diagnostic
Definition diagnostic.h:977
enum diagnostic_path_format get_path_format() const
Definition diagnostic.h:708
int pch_save(FILE *f)
Definition diagnostic.h:797
pretty_printer * m_reference_printer
Definition diagnostic.h:899
char ** m_original_argv
Definition diagnostic.h:1109
diagnostic_client_data_hooks * m_client_data_hooks
Definition diagnostic.h:1095
void(* m_internal_error)(diagnostic_context *, const char *, va_list *)
Definition diagnostic.h:990
bool warning_enabled_at(location_t loc, diagnostic_option_id option_id)
Definition diagnostic.cc:1354
bool m_show_cwe
Definition diagnostic.h:921
diagnostic_text_finalizer_fn m_end_diagnostic
Definition diagnostic.h:986
void pop_urlifier()
Definition diagnostic.cc:583
void * m_client_aux_data
Definition diagnostic.h:1014
void set_client_data_hooks(std::unique_ptr< diagnostic_client_data_hooks > hooks)
Definition diagnostic.cc:536
diagnostic_option_manager * m_option_mgr
Definition diagnostic.h:998
void set_prefixing_rule(diagnostic_prefixing_rule_t rule)
Definition diagnostic.cc:653
auto & get_classification_history()
Definition diagnostic.h:843
void inhibit_notes()
Definition diagnostic.h:878
void set_warning_as_error_requested(bool val)
Definition diagnostic.h:674
location_t m_last_location
Definition diagnostic.h:1017
void check_max_errors(bool flush)
Definition diagnostic.cc:917
unsigned get_lang_mask() const
Definition diagnostic.h:776
void push_borrowed_urlifier(const urlifier &)
Definition diagnostic.cc:575
auto_vec< urlifier_stack_node > * m_urlifier_stack
Definition diagnostic.h:1010
void set_adjust_diagnostic_info_callback(void(*cb)(diagnostic_context *, diagnostic_info *))
Definition diagnostic.h:871
void pop_nesting_level()
Definition diagnostic.cc:1853
enum diagnostics_escape_format get_escape_format() const
Definition diagnostic.h:709
int m_inhibiting_notes_from
Definition diagnostic.h:1070
bool emit_diagnostic_with_group(diagnostic_t kind, rich_location &richloc, const diagnostic_metadata *metadata, diagnostic_option_id option_id, const char *gmsgid,...) ATTRIBUTE_GCC_DIAG(6
Definition diagnostic.cc:1373
const logical_location_manager * get_logical_location_manager() const
Definition diagnostic.cc:594
void set_text_art_charset(enum diagnostic_text_art_charset charset)
Definition diagnostic.cc:1915
auto_vec< diagnostic_output_format * > m_output_sinks
Definition diagnostic.h:1081
const urlifier * get_urlifier() const
Definition diagnostic.cc:602
text_art::theme * m_theme
Definition diagnostic.h:1104
bool m_inhibit_notes_p
Definition diagnostic.h:1022
bool show_path_depths_p() const
Definition diagnostic.h:706
bool supports_fnotice_on_stderr_p() const
Definition diagnostic.cc:519
void color_init(int value)
Definition diagnostic.cc:314
bool m_warning_as_error_requested
Definition diagnostic.h:910
const diagnostic_client_data_hooks * get_client_data_hooks() const
Definition diagnostic.h:725
void set_show_option_requested(bool val)
Definition diagnostic.h:691
void set_original_argv(unique_argv original_argv)
Definition diagnostic.cc:544
void urls_init(int value)
Definition diagnostic.cc:345
friend class diagnostic_buffer
Definition diagnostic.h:563
bool bool bool report_diagnostic(diagnostic_info *)
Definition diagnostic.cc:1419
int m_n_opts
Definition diagnostic.h:914
bool diagnostic_impl(rich_location *, const diagnostic_metadata *, diagnostic_option_id, const char *, va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5
Definition diagnostic.cc:1690
void report_global_digraph(const diagnostics::digraphs::lazy_digraph &)
Definition diagnostic.cc:1629
bool option_unspecified_p(diagnostic_option_id option_id) const
Definition diagnostic.h:604
void set_permissive_option(diagnostic_option_id opt_permissive)
Definition diagnostic.h:851
diagnostic_t classify_diagnostic(diagnostic_option_id option_id, diagnostic_t new_kind, location_t where)
Definition diagnostic.h:631
file_cache & get_file_cache() const
Definition diagnostic.h:715
bool option_enabled_p(diagnostic_option_id option_id) const
Definition diagnostic.h:747
void pop_diagnostics(location_t where)
Definition diagnostic.h:645
bool m_pedantic_errors
Definition diagnostic.h:944
text_art::theme * get_diagram_theme() const
Definition diagnostic.h:735
int m_column_origin
Definition diagnostic.h:1041
bool m_fatal_errors
Definition diagnostic.h:955
bool m_permissive
Definition diagnostic.h:947
void maybe_show_locus(const rich_location &richloc, const diagnostic_source_printing_options &opts, diagnostic_t diagnostic_kind, pretty_printer &pp, diagnostic_source_effect_info *effect_info)
Definition diagnostic-show-locus.cc:3844
diagnostic_start_span_fn< to_html > m_html_start_span
Definition diagnostic.h:983
void(* m_adjust_diagnostic_info)(diagnostic_context *, diagnostic_info *)
Definition diagnostic.h:994
unsigned m_lang_mask
Definition diagnostic.h:999
void create_edit_context()
Definition diagnostic.cc:662
diagnostic_buffer * get_diagnostic_buffer() const
Definition diagnostic.h:810
enum diagnostics_column_unit m_column_unit
Definition diagnostic.h:1038
void emit_diagram(const diagnostic_diagram &diagram)
Definition diagnostic.cc:1747
int m_lock
Definition diagnostic.h:1020
friend diagnostic_start_span_fn< to_text > & diagnostic_start_span(diagnostic_context *context)
Definition diagnostic.h:1133
void set_report_bug(bool val)
Definition diagnostic.h:678
bool m_show_rules
Definition diagnostic.h:924
void set_show_cwe(bool val)
Definition diagnostic.h:683
void clear_diagnostic_buffer(diagnostic_buffer &)
Definition diagnostic.cc:1982
bool bool int get_diagnostic_nesting_level() const
Definition diagnostic.h:789
int m_max_errors
Definition diagnostic.h:966
bool m_abort_on_error
Definition diagnostic.h:937
edit_context * m_edit_context_ptr
Definition diagnostic.h:1055
diagnostic_source_printing_options m_source_printing
Definition diagnostic.h:1025
void set_abort_on_error(bool val)
Definition diagnostic.h:836
bool warning_as_error_requested_p() const
Definition diagnostic.h:702
void set_extra_output_kind(enum diagnostics_extra_output_kind kind)
Definition diagnostic.h:679
int m_group_nesting_depth
Definition diagnostic.h:1060
void set_show_highlight_colors(bool val)
Definition diagnostic.cc:644
diagnostic_buffer * m_diagnostic_buffer
Definition diagnostic.h:1118
void initialize_input_context(diagnostic_input_charset_callback ccb, bool should_skip_bom)
Definition diagnostic.cc:377
Definition diagnostic-diagram.h:33
Definition diagnostic.h:395
diagnostic_location_print_policy(const diagnostic_context &dc)
Definition diagnostic.cc:790
void print_html_span_start(const diagnostic_context &dc, xml::printer &xp, const expanded_location &exploc)
Definition diagnostic-show-locus.cc:702
bool m_show_column
Definition diagnostic.h:417
bool show_column_p() const
Definition diagnostic.h:400
void print_text_span_start(const diagnostic_context &dc, pretty_printer &pp, const expanded_location &exploc)
Definition diagnostic-show-locus.cc:691
const diagnostic_column_policy & get_column_policy() const
Definition diagnostic.h:403
diagnostic_column_policy m_column_policy
Definition diagnostic.h:416
Definition diagnostic-metadata.h:42
Definition diagnostic.h:242
void push()
Definition diagnostic.cc:196
diagnostic_t update_effective_level_from_pragmas(diagnostic_info *diagnostic) const
Definition diagnostic.cc:1255
vec< int > m_push_list
Definition diagnostic.h:314
void fini()
Definition diagnostic.cc:141
int m_n_opts
Definition diagnostic.h:293
vec< diagnostic_classification_change_t > m_classification_history
Definition diagnostic.h:308
void pop(location_t where)
Definition diagnostic.cc:205
diagnostic_t classify_diagnostic(const diagnostic_context *context, diagnostic_option_id option_id, diagnostic_t new_kind, location_t where)
Definition diagnostic.cc:1090
diagnostic_t * m_classify_diagnostic
Definition diagnostic.h:301
int pch_restore(FILE *)
Definition diagnostic.cc:173
diagnostic_t get_current_override(diagnostic_option_id option_id) const
Definition diagnostic.h:259
void init(int n_opts)
Definition diagnostic.cc:130
int pch_save(FILE *)
Definition diagnostic.cc:153
bool option_unspecified_p(diagnostic_option_id option_id) const
Definition diagnostic.h:254
friend class diagnostic_context
Definition diagnostic.h:311
Definition diagnostic.h:203
virtual ~diagnostic_option_manager()
Definition diagnostic.h:205
virtual int option_enabled_p(diagnostic_option_id option_id) const =0
virtual char * make_option_name(diagnostic_option_id option_id, diagnostic_t orig_diag_kind, diagnostic_t diag_kind) const =0
virtual char * make_option_url(diagnostic_option_id option_id) const =0
Definition diagnostic-format.h:33
Definition diagnostic-label-effects.h:41
Definition diagnostic.h:436
diagnostic_start_span_fn< to_text > m_text_start_span_cb
Definition diagnostic.h:489
void print_as_html(xml::printer &xp, const rich_location &richloc, diagnostic_t diagnostic_kind, diagnostic_source_effect_info *effect_info, html_label_writer *label_writer) const
Definition diagnostic-show-locus.cc:3957
text_art::theme * m_diagram_theme
Definition diagnostic.h:494
void print(pretty_printer &pp, const rich_location &richloc, diagnostic_t diagnostic_kind, diagnostic_source_effect_info *effect_info) const
Definition diagnostic-show-locus.cc:3939
file_cache & m_file_cache
Definition diagnostic.h:491
diagnostic_start_span_fn< to_html > m_html_start_span_cb
Definition diagnostic.h:490
file_cache & get_file_cache() const
Definition diagnostic.h:465
text_art::theme * get_diagram_theme() const
Definition diagnostic.h:474
diagnostic_source_print_policy(const diagnostic_context &)
Definition diagnostic-show-locus.cc:3909
diagnostic_start_span_fn< to_text > get_text_start_span_fn() const
Definition diagnostic.h:459
enum diagnostics_escape_format m_escape_format
Definition diagnostic.h:495
class diagnostic_location_print_policy m_location_policy
Definition diagnostic.h:488
const diagnostic_source_printing_options & get_options() const
Definition diagnostic.h:456
const diagnostic_source_printing_options & m_options
Definition diagnostic.h:487
const diagnostic_location_print_policy & get_location_policy() const
Definition diagnostic.h:481
diagnostic_start_span_fn< to_html > get_html_start_span_fn() const
Definition diagnostic.h:462
enum diagnostics_escape_format get_escape_format() const
Definition diagnostic.h:468
const diagnostic_column_policy & get_column_policy() const
Definition diagnostic.h:476
Definition diagnostic-format-text.h:33
Definition diagnostic-digraphs.h:383
Definition edit-context.h:44
Definition input.h:136
Definition diagnostic.h:424
virtual void begin_label()=0
virtual void end_label()=0
virtual ~html_label_writer()
Definition diagnostic.h:426
Definition logical-location.h:91
Definition pretty-print.h:241
Definition libgdiagnostics.cc:219
Definition theme.h:30
Definition pretty-print-urlifier.h:27
Definition xml-printer.h:33
const char *(* diagnostic_input_charset_callback)(const char *)
Definition coretypes.h:171
void ATTRIBUTE_NORETURN
Definition diagnostic-core.h:108
diagnostic_t
Definition diagnostic-core.h:29
@ DK_LAST_DIAGNOSTIC_KIND
Definition diagnostic-core.h:90
#define ATTRIBUTE_GCC_DIAG(m, n)
Definition diagnostic-core.h:103
diagnostic_context * global_dc
Definition diagnostic-global-context.cc:34
int num_digits(int value)
Definition diagnostic.cc:1638
void diagnostic_set_caret_max_width(diagnostic_context *context, int value)
Definition diagnostic.cc:116
void diagnostic_set_info(diagnostic_info *, const char *, va_list *, rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2
char * get_cwe_url(int cwe)
Definition diagnostic.cc:1301
location_t diagnostic_location(const diagnostic_info *diagnostic, int which=0)
Definition diagnostic.h:1323
const int CARET_LINE_MARGIN
Definition diagnostic.h:1349
diagnostics_escape_format
Definition diagnostic.h:63
@ DIAGNOSTICS_ESCAPE_FORMAT_BYTES
Definition diagnostic.h:70
@ DIAGNOSTICS_ESCAPE_FORMAT_UNICODE
Definition diagnostic.h:66
diagnostic_text_art_charset
Definition diagnostic.h:123
@ DIAGNOSTICS_TEXT_ART_CHARSET_ASCII
Definition diagnostic.h:128
@ DIAGNOSTICS_TEXT_ART_CHARSET_NONE
Definition diagnostic.h:125
@ DIAGNOSTICS_TEXT_ART_CHARSET_UNICODE
Definition diagnostic.h:132
@ DIAGNOSTICS_TEXT_ART_CHARSET_EMOJI
Definition diagnostic.h:135
const char * maybe_line_and_column(int line, int col)
Definition diagnostic-format-text.cc:622
diagnostic_t diagnostic_classify_diagnostic(diagnostic_context *context, diagnostic_option_id option_id, diagnostic_t kind, location_t where)
Definition diagnostic.h:1260
void(* diagnostic_text_finalizer_fn)(diagnostic_text_output_format &, const diagnostic_info *, diagnostic_t)
Definition diagnostic.h:195
diagnostic_path_format
Definition diagnostic.h:89
@ DPF_NONE
Definition diagnostic.h:91
@ DPF_SEPARATE_EVENTS
Definition diagnostic.h:95
@ DPF_INLINE_EVENTS
Definition diagnostic.h:101
void diagnostic_initialize_input_context(diagnostic_context *context, diagnostic_input_charset_callback ccb, bool should_skip_bom)
Definition diagnostic.h:1251
diagnostic_text_starter_fn & diagnostic_text_starter(diagnostic_context *context)
Definition diagnostic.h:1124
diagnostics_extra_output_kind
Definition diagnostic.h:108
@ EXTRA_DIAGNOSTIC_OUTPUT_none
Definition diagnostic.h:110
@ EXTRA_DIAGNOSTIC_OUTPUT_fixits_v2
Definition diagnostic.h:117
@ EXTRA_DIAGNOSTIC_OUTPUT_fixits_v1
Definition diagnostic.h:114
diagnostics_output_format
Definition diagnostic.h:76
@ DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE
Definition diagnostic.h:84
@ DIAGNOSTICS_OUTPUT_FORMAT_TEXT
Definition diagnostic.h:78
@ DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR
Definition diagnostic.h:81
void diagnostic_urls_init(diagnostic_context *context, int value=-1)
Definition diagnostic.h:1195
diagnostic_text_finalizer_fn & diagnostic_text_finalizer(diagnostic_context *context)
Definition diagnostic.h:1141
int get_terminal_width(void)
Definition diagnostic.cc:95
const char * diagnostic_get_color_for_kind(diagnostic_t kind)
Definition diagnostic.cc:709
void default_diagnostic_text_finalizer(diagnostic_text_output_format &, const diagnostic_info *, diagnostic_t)
Definition diagnostic-format-text.cc:716
void default_diagnostic_start_span_fn(const diagnostic_location_print_policy &, Sink &sink, expanded_location)
pretty_printer * get_printer(to_text &)
Definition diagnostic-show-locus.cc:712
diagnostics_column_unit
Definition diagnostic.h:51
@ DIAGNOSTICS_COLUMN_UNIT_BYTE
Definition diagnostic.h:56
@ DIAGNOSTICS_COLUMN_UNIT_DISPLAY
Definition diagnostic.h:53
expanded_location diagnostic_expand_location(const diagnostic_info *diagnostic, int which=0)
Definition diagnostic.h:1341
const char * get_diagnostic_kind_text(diagnostic_t kind)
Definition diagnostic.cc:814
void(* diagnostic_text_starter_fn)(diagnostic_text_output_format &, const diagnostic_info *)
Definition diagnostic.h:182
bool option_unspecified_p(diagnostic_option_id option_id)
Definition diagnostic.h:1380
char * build_message_string(const char *,...) ATTRIBUTE_PRINTF_1
Definition diagnostic.cc:78
void diagnostic_finish(diagnostic_context *context)
Definition diagnostic.h:1201
bool warning_enabled_at(location_t loc, diagnostic_option_id option_id)
Definition diagnostic.h:1374
unsigned int diagnostic_num_locations(const diagnostic_info *diagnostic)
Definition diagnostic.h:1331
void diagnostic_show_locus_as_html(diagnostic_context *context, const diagnostic_source_printing_options &opts, rich_location *richloc, diagnostic_t diagnostic_kind, xml::printer &xp, diagnostic_source_effect_info *effect_info=nullptr, html_label_writer *label_writer=nullptr)
Definition diagnostic.h:1221
void diagnostic_initialize(diagnostic_context *context, int n_opts)
Definition diagnostic.h:1183
void diagnostic_set_option_id(diagnostic_info *info, diagnostic_option_id option_id)
Definition diagnostic.h:1174
void diagnostic_color_init(diagnostic_context *context, int value=-1)
Definition diagnostic.h:1189
void diagnostic_show_locus(diagnostic_context *context, const diagnostic_source_printing_options &opts, rich_location *richloc, diagnostic_t diagnostic_kind, pretty_printer *pp, diagnostic_source_effect_info *effect_info=nullptr)
Definition diagnostic.h:1207
diagnostic_start_span_fn< to_text > & diagnostic_start_span(diagnostic_context *context)
Definition diagnostic.h:1133
void void diagnostic_set_info_translated(diagnostic_info *, const char *, va_list *, rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2
void diagnostic_pop_diagnostics(diagnostic_context *context, location_t where)
Definition diagnostic.h:1275
void diagnostic_push_diagnostics(diagnostic_context *context, location_t where)
Definition diagnostic.h:1269
bool diagnostic_same_line(const diagnostic_context *context, expanded_location s1, expanded_location s2)
Definition diagnostic.h:1356
bool diagnostic_report_diagnostic(diagnostic_context *context, diagnostic_info *diagnostic)
Definition diagnostic.h:1289
void(*)(const diagnostic_location_print_policy &, Sink &sink, expanded_location) diagnostic_start_span_fn
Definition diagnostic.h:191
void void void default_diagnostic_text_starter(diagnostic_text_output_format &, const diagnostic_info *)
Definition diagnostic-format-text.cc:707
@ value
Definition logical-location.h:59
Definition diagnostic-digraphs.h:36
Definition diagnostic-digraphs.h:35
Definition diagnostic-diagram.h:25
Definition diagnostic-path.h:28
bool(* printer_fn)(pretty_printer *, text_info *, const char *, int, bool, bool, bool, bool *, pp_token_list &)
Definition pretty-print.h:190
diagnostic_prefixing_rule_t
Definition pretty-print.h:66
static void const char va_list ap
Definition read-md.cc:205
Definition diagnostic.h:1006
bool m_owned
Definition diagnostic.h:1008
urlifier * m_urlifier
Definition diagnostic.h:1007
Definition diagnostic.h:503
void clear()
Definition diagnostic.cc:2046
diagnostic_counters()
Definition diagnostic.cc:2014
void move_to(diagnostic_counters &dest)
Definition diagnostic.cc:2038
int get_count(diagnostic_t kind) const
Definition diagnostic.h:509
int m_count_for_kind[DK_LAST_DIAGNOSTIC_KIND]
Definition diagnostic.h:514
void DEBUG_FUNCTION dump() const
Definition diagnostic.h:507
Definition diagnostic.h:168
void * m_ao
Definition diagnostic.h:172
auto_vec< location_t, 8 > m_ilocs
Definition diagnostic.h:170
bool m_allsyslocs
Definition diagnostic.h:174
Definition diagnostic.h:142
const diagnostic_metadata * metadata
Definition diagnostic.h:156
diagnostic_info()
Definition diagnostic.h:143
void * x_data
Definition diagnostic.h:159
diagnostic_t kind
Definition diagnostic.h:161
struct diagnostic_info::inlining_info m_iinfo
text_info message
Definition diagnostic.h:149
rich_location * richloc
Definition diagnostic.h:152
diagnostic_option_id option_id
Definition diagnostic.h:163
Definition diagnostic-core.h:72
int m_idx
Definition diagnostic-core.h:84
Definition diagnostic.h:321
bool enabled
Definition diagnostic.h:325
bool show_line_numbers_p
Definition diagnostic.h:349
bool show_event_links_p
Definition diagnostic.h:363
int max_width
Definition diagnostic.h:328
char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES]
Definition diagnostic.h:331
bool show_ruler_p
Definition diagnostic.h:358
bool show_labels_p
Definition diagnostic.h:344
bool colorize_source_p
Definition diagnostic.h:340
int min_margin_width
Definition diagnostic.h:354
Definition libgdiagnostics.cc:1201
Definition pretty-print.h:34
Definition diagnostic-show-locus.cc:544
Definition diagnostic-show-locus.cc:408
Definition unique-argv.h:28
Definition vec.h:450
#define gcc_assert(EXPR)
Definition system.h:814
#define DEBUG_FUNCTION
Definition system.h:1236