GCC Middle and Back End API Reference
diagnostic-format.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_DIAGNOSTIC_FORMAT_H
22#define GCC_DIAGNOSTIC_FORMAT_H
23
24#include "diagnostic.h"
25
27
28/* Abstract base class for a particular output format for diagnostics;
29 each value of -fdiagnostics-output-format= will have its own
30 implementation. */
31
33{
34public:
36
37 virtual void dump (FILE *out, int indent) const;
38
39 /* Vfunc for making an appropriate diagnostic_per_format_buffer
40 subclass for this format. */
41 virtual std::unique_ptr<diagnostic_per_format_buffer>
43
44 /* Vfunc to be called when call a diagnostic_buffer is set on
45 a diagnostic_context, to update this format. The per_format_buffer
46 will be one created by make_per_format_buffer above and thus be
47 of the correct subclass. */
49
50 virtual void on_begin_group () = 0;
51 virtual void on_end_group () = 0;
52
53 /* Vfunc with responsibility for phase 3 of formatting the message
54 and "printing" the result. */
56 diagnostic_t orig_diag_kind) = 0;
57
58 virtual void on_report_verbatim (text_info &);
59
60 virtual void on_diagram (const diagnostic_diagram &diagram) = 0;
61 virtual void after_diagnostic (const diagnostic_info &) = 0;
62 virtual bool machine_readable_stderr_p () const = 0;
63 virtual bool follows_reference_printer_p () const = 0;
64
65 /* Vfunc called when the diagnostic_context changes its
66 reference printer (either to a new subclass of pretty_printer
67 or when color/url options change).
68 Subclasses should update their m_printer accordingly. */
69 virtual void update_printer () = 0;
70
72 pretty_printer *get_printer () const { return m_printer.get (); }
73
74 text_art::theme *get_diagram_theme () const
75 {
77 }
78
79 void DEBUG_FUNCTION dump () const { dump (stderr, 0); }
80
81protected:
83 : m_context (context),
84 m_printer (context.clone_printer ())
85 {}
86
87protected:
89 std::unique_ptr<pretty_printer> m_printer;
90};
91
92extern void
94 const char *main_input_filename_,
95 const char *base_file_name,
97 bool json_formatting);
98extern void
100 bool formatted);
101extern void
103 bool formatted,
104 const char *base_file_name);
105
106#endif /* ! GCC_DIAGNOSTIC_FORMAT_H */
Definition diagnostic.h:506
text_art::theme * get_diagram_theme() const
Definition diagnostic.h:672
Definition diagnostic-diagram.h:33
Definition diagnostic-format.h:33
virtual void on_end_group()=0
virtual bool machine_readable_stderr_p() const =0
virtual void on_report_verbatim(text_info &)
Definition diagnostic.cc:1768
virtual bool follows_reference_printer_p() const =0
pretty_printer * get_printer() const
Definition diagnostic-format.h:72
diagnostic_output_format(diagnostic_context &context)
Definition diagnostic-format.h:82
virtual void update_printer()=0
text_art::theme * get_diagram_theme() const
Definition diagnostic-format.h:74
virtual void on_diagram(const diagnostic_diagram &diagram)=0
std::unique_ptr< pretty_printer > m_printer
Definition diagnostic-format.h:89
virtual void after_diagnostic(const diagnostic_info &)=0
virtual void on_begin_group()=0
virtual std::unique_ptr< diagnostic_per_format_buffer > make_per_format_buffer()=0
virtual ~diagnostic_output_format()
Definition diagnostic-format.h:35
virtual void on_report_diagnostic(const diagnostic_info &, diagnostic_t orig_diag_kind)=0
diagnostic_context & get_context() const
Definition diagnostic-format.h:71
void DEBUG_FUNCTION dump() const
Definition diagnostic-format.h:79
virtual void set_buffer(diagnostic_per_format_buffer *)=0
diagnostic_context & m_context
Definition diagnostic-format.h:88
Definition diagnostic-buffer.h:96
Definition pretty-print.h:241
diagnostic_t
Definition diagnostic-core.h:29
void diagnostic_output_format_init_json_file(diagnostic_context &context, bool formatted, const char *base_file_name)
Definition diagnostic-format-json.cc:535
void diagnostic_output_format_init_json_stderr(diagnostic_context &context, bool formatted)
Definition diagnostic-format-json.cc:522
void diagnostic_output_format_init(diagnostic_context &, const char *main_input_filename_, const char *base_file_name, enum diagnostics_output_format, bool json_formatting)
Definition diagnostic.cc:1777
diagnostics_output_format
Definition diagnostic.h:65
static const char * base_file_name(const char *file_name)
Definition genautomata.cc:9225
Definition diagnostic.h:137
Definition pretty-print.h:34
#define DEBUG_FUNCTION
Definition system.h:1236