Branch data Line data Source code
1 : : /* Declarations for managing different output formats for diagnostics.
2 : : Copyright (C) 2023-2025 Free Software Foundation, Inc.
3 : : Contributed by David Malcolm <dmalcolm@redhat.com>.
4 : :
5 : : This file is part of GCC.
6 : :
7 : : GCC is free software; you can redistribute it and/or modify it under
8 : : the terms of the GNU General Public License as published by the Free
9 : : Software Foundation; either version 3, or (at your option) any later
10 : : version.
11 : :
12 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 : : for more details.
16 : :
17 : : You should have received a copy of the GNU General Public License
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : : #ifndef GCC_DIAGNOSTICS_SINK_H
22 : : #define GCC_DIAGNOSTICS_SINK_H
23 : :
24 : : #include "diagnostic.h"
25 : :
26 : : namespace diagnostics {
27 : :
28 : : class per_sink_buffer;
29 : :
30 : : /* Abstract base class for a particular output format for diagnostics;
31 : : each value of -fdiagnostics-output-format= will have its own
32 : : implementation. */
33 : :
34 : : class sink
35 : : {
36 : : public:
37 : 307795 : virtual ~sink () {}
38 : :
39 : 0 : virtual text_sink *dyn_cast_text_sink () { return nullptr; }
40 : :
41 : : virtual void dump_kind (FILE *out) const = 0;
42 : : virtual void dump (FILE *out, int indent) const;
43 : :
44 : : /* Vfunc for notifying this format what the primary input file is,
45 : : e.g. for titles of HTML, for SARIF's artifact metadata. */
46 : 12 : virtual void set_main_input_filename (const char *) {}
47 : :
48 : : /* Vfunc for making an appropriate per_sink_buffer
49 : : subclass for this format. */
50 : : virtual std::unique_ptr<per_sink_buffer>
51 : : make_per_sink_buffer () = 0;
52 : :
53 : : /* Vfunc to be called when call a diagnostics::buffer is set on
54 : : a diagnostics::context, to update this format. The per_sink_buffer
55 : : will be one created by make_per_sink_buffer above and thus be
56 : : of the correct subclass. */
57 : : virtual void set_buffer (per_sink_buffer *) = 0;
58 : :
59 : : virtual void on_begin_group () = 0;
60 : : virtual void on_end_group () = 0;
61 : :
62 : : /* Vfunc with responsibility for phase 3 of formatting the message
63 : : and "printing" the result. */
64 : : virtual void on_report_diagnostic (const diagnostic_info &,
65 : : enum kind orig_diag_kind) = 0;
66 : :
67 : : virtual void on_report_verbatim (text_info &);
68 : :
69 : : virtual void on_diagram (const diagram &diag) = 0;
70 : : virtual void after_diagnostic (const diagnostic_info &) = 0;
71 : : virtual bool machine_readable_stderr_p () const = 0;
72 : : virtual bool follows_reference_printer_p () const = 0;
73 : :
74 : : /* Vfunc called when the diagnostics::context changes its
75 : : reference printer (either to a new subclass of pretty_printer
76 : : or when color/url options change).
77 : : Subclasses should update their m_printer accordingly. */
78 : : virtual void update_printer () = 0;
79 : :
80 : : virtual void
81 : : report_global_digraph (const lazily_created<digraphs::digraph> &) = 0;
82 : :
83 : 4340079 : context &get_context () const { return m_context; }
84 : 18942112 : pretty_printer *get_printer () const { return m_printer.get (); }
85 : :
86 : 2644 : text_art::theme *get_diagram_theme () const
87 : : {
88 : 2644 : return m_context.get_diagram_theme ();
89 : : }
90 : :
91 : 0 : void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
92 : :
93 : 1533846 : logging::logger *get_logger () { return m_context.get_logger (); }
94 : :
95 : : protected:
96 : 712611 : sink (context &dc)
97 : 712611 : : m_context (dc),
98 : 712611 : m_printer (dc.clone_printer ())
99 : : {}
100 : :
101 : : protected:
102 : : context &m_context;
103 : : std::unique_ptr<pretty_printer> m_printer;
104 : : };
105 : :
106 : : extern void
107 : : output_format_init (context &,
108 : : const char *main_input_filename_,
109 : : const char *base_file_name,
110 : : enum diagnostics_output_format,
111 : : bool json_formatting);
112 : :
113 : : } // namespace diagnostics
114 : :
115 : : #endif /* ! GCC_DIAGNOSTICS_SINK_H */
|