GCC Middle and Back End API Reference
sink.h
Go to the documentation of this file.
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
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_DIAGNOSTICS_SINK_H
22#define GCC_DIAGNOSTICS_SINK_H
23
24#include "diagnostic.h"
25
26namespace diagnostics {
27
28class 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
34class sink
35{
36public:
37 virtual ~sink () {}
38
39 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 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>
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. */
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
82
83 context &get_context () const { return m_context; }
84 pretty_printer *get_printer () const { return m_printer.get (); }
85
87 {
88 return m_context.get_diagram_theme ();
89 }
90
91 void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
92
93 logging::logger *get_logger () { return m_context.get_logger (); }
94
95protected:
97 : m_context (dc),
98 m_printer (dc.clone_printer ())
99 {}
100
101protected:
103 std::unique_ptr<pretty_printer> m_printer;
104};
105
106extern void
108 const char *main_input_filename_,
109 const char *base_file_name,
111 bool json_formatting);
112
113} // namespace diagnostics
114
115#endif /* ! GCC_DIAGNOSTICS_SINK_H */
Definition diagnostics/context.h:254
Definition diagram.h:35
Definition logging.h:38
Definition buffering.h:98
std::unique_ptr< pretty_printer > m_printer
Definition sink.h:103
virtual void on_begin_group()=0
virtual text_sink * dyn_cast_text_sink()
Definition sink.h:39
text_art::theme * get_diagram_theme() const
Definition sink.h:86
context & get_context() const
Definition sink.h:83
virtual void on_diagram(const diagram &diag)=0
virtual std::unique_ptr< per_sink_buffer > make_per_sink_buffer()=0
virtual void set_buffer(per_sink_buffer *)=0
virtual bool follows_reference_printer_p() const =0
virtual void dump_kind(FILE *out) const =0
pretty_printer * get_printer() const
Definition sink.h:84
virtual void after_diagnostic(const diagnostic_info &)=0
virtual void on_report_diagnostic(const diagnostic_info &, enum kind orig_diag_kind)=0
virtual void on_end_group()=0
context & m_context
Definition sink.h:102
sink(context &dc)
Definition sink.h:96
void DEBUG_FUNCTION dump() const
Definition sink.h:91
virtual bool machine_readable_stderr_p() const =0
virtual void report_global_digraph(const lazily_created< digraphs::digraph > &)=0
virtual void update_printer()=0
virtual void on_report_verbatim(text_info &)
Definition diagnostics/context.cc:1866
virtual ~sink()
Definition sink.h:37
virtual void set_main_input_filename(const char *)
Definition sink.h:46
logging::logger * get_logger()
Definition sink.h:93
Definition text-sink.h:35
Definition lazily-created.h:31
Definition pretty-print.h:241
Definition theme.h:30
diagnostics_output_format
Definition context-options.h:54
static const char * base_file_name(const char *file_name)
Definition genautomata.cc:9229
Definition coretypes.h:167
void output_format_init(context &dc, const char *main_input_filename_, const char *base_file_name, enum diagnostics_output_format format, bool json_formatting)
Definition diagnostics/context.cc:1875
kind
Definition kinds.h:27
Definition diagnostic-info.h:32
Definition pretty-print.h:34
#define DEBUG_FUNCTION
Definition system.h:1236