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 /* JSON-based output, to stderr. */
76
77 /* JSON-based output, to a file. */
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 pragma push/pop. */
312};
313
314/* A bundle of options relating to printing the user's source code
315 (potentially with a margin, underlining, labels, etc). */
316
318{
319 /* True if we should print the source line with a caret indicating
320 the location.
321 Corresponds to -fdiagnostics-show-caret. */
323
324 /* Maximum width of the source line printed. */
326
327 /* Character used at the caret when printing source locations. */
328 char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES];
329
330 /* When printing source code, should the characters at carets and ranges
331 be colorized? (assuming colorization is on at all).
332 This should be true for frontends that generate range information
333 (so that the ranges of code are colorized),
334 and false for frontends that merely specify points within the
335 source code (to avoid e.g. colorizing just the first character in
336 a token, which would look strange). */
338
339 /* When printing source code, should labelled ranges be printed?
340 Corresponds to -fdiagnostics-show-labels. */
342
343 /* When printing source code, should there be a left-hand margin
344 showing line numbers?
345 Corresponds to -fdiagnostics-show-line-numbers. */
347
348 /* If printing source code, what should the minimum width of the margin
349 be? Line numbers will be right-aligned, and padded to this width.
350 Corresponds to -fdiagnostics-minimum-margin-width=VALUE. */
352
353 /* Usable by plugins; if true, print a debugging ruler above the
354 source output. */
356
357 /* When printing events in an inline path, should we print lines
358 visualizing links between related events (e.g. for CFG paths)?
359 Corresponds to -fdiagnostics-show-event-links. */
361};
362
363/* A bundle of state for determining column numbers in diagnostics
364 (tab stops, whether to start at 0 or 1, etc).
365 Uses a file_cache to handle tabs. */
366
368{
369public:
371
372 int converted_column (expanded_location s) const;
373
374 label_text get_location_text (const expanded_location &s,
375 bool show_column,
376 bool colorize) const;
377
378 int get_tabstop () const { return m_tabstop; }
379
380private:
385};
386
387/* A bundle of state for printing locations within diagnostics
388 (e.g. "FILENAME:LINE:COLUMN"), to isolate the interactions between
389 diagnostic_context and the start_span callbacks. */
390
392{
393public:
396
397 bool show_column_p () const { return m_show_column; }
398
401
402 void
404 pretty_printer &pp,
405 const expanded_location &exploc);
406
407 void
409 xml::printer &xp,
410 const expanded_location &exploc);
411
412private:
415};
416
417/* Abstract base class for optionally supplying extra tags when writing
418 out annotation labels in HTML output. */
419
421{
422public:
423 virtual ~html_label_writer () {}
424 virtual void begin_label () = 0;
425 virtual void end_label () = 0;
426};
427
428/* A bundle of state for printing source within a diagnostic,
429 to isolate the interactions between diagnostic_context and the
430 implementation of diagnostic_show_locus. */
431
433{
434public:
438
439 void
441 const rich_location &richloc,
442 diagnostic_t diagnostic_kind,
443 diagnostic_source_effect_info *effect_info) const;
444
445 void
447 const rich_location &richloc,
448 diagnostic_t diagnostic_kind,
450 html_label_writer *label_writer) const;
451
453 get_options () const { return m_options; }
454
457
460
461 file_cache &
462 get_file_cache () const { return m_file_cache; }
463
466 {
467 return m_escape_format;
468 }
469
470 text_art::theme *
472
474 {
475 return m_location_policy.get_column_policy ();
476 }
477
482
483private:
489
490 /* Other data copied from diagnostic_context. */
491 text_art::theme *m_diagram_theme;
493};
494
495/* A collection of counters of diagnostics, per-kind
496 (e.g. "3 errors and 1 warning"), for use by both diagnostic_context
497 and by diagnostic_buffer. */
498
500{
502
503 void dump (FILE *out, int indent) const;
504 void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
505
506 int get_count (diagnostic_t kind) const { return m_count_for_kind[kind]; }
507
508 void move_to (diagnostic_counters &dest);
509 void clear ();
510
512};
513
514/* This class encapsulates the state of the diagnostics subsystem
515 as a whole (either directly, or via owned objects of other classes, to
516 avoid global variables).
517
518 It has responsibility for:
519 - being a central place for clients to report diagnostics
520 - reporting those diagnostics to zero or more output sinks
521 (e.g. text vs SARIF)
522 - providing a "dump" member function for a debug dump of the state of
523 the diagnostics subsytem
524 - direct vs buffered diagnostics (see class diagnostic_buffer)
525 - tracking the original argv of the program (for SARIF output)
526 - crash-handling
527
528 It delegates responsibility to various other classes:
529 - the various output sinks (instances of diagnostic_output_format
530 subclasses)
531 - formatting of messages (class pretty_printer)
532 - an optional urlifier to inject URLs into formatted messages
533 - counting the number of diagnostics reported of each kind
534 (class diagnostic_counters)
535 - calling out to a diagnostic_option_manager to determine if
536 a particular warning is enabled or disabled
537 - tracking pragmas that enable/disable warnings in a range of
538 source code
539 - a cache for use when quoting the user's source code (class file_cache)
540 - a text_art::theme
541 - an edit_context for generating patches from fix-it hints
542 - diagnostic_client_data_hooks for metadata.
543
544 Try to avoid adding new responsibilities to this class itself, to avoid
545 the "blob" anti-pattern. */
546
548{
549public:
550 /* Give access to m_text_callbacks. */
557
560 friend class diagnostic_buffer;
561
564
565 void initialize (int n_opts);
566 void color_init (int value);
567 void urls_init (int value);
568 void set_pretty_printer (std::unique_ptr<pretty_printer> pp);
569 void refresh_output_sinks ();
570
571 void finish ();
572
573 void dump (FILE *out) const;
574 void DEBUG_FUNCTION dump () const { dump (stderr); }
575
576 bool execution_failed_p () const;
577
578 void set_original_argv (unique_argv original_argv);
579 const char * const *get_original_argv ()
580 {
581 return const_cast<const char * const *> (m_original_argv);
582 }
583
588
589 void
591 bool should_skip_bom);
592
593 void begin_group ();
594 void end_group ();
595
596 void push_nesting_level ();
597 void pop_nesting_level ();
598
599 bool warning_enabled_at (location_t loc, diagnostic_option_id option_id);
600
602 {
603 return m_option_classifier.option_unspecified_p (option_id);
604 }
605
607 rich_location &richloc,
608 const diagnostic_metadata *metadata,
609 diagnostic_option_id option_id,
610 const char *gmsgid, ...)
613 rich_location &richloc,
614 const diagnostic_metadata *metadata,
615 diagnostic_option_id option_id,
616 const char *gmsgid, va_list *ap)
618
620 void report_verbatim (text_info &);
621
624 diagnostic_t new_kind,
625 location_t where)
626 {
627 return m_option_classifier.classify_diagnostic (this,
628 option_id,
629 new_kind,
630 where);
631 }
632
633 void push_diagnostics (location_t where ATTRIBUTE_UNUSED)
634 {
635 m_option_classifier.push ();
636 }
637 void pop_diagnostics (location_t where)
638 {
639 m_option_classifier.pop (where);
640 }
641
642 void maybe_show_locus (const rich_location &richloc,
644 diagnostic_t diagnostic_kind,
645 pretty_printer &pp,
646 diagnostic_source_effect_info *effect_info);
647 void maybe_show_locus_as_html (const rich_location &richloc,
649 diagnostic_t diagnostic_kind,
650 xml::printer &xp,
652 html_label_writer *label_writer);
653
654 void emit_diagram (const diagnostic_diagram &diagram);
655
656 /* Various setters for use by option-handling logic. */
657 void set_output_format (std::unique_ptr<diagnostic_output_format> output_format);
659 void set_client_data_hooks (std::unique_ptr<diagnostic_client_data_hooks> hooks);
660
661 void push_owned_urlifier (std::unique_ptr<urlifier>);
662 void push_borrowed_urlifier (const urlifier &);
663 void pop_urlifier ();
664
665 void create_edit_context ();
667 {
669 }
670 void set_report_bug (bool val) { m_report_bug = val; }
675 void set_show_cwe (bool val) { m_show_cwe = val; }
676 void set_show_rules (bool val) { m_show_rules = val; }
677 void set_show_highlight_colors (bool val);
679 {
680 m_path_format = val;
681 }
682 void set_show_path_depths (bool val) { m_show_path_depths = val; }
684 void set_max_errors (int val) { m_max_errors = val; }
686 {
687 m_escape_format = val;
688 }
689
690 void set_format_decoder (printer_fn format_decoder);
692
693 /* Various accessors. */
695 {
697 }
698 bool show_path_depths_p () const { return m_show_path_depths; }
702 {
703 return m_escape_format;
704 }
705
706 file_cache &
708 {
710 return *m_file_cache;
711 }
712
714 {
715 return m_edit_context_ptr;
716 }
721
724
725 const urlifier *get_urlifier () const;
726
727 text_art::theme *get_diagram_theme () const { return m_diagrams.m_theme; }
728
730 {
731 return m_diagnostic_counters.m_count_for_kind[kind];
732 }
734 {
735 return m_diagnostic_counters.get_count (kind);
736 }
737
738 /* Option-related member functions. */
739 inline bool option_enabled_p (diagnostic_option_id option_id) const
740 {
741 if (!m_option_mgr)
742 return true;
743 return m_option_mgr->option_enabled_p (option_id);
744 }
745
746 inline char *make_option_name (diagnostic_option_id option_id,
747 diagnostic_t orig_diag_kind,
748 diagnostic_t diag_kind) const
749 {
750 if (!m_option_mgr)
751 return nullptr;
752 return m_option_mgr->make_option_name (option_id,
753 orig_diag_kind,
754 diag_kind);
755 }
756
757 inline char *make_option_url (diagnostic_option_id option_id) const
758 {
759 if (!m_option_mgr)
760 return nullptr;
761 return m_option_mgr->make_option_url (option_id);
762 }
763
764 void
765 set_option_manager (std::unique_ptr<diagnostic_option_manager> mgr,
766 unsigned lang_mask);
767
768 unsigned get_lang_mask () const
769 {
770 return m_lang_mask;
771 }
772
773 bool diagnostic_impl (rich_location *, const diagnostic_metadata *,
774 diagnostic_option_id, const char *,
775 va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5,0);
776 bool diagnostic_n_impl (rich_location *, const diagnostic_metadata *,
777 diagnostic_option_id, unsigned HOST_WIDE_INT,
778 const char *, const char *, va_list *,
780
782 {
783 return m_diagnostic_groups.m_diagnostic_nesting_level;
784 }
785
786 char *build_indent_prefix () const;
787
788 int
789 pch_save (FILE *f)
790 {
791 return m_option_classifier.pch_save (f);
792 }
793
794 int
795 pch_restore (FILE *f)
796 {
797 return m_option_classifier.pch_restore (f);
798 }
799
800
808
809 std::unique_ptr<pretty_printer> clone_printer () const
810 {
811 return m_reference_printer->clone ();
812 }
813
818
819 void
820 add_sink (std::unique_ptr<diagnostic_output_format>);
821
823
824 bool supports_fnotice_on_stderr_p () const;
825
826 /* Raise SIGABRT on any diagnostic of severity DK_ERROR or higher. */
827 void
829 {
830 m_abort_on_error = val;
831 }
832
833private:
835
837
839
840 void check_max_errors (bool flush);
841 void action_after_output (diagnostic_t diag_kind);
842
843 /* Data members.
844 Ideally, all of these would be private. */
845
846private:
847 /* A reference instance of pretty_printer created by the client
848 and owned by the context. Used for cloning when creating/adding
849 output formats.
850 Owned by the context; this would be a std::unique_ptr if
851 diagnostic_context had a proper ctor. */
853
854 /* Cache of source code.
855 Owned by the context; this would be a std::unique_ptr if
856 diagnostic_context had a proper ctor. */
858
859 /* The number of times we have issued diagnostics. */
861
862 /* True if it has been requested that warnings be treated as errors. */
864
865 /* The number of option indexes that can be passed to warning() et
866 al. */
868
869 /* The stack of sets of overridden diagnostic option severities. */
871
872 /* True if we should print any CWE identifiers associated with
873 diagnostics. */
875
876 /* True if we should print any rules associated with diagnostics. */
878
879 /* How should diagnostic_path objects be printed. */
881
882 /* True if we should print stack depths when printing diagnostic paths. */
884
885 /* True if we should print the command line option which controls
886 each diagnostic, if known. */
888
889 /* True if we should raise a SIGABRT on errors. */
891
892public:
893 /* True if we should show the column number on diagnostics. */
895
896 /* True if pedwarns are errors. */
898
899 /* True if permerrors are warnings. */
901
902 /* The option to associate with turning permerrors into warnings,
903 if any. */
905
906 /* True if errors are fatal. */
908
909 /* True if all warnings should be disabled. */
911
912 /* True if warnings should be given in system headers. */
914
915private:
916 /* Maximum number of errors to report. */
918
919 /* Client-supplied callbacks for use in text output. */
920 struct {
921 /* This function is called before any message is printed out. It is
922 responsible for preparing message prefix and such. For example, it
923 might say:
924 In file included from "/usr/local/include/curses.h:5:
925 from "/home/gdr/src/nifty_printer.h:56:
926 ...
927 */
929
930 /* This function is called by diagnostic_show_locus in between
931 disjoint spans of source code, so that the context can print
932 something to indicate that a new span of source code has begun. */
935
936 /* This function is called after the diagnostic message is printed. */
939
940public:
941 /* Client hook to report an internal error. */
942 void (*m_internal_error) (diagnostic_context *, const char *, va_list *);
943
944 /* Client hook to adjust properties of the given diagnostic that we're
945 about to issue, such as its kind. */
947
948private:
949 /* Owned by the context; this would be a std::unique_ptr if
950 diagnostic_context had a proper ctor. */
952 unsigned m_lang_mask;
953
954 /* A stack of optional hooks for adding URLs to quoted text strings in
955 diagnostics. Only used for the main diagnostic message.
956 Typically a single one owner by the context, but can be temporarily
957 overridden by a borrowed urlifier (e.g. on-stack). */
964
965public:
966 /* Auxiliary data for client. */
968
969 /* Used to detect that the last caret was printed at the same location. */
970 location_t m_last_location;
971
972private:
974
975public:
977
979
980private:
981 /* True if -freport-bug option is used. */
983
984 /* Used to specify additional diagnostic output to be emitted after the
985 rest of the diagnostic. This is for implementing
986 -fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT. */
988
989public:
990 /* What units to use when outputting the column number. */
992
993 /* The origin for the column number (1-based or 0-based typically). */
995
996 /* The size of the tabstop for tab expansion. */
998
999private:
1000 /* How should non-ASCII/non-printable bytes be escaped when
1001 a diagnostic suggests escaping the source code on output. */
1003
1004 /* If non-NULL, an edit_context to which fix-it hints should be
1005 applied, for generating patches.
1006 Owned by the context; this would be a std::unique_ptr if
1007 diagnostic_context had a proper ctor. */
1009
1010 /* Fields relating to diagnostic groups. */
1011 struct {
1012 /* How many diagnostic_group instances are currently alive. */
1014
1015 /* How many nesting levels have been pushed within this group. */
1017
1018 /* How many diagnostics have been emitted since the bottommost
1019 diagnostic_group was pushed. */
1021
1022 /* The "group+diagnostic" nesting depth from which to inhibit notes. */
1025
1026 void inhibit_notes_in_group (bool inhibit = true);
1027 bool notes_inhibited_in_group () const;
1028
1029 /* The various sinks to which diagnostics are to be outputted
1030 (text vs structured formats such as SARIF).
1031 The sinks are owned by the context; this would be a
1032 std::vector<std::unique_ptr> if diagnostic_context had a
1033 proper ctor. */
1035
1036 /* Callback to set the locations of call sites along the inlining
1037 stack corresponding to a diagnostic location. Needed to traverse
1038 the BLOCK_SUPERCONTEXT() chain hanging off the LOCATION_BLOCK()
1039 of a diagnostic's location. */
1041
1042 /* A bundle of hooks for providing data to the context about its client
1043 e.g. version information, plugins, etc.
1044 Used by SARIF output to give metadata about the client that's
1045 producing diagnostics.
1046 Owned by the context; this would be a std::unique_ptr if
1047 diagnostic_context had a proper ctor. */
1049
1050 /* Support for diagrams. */
1051 struct
1052 {
1053 /* Theme to use when generating diagrams.
1054 Can be NULL (if text art is disabled).
1055 Owned by the context; this would be a std::unique_ptr if
1056 diagnostic_context had a proper ctor. */
1057 text_art::theme *m_theme;
1058
1060
1061 /* Owned by the context. */
1063
1064 /* Borrowed pointer to the active diagnostic_buffer, if any.
1065 If null (the default), then diagnostics that are reported to the
1066 context are immediately issued to the output format.
1067 If non-null, then diagnostics that are reported to the context
1068 are buffered in the buffer, and may be issued to the output format
1069 later (if the buffer is flushed), moved to other buffers, or
1070 discarded (if the buffer is cleared). */
1072};
1073
1074inline void
1076{
1077 context->m_inhibit_notes_p = true;
1078}
1079
1080
1081/* Client supplied function to announce a diagnostic
1082 (for text-based diagnostic output). */
1088
1089/* Client supplied function called between disjoint spans of source code,
1090 so that the context can print
1091 something to indicate that a new span of source code has begun. */
1097
1098/* Client supplied function called after a diagnostic message is
1099 displayed (for text-based diagnostic output). */
1105
1106/* Extension hooks for client. */
1107#define diagnostic_context_auxiliary_data(DC) (DC)->m_client_aux_data
1108#define diagnostic_info_auxiliary_data(DI) (DI)->x_data
1109
1110/* This diagnostic_context is used by front-ends that directly output
1111 diagnostic messages without going through `error', `warning',
1112 and similar functions. */
1114
1115/* The number of errors that have been issued so far. Ideally, these
1116 would take a diagnostic_context as an argument. */
1117#define errorcount global_dc->diagnostic_count (DK_ERROR)
1118/* Similarly, but for warnings. */
1119#define warningcount global_dc->diagnostic_count (DK_WARNING)
1120/* Similarly, but for warnings promoted to errors. */
1121#define werrorcount global_dc->diagnostic_count (DK_WERROR)
1122/* Similarly, but for sorrys. */
1123#define sorrycount global_dc->diagnostic_count (DK_SORRY)
1124
1125/* Returns nonzero if warnings should be emitted. */
1126#define diagnostic_report_warnings_p(DC, LOC) \
1127 (!(DC)->m_inhibit_warnings \
1128 && !(in_system_header_at (LOC) && !(DC)->m_warn_system_headers))
1129
1130/* Override the option index to be used for reporting a
1131 diagnostic. */
1132
1133inline void
1135 diagnostic_option_id option_id)
1136{
1137 info->option_id = option_id;
1138}
1139
1140/* Diagnostic related functions. */
1141
1142inline void
1144{
1145 context->initialize (n_opts);
1146}
1147
1148inline void
1150{
1151 context->color_init (value);
1152}
1153
1154inline void
1156{
1157 context->urls_init (value);
1158}
1159
1160inline void
1162{
1163 context->finish ();
1164}
1165
1166inline void
1169 rich_location *richloc,
1170 diagnostic_t diagnostic_kind,
1171 pretty_printer *pp,
1172 diagnostic_source_effect_info *effect_info = nullptr)
1173{
1174 gcc_assert (context);
1175 gcc_assert (richloc);
1176 gcc_assert (pp);
1177 context->maybe_show_locus (*richloc, opts, diagnostic_kind, *pp, effect_info);
1178}
1179
1180inline void
1183 rich_location *richloc,
1184 diagnostic_t diagnostic_kind,
1185 xml::printer &xp,
1186 diagnostic_source_effect_info *effect_info = nullptr,
1187 html_label_writer *label_writer = nullptr)
1188{
1189 gcc_assert (context);
1190 gcc_assert (richloc);
1191 context->maybe_show_locus_as_html (*richloc, opts, diagnostic_kind, xp,
1192 effect_info, label_writer);
1193}
1194
1195/* Because we read source files a second time after the frontend did it the
1196 first time, we need to know how the frontend handled things like character
1197 set conversion and UTF-8 BOM stripping, in order to make everything
1198 consistent. This function needs to be called by each frontend that requires
1199 non-default behavior, to inform the diagnostics infrastructure how input is
1200 to be processed. The default behavior is to do no conversion and not to
1201 strip a UTF-8 BOM.
1202
1203 The callback should return the input charset to be used to convert the given
1204 file's contents to UTF-8, or it should return NULL if no conversion is needed
1205 for this file. SHOULD_SKIP_BOM only applies in case no conversion was
1206 performed, and if true, it will cause a UTF-8 BOM to be skipped at the
1207 beginning of the file. (In case a conversion was performed, the BOM is
1208 rather skipped as part of the conversion process.) */
1209
1210inline void
1213 bool should_skip_bom)
1214{
1215 context->initialize_input_context (ccb, should_skip_bom);
1216}
1217
1218/* Force diagnostics controlled by OPTIDX to be kind KIND. */
1219inline diagnostic_t
1221 diagnostic_option_id option_id,
1222 diagnostic_t kind,
1223 location_t where)
1224{
1225 return context->classify_diagnostic (option_id, kind, where);
1226}
1227
1228inline void
1230 location_t where)
1231{
1232 context->push_diagnostics (where);
1233}
1234inline void
1236 location_t where)
1237{
1238 context->pop_diagnostics (where);
1239}
1240
1241/* Report a diagnostic message (an error or a warning) as specified by
1242 DC. This function is *the* subroutine in terms of which front-ends
1243 should implement their specific diagnostic handling modules. The
1244 front-end independent format specifiers are exactly those described
1245 in the documentation of output_format.
1246 Return true if a diagnostic was printed, false otherwise. */
1247
1248inline bool
1251{
1252 context->begin_group ();
1253 bool warned = context->report_diagnostic (diagnostic);
1254 context->end_group ();
1255 return warned;
1256}
1257
1258#ifdef ATTRIBUTE_GCC_DIAG
1259extern void diagnostic_set_info (diagnostic_info *, const char *, va_list *,
1260 rich_location *, diagnostic_t) ATTRIBUTE_GCC_DIAG(2,0);
1262 va_list *, rich_location *,
1264 ATTRIBUTE_GCC_DIAG(2,0);
1265#endif
1267 const diagnostic_info *);
1268template <typename Sink>
1270 Sink &sink,
1271 expanded_location);
1273 const diagnostic_info *,
1274 diagnostic_t);
1276
1277int get_terminal_width (void);
1278
1279/* Return the location associated to this diagnostic. Parameter WHICH
1280 specifies which location. By default, expand the first one. */
1281
1282inline location_t
1284{
1285 return diagnostic->message.get_location (which);
1286}
1287
1288/* Return the number of locations to be printed in DIAGNOSTIC. */
1289
1290inline unsigned int
1292{
1293 return diagnostic->message.m_richloc->get_num_locations ();
1294}
1295
1296/* Expand the location of this diagnostic. Use this function for
1297 consistency. Parameter WHICH specifies which location. By default,
1298 expand the first one. */
1299
1300inline expanded_location
1302{
1303 return diagnostic->richloc->get_expanded_location (which);
1304}
1305
1306/* This is somehow the right-side margin of a caret line, that is, we
1307 print at least these many characters after the position pointed at
1308 by the caret. */
1309const int CARET_LINE_MARGIN = 10;
1310
1311/* Return true if the two locations can be represented within the same
1312 caret line. This is used to build a prefix and also to determine
1313 whether to print one or two caret lines. */
1314
1315inline bool
1317 expanded_location s1, expanded_location s2)
1318{
1319 return (s2.column && s1.line == s2.line
1321 > abs (s1.column - s2.column)));
1322}
1323
1324extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
1325
1326/* Pure text formatting support functions. */
1327
1328extern char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
1329
1330/* Compute the number of digits in the decimal representation of an integer. */
1331extern int num_digits (int);
1332
1333inline bool
1334warning_enabled_at (location_t loc, diagnostic_option_id option_id)
1335{
1336 return global_dc->warning_enabled_at (loc, option_id);
1337}
1338
1339inline bool
1341{
1342 return global_dc->option_unspecified_p (option_id);
1343}
1344
1345extern char *get_cwe_url (int cwe);
1346
1347extern const char *get_diagnostic_kind_text (diagnostic_t kind);
1348
1349const char *maybe_line_and_column (int line, int col);
1350
1351#endif /* ! GCC_DIAGNOSTIC_H */
Definition vec.h:1667
Definition diagnostic-buffer.h:57
Definition diagnostic-client-data-hooks.h:33
Definition diagnostic.h:368
label_text get_location_text(const expanded_location &s, bool show_column, bool colorize) const
Definition diagnostic.cc:761
enum diagnostics_column_unit m_column_unit
Definition diagnostic.h:382
int m_column_origin
Definition diagnostic.h:383
diagnostic_column_policy(const diagnostic_context &dc)
Definition diagnostic.cc:737
int converted_column(expanded_location s) const
Definition diagnostic.cc:749
int m_tabstop
Definition diagnostic.h:384
int get_tabstop() const
Definition diagnostic.h:378
file_cache & m_file_cache
Definition diagnostic.h:381
Definition diagnostic.h:548
struct diagnostic_context::@012375117275062000312167204021321243213276373064 m_diagnostic_groups
void action_after_output(diagnostic_t diag_kind)
Definition diagnostic.cc:934
void push_owned_urlifier(std::unique_ptr< urlifier >)
Definition diagnostic.cc:560
friend class diagnostic_source_print_policy
Definition diagnostic.h:558
int diagnostic_count(diagnostic_t kind) const
Definition diagnostic.h:733
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:1389
int m_tabstop
Definition diagnostic.h:997
void initialize(int n_opts)
Definition diagnostic.cc:221
bool notes_inhibited_in_group() const
Definition diagnostic.cc:1041
file_cache * m_file_cache
Definition diagnostic.h:857
bool execution_failed_p() const
Definition diagnostic.cc:478
void set_show_rules(bool val)
Definition diagnostic.h:676
void get_any_inlining_info(diagnostic_info *diagnostic)
Definition diagnostic.cc:1219
enum diagnostic_path_format m_path_format
Definition diagnostic.h:880
void finish()
Definition diagnostic.cc:386
pretty_printer * get_reference_printer() const
Definition diagnostic.h:814
void end_group()
Definition diagnostic.cc:1815
void error_recursion() ATTRIBUTE_NORETURN
Definition diagnostic.cc:1747
int m_diagnostic_nesting_level
Definition diagnostic.h:1016
void set_escape_format(enum diagnostics_escape_format val)
Definition diagnostic.h:685
bool diagnostic_enabled(diagnostic_info *diagnostic)
Definition diagnostic.cc:1303
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:562
bool m_show_option_requested
Definition diagnostic.h:887
void set_set_locations_callback(set_locations_callback_t cb)
Definition diagnostic.h:584
void DEBUG_FUNCTION dump() const
Definition diagnostic.h:574
bool m_report_bug
Definition diagnostic.h:982
void inhibit_notes_in_group(bool inhibit=true)
Definition diagnostic.cc:1011
void remove_all_output_sinks()
Definition diagnostic.cc:488
void refresh_output_sinks()
Definition diagnostic.cc:619
edit_context * get_edit_context() const
Definition diagnostic.h:713
void push_nesting_level()
Definition diagnostic.cc:1832
void set_format_decoder(printer_fn format_decoder)
Definition diagnostic.cc:629
void set_path_format(enum diagnostic_path_format val)
Definition diagnostic.h:678
friend diagnostic_text_starter_fn & diagnostic_text_starter(diagnostic_context *context)
Definition diagnostic.h:1084
void set_diagnostic_buffer(diagnostic_buffer *)
Definition diagnostic.cc:1944
void set_max_errors(int val)
Definition diagnostic.h:684
friend class diagnostic_text_output_format
Definition diagnostic.h:559
int pch_restore(FILE *f)
Definition diagnostic.h:795
void set_option_manager(std::unique_ptr< diagnostic_option_manager > mgr, unsigned lang_mask)
Definition diagnostic.cc:551
enum diagnostics_extra_output_kind m_extra_output_kind
Definition diagnostic.h:987
bool m_inhibit_warnings
Definition diagnostic.h:910
int m_emission_count
Definition diagnostic.h:1020
friend diagnostic_text_finalizer_fn & diagnostic_text_finalizer(diagnostic_context *context)
Definition diagnostic.h:1101
diagnostic_output_format & get_output_format(size_t idx) const
Definition diagnostic.cc:503
bool m_show_column
Definition diagnostic.h:894
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:1701
struct diagnostic_context::@144115345167042231333361231316114173002254305105 m_diagrams
diagnostic_option_classifier m_option_classifier
Definition diagnostic.h:870
diagnostic_option_id m_opt_permissive
Definition diagnostic.h:904
void report_verbatim(text_info &)
Definition diagnostic.cc:1607
bool m_show_path_depths
Definition diagnostic.h:883
int & diagnostic_count(diagnostic_t kind)
Definition diagnostic.h:729
char * make_option_url(diagnostic_option_id option_id) const
Definition diagnostic.h:757
void push_diagnostics(location_t where)
Definition diagnostic.h:633
void begin_group()
Definition diagnostic.cc:1809
enum diagnostics_escape_format m_escape_format
Definition diagnostic.h:1002
set_locations_callback_t m_set_locations_cb
Definition diagnostic.h:1040
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:682
diagnostic_start_span_fn< to_text > m_text_start_span
Definition diagnostic.h:933
char * make_option_name(diagnostic_option_id option_id, diagnostic_t orig_diag_kind, diagnostic_t diag_kind) const
Definition diagnostic.h:746
diagnostic_counters m_diagnostic_counters
Definition diagnostic.h:860
std::unique_ptr< pretty_printer > clone_printer() const
Definition diagnostic.h:809
const char *const * get_original_argv()
Definition diagnostic.h:579
void set_pretty_printer(std::unique_ptr< pretty_printer > pp)
Definition diagnostic.cc:609
bool m_warn_system_headers
Definition diagnostic.h:913
char * build_indent_prefix() const
void flush_diagnostic_buffer(diagnostic_buffer &)
Definition diagnostic.cc:1994
diagnostic_text_starter_fn m_begin_diagnostic
Definition diagnostic.h:928
enum diagnostic_path_format get_path_format() const
Definition diagnostic.h:700
int pch_save(FILE *f)
Definition diagnostic.h:789
pretty_printer * m_reference_printer
Definition diagnostic.h:852
char ** m_original_argv
Definition diagnostic.h:1062
diagnostic_client_data_hooks * m_client_data_hooks
Definition diagnostic.h:1048
void(* m_internal_error)(diagnostic_context *, const char *, va_list *)
Definition diagnostic.h:942
bool warning_enabled_at(location_t loc, diagnostic_option_id option_id)
Definition diagnostic.cc:1347
bool m_show_cwe
Definition diagnostic.h:874
diagnostic_text_finalizer_fn m_end_diagnostic
Definition diagnostic.h:937
void pop_urlifier()
Definition diagnostic.cc:576
void * m_client_aux_data
Definition diagnostic.h:967
void set_client_data_hooks(std::unique_ptr< diagnostic_client_data_hooks > hooks)
Definition diagnostic.cc:529
diagnostic_option_manager * m_option_mgr
Definition diagnostic.h:951
void set_prefixing_rule(diagnostic_prefixing_rule_t rule)
Definition diagnostic.cc:646
void set_warning_as_error_requested(bool val)
Definition diagnostic.h:666
location_t m_last_location
Definition diagnostic.h:970
void check_max_errors(bool flush)
Definition diagnostic.cc:910
unsigned get_lang_mask() const
Definition diagnostic.h:768
void push_borrowed_urlifier(const urlifier &)
Definition diagnostic.cc:568
auto_vec< urlifier_stack_node > * m_urlifier_stack
Definition diagnostic.h:963
void pop_nesting_level()
Definition diagnostic.cc:1838
enum diagnostics_escape_format get_escape_format() const
Definition diagnostic.h:701
int m_inhibiting_notes_from
Definition diagnostic.h:1023
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:1366
const logical_location_manager * get_logical_location_manager() const
Definition diagnostic.cc:587
void set_text_art_charset(enum diagnostic_text_art_charset charset)
Definition diagnostic.cc:1911
auto_vec< diagnostic_output_format * > m_output_sinks
Definition diagnostic.h:1034
const urlifier * get_urlifier() const
Definition diagnostic.cc:595
text_art::theme * m_theme
Definition diagnostic.h:1057
bool m_inhibit_notes_p
Definition diagnostic.h:976
bool show_path_depths_p() const
Definition diagnostic.h:698
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:863
const diagnostic_client_data_hooks * get_client_data_hooks() const
Definition diagnostic.h:717
void set_show_option_requested(bool val)
Definition diagnostic.h:683
void set_original_argv(unique_argv original_argv)
Definition diagnostic.cc:537
void urls_init(int value)
Definition diagnostic.cc:345
friend class diagnostic_buffer
Definition diagnostic.h:560
bool bool bool report_diagnostic(diagnostic_info *)
Definition diagnostic.cc:1412
int m_n_opts
Definition diagnostic.h:867
bool diagnostic_impl(rich_location *, const diagnostic_metadata *, diagnostic_option_id, const char *, va_list *, diagnostic_t) ATTRIBUTE_GCC_DIAG(5
Definition diagnostic.cc:1675
bool option_unspecified_p(diagnostic_option_id option_id) const
Definition diagnostic.h:601
diagnostic_t classify_diagnostic(diagnostic_option_id option_id, diagnostic_t new_kind, location_t where)
Definition diagnostic.h:623
file_cache & get_file_cache() const
Definition diagnostic.h:707
bool option_enabled_p(diagnostic_option_id option_id) const
Definition diagnostic.h:739
void pop_diagnostics(location_t where)
Definition diagnostic.h:637
bool m_pedantic_errors
Definition diagnostic.h:897
text_art::theme * get_diagram_theme() const
Definition diagnostic.h:727
int m_column_origin
Definition diagnostic.h:994
bool m_fatal_errors
Definition diagnostic.h:907
bool m_permissive
Definition diagnostic.h:900
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:934
void(* m_adjust_diagnostic_info)(diagnostic_context *, diagnostic_info *)
Definition diagnostic.h:946
unsigned m_lang_mask
Definition diagnostic.h:952
void create_edit_context()
Definition diagnostic.cc:655
diagnostic_buffer * get_diagnostic_buffer() const
Definition diagnostic.h:802
enum diagnostics_column_unit m_column_unit
Definition diagnostic.h:991
void emit_diagram(const diagnostic_diagram &diagram)
Definition diagnostic.cc:1732
int m_lock
Definition diagnostic.h:973
friend diagnostic_start_span_fn< to_text > & diagnostic_start_span(diagnostic_context *context)
Definition diagnostic.h:1093
void set_report_bug(bool val)
Definition diagnostic.h:670
bool m_show_rules
Definition diagnostic.h:877
void set_show_cwe(bool val)
Definition diagnostic.h:675
void clear_diagnostic_buffer(diagnostic_buffer &)
Definition diagnostic.cc:1978
bool bool int get_diagnostic_nesting_level() const
Definition diagnostic.h:781
int m_max_errors
Definition diagnostic.h:917
bool m_abort_on_error
Definition diagnostic.h:890
edit_context * m_edit_context_ptr
Definition diagnostic.h:1008
diagnostic_source_printing_options m_source_printing
Definition diagnostic.h:978
void set_abort_on_error(bool val)
Definition diagnostic.h:828
bool warning_as_error_requested_p() const
Definition diagnostic.h:694
void set_extra_output_kind(enum diagnostics_extra_output_kind kind)
Definition diagnostic.h:671
int m_group_nesting_depth
Definition diagnostic.h:1013
void set_show_highlight_colors(bool val)
Definition diagnostic.cc:637
diagnostic_buffer * m_diagnostic_buffer
Definition diagnostic.h:1071
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:392
diagnostic_location_print_policy(const diagnostic_context &dc)
Definition diagnostic.cc:783
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:414
bool show_column_p() const
Definition diagnostic.h:397
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:400
diagnostic_column_policy m_column_policy
Definition diagnostic.h:413
Definition diagnostic-metadata.h:33
Definition diagnostic.h:242
void push()
Definition diagnostic.cc:196
diagnostic_t update_effective_level_from_pragmas(diagnostic_info *diagnostic) const
Definition diagnostic.cc:1248
vec< int > m_push_list
Definition diagnostic.h:311
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:1083
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
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:433
diagnostic_start_span_fn< to_text > m_text_start_span_cb
Definition diagnostic.h:486
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:491
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:488
diagnostic_start_span_fn< to_html > m_html_start_span_cb
Definition diagnostic.h:487
file_cache & get_file_cache() const
Definition diagnostic.h:462
text_art::theme * get_diagram_theme() const
Definition diagnostic.h:471
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:456
enum diagnostics_escape_format m_escape_format
Definition diagnostic.h:492
class diagnostic_location_print_policy m_location_policy
Definition diagnostic.h:485
const diagnostic_source_printing_options & get_options() const
Definition diagnostic.h:453
const diagnostic_source_printing_options & m_options
Definition diagnostic.h:484
const diagnostic_location_print_policy & get_location_policy() const
Definition diagnostic.h:478
diagnostic_start_span_fn< to_html > get_html_start_span_fn() const
Definition diagnostic.h:459
enum diagnostics_escape_format get_escape_format() const
Definition diagnostic.h:465
const diagnostic_column_policy & get_column_policy() const
Definition diagnostic.h:473
Definition diagnostic-format-text.h:33
Definition edit-context.h:44
Definition input.h:136
Definition diagnostic.h:421
virtual void begin_label()=0
virtual void end_label()=0
virtual ~html_label_writer()
Definition diagnostic.h:423
Definition logical-location.h:91
Definition pretty-print.h:241
Definition libgdiagnostics.cc:211
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:1623
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:1294
location_t diagnostic_location(const diagnostic_info *diagnostic, int which=0)
Definition diagnostic.h:1283
const int CARET_LINE_MARGIN
Definition diagnostic.h:1309
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: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:1220
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:1211
diagnostic_text_starter_fn & diagnostic_text_starter(diagnostic_context *context)
Definition diagnostic.h:1084
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:70
@ DIAGNOSTICS_OUTPUT_FORMAT_SARIF_FILE
Definition diagnostic.h:84
@ DIAGNOSTICS_OUTPUT_FORMAT_JSON_STDERR
Definition diagnostic.h:75
@ DIAGNOSTICS_OUTPUT_FORMAT_TEXT
Definition diagnostic.h:72
@ DIAGNOSTICS_OUTPUT_FORMAT_SARIF_STDERR
Definition diagnostic.h:81
@ DIAGNOSTICS_OUTPUT_FORMAT_JSON_FILE
Definition diagnostic.h:78
void diagnostic_urls_init(diagnostic_context *context, int value=-1)
Definition diagnostic.h:1155
diagnostic_text_finalizer_fn & diagnostic_text_finalizer(diagnostic_context *context)
Definition diagnostic.h:1101
void diagnostic_inhibit_notes(diagnostic_context *context)
Definition diagnostic.h:1075
int get_terminal_width(void)
Definition diagnostic.cc:95
const char * diagnostic_get_color_for_kind(diagnostic_t kind)
Definition diagnostic.cc:702
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:1301
const char * get_diagnostic_kind_text(diagnostic_t kind)
Definition diagnostic.cc:807
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:1340
char * build_message_string(const char *,...) ATTRIBUTE_PRINTF_1
Definition diagnostic.cc:78
void diagnostic_finish(diagnostic_context *context)
Definition diagnostic.h:1161
bool warning_enabled_at(location_t loc, diagnostic_option_id option_id)
Definition diagnostic.h:1334
unsigned int diagnostic_num_locations(const diagnostic_info *diagnostic)
Definition diagnostic.h:1291
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:1181
void diagnostic_initialize(diagnostic_context *context, int n_opts)
Definition diagnostic.h:1143
void diagnostic_set_option_id(diagnostic_info *info, diagnostic_option_id option_id)
Definition diagnostic.h:1134
void diagnostic_color_init(diagnostic_context *context, int value=-1)
Definition diagnostic.h:1149
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:1167
diagnostic_start_span_fn< to_text > & diagnostic_start_span(diagnostic_context *context)
Definition diagnostic.h:1093
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:1235
void diagnostic_push_diagnostics(diagnostic_context *context, location_t where)
Definition diagnostic.h:1229
bool diagnostic_same_line(const diagnostic_context *context, expanded_location s1, expanded_location s2)
Definition diagnostic.h:1316
bool diagnostic_report_diagnostic(diagnostic_context *context, diagnostic_info *diagnostic)
Definition diagnostic.h:1249
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-diagram.h:25
Definition diagnostic.h:35
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:959
bool m_owned
Definition diagnostic.h:961
urlifier * m_urlifier
Definition diagnostic.h:960
Definition diagnostic.h:500
void clear()
Definition diagnostic.cc:2042
diagnostic_counters()
Definition diagnostic.cc:2010
void move_to(diagnostic_counters &dest)
Definition diagnostic.cc:2034
int get_count(diagnostic_t kind) const
Definition diagnostic.h:506
int m_count_for_kind[DK_LAST_DIAGNOSTIC_KIND]
Definition diagnostic.h:511
void DEBUG_FUNCTION dump() const
Definition diagnostic.h:504
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:318
bool enabled
Definition diagnostic.h:322
bool show_line_numbers_p
Definition diagnostic.h:346
bool show_event_links_p
Definition diagnostic.h:360
int max_width
Definition diagnostic.h:325
char caret_chars[rich_location::STATICALLY_ALLOCATED_RANGES]
Definition diagnostic.h:328
bool show_ruler_p
Definition diagnostic.h:355
bool show_labels_p
Definition diagnostic.h:341
bool colorize_source_p
Definition diagnostic.h:337
int min_margin_width
Definition diagnostic.h:351
Definition libgdiagnostics.cc:907
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