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