GCC Middle and Back End API Reference
output-spec.h
Go to the documentation of this file.
1/* Support for the DSL of -fdiagnostics-add-output= and
2 -fdiagnostics-set-output=.
3 Copyright (C) 2024-2025 Free Software Foundation, Inc.
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_OUTPUT_SPEC_H
22#define GCC_DIAGNOSTICS_OUTPUT_SPEC_H
23
24#include "diagnostics/sink.h"
26
27namespace diagnostics {
28namespace output_spec {
29
30/* An abstract base class for handling the DSL of -fdiagnostics-add-output=
31 and -fdiagnostics-set-output=. */
32
34{
35 public:
36 std::unique_ptr<sink>
37 parse_and_make_sink (const char *,
39
40 void
41 report_error (const char *gmsgid, ...) const
43
44 void
45 report_unknown_key (const char *unparsed_arg,
46 const std::string &key,
47 const std::string &scheme_name,
48 auto_vec<const char *> &known_keys) const;
49
50 void
51 report_missing_key (const char *unparsed_arg,
52 const std::string &key,
53 const std::string &scheme_name,
54 const char *metavar) const;
55
57 open_output_file (label_text &&filename) const;
58
59 const char *
60 get_option_name () const { return m_option_name; }
61
62 line_maps *
64
65 virtual ~context () {}
66
67 virtual void
68 report_error_va (const char *gmsgid, va_list *ap) const = 0;
69
70 virtual const char *
71 get_base_filename () const = 0;
72
73protected:
74 context (const char *option_name,
75 line_maps *affected_location_mgr)
76 : m_option_name (option_name),
77 m_affected_location_mgr (affected_location_mgr)
78 {
79 }
80
81 const char *m_option_name;
83};
84
85/* A subclass that implements reporting errors via a diagnostics::context. */
86
88{
89public:
91 line_maps *affected_location_mgr,
92 line_maps *control_location_mgr,
93 location_t loc,
94 const char *option_name)
95 : context (option_name, affected_location_mgr),
96 m_dc (dc),
97 m_control_location_mgr (control_location_mgr),
98 m_loc (loc)
99 {}
100
101 void report_error_va (const char *gmsgid, va_list *ap) const final override
103 {
104 m_dc.begin_group ();
106 m_dc.diagnostic_impl (&richloc, nullptr, -1, gmsgid, ap, kind::error);
107 m_dc.end_group ();
108 }
109
112 location_t m_loc;
113};
114
115} // namespace output_spec
116} // namespace diagnostics
117
118#endif // #ifndef GCC_DIAGNOSTICS_OUTPUT_SPEC_H
Definition vec.h:1667
Definition diagnostics/context.h:253
Definition output-file.h:32
Definition output-spec.h:34
context(const char *option_name, line_maps *affected_location_mgr)
Definition output-spec.h:74
void report_missing_key(const char *unparsed_arg, const std::string &key, const std::string &scheme_name, const char *metavar) const
Definition output-spec.cc:227
virtual const char * get_base_filename() const =0
void void report_unknown_key(const char *unparsed_arg, const std::string &key, const std::string &scheme_name, auto_vec< const char * > &known_keys) const
Definition output-spec.cc:213
line_maps * m_affected_location_mgr
Definition output-spec.h:82
std::unique_ptr< sink > parse_and_make_sink(const char *, diagnostics::context &dc)
Definition output-spec.cc:304
line_maps * get_affected_location_mgr() const
Definition output-spec.h:63
const char * get_option_name() const
Definition output-spec.h:60
virtual void report_error_va(const char *gmsgid, va_list *ap) const =0
void report_error(const char *gmsgid,...) const ATTRIBUTE_GCC_DIAG(2
Definition output-spec.cc:204
virtual ~context()
Definition output-spec.h:65
const char * m_option_name
Definition output-spec.h:81
output_file open_output_file(label_text &&filename) const
Definition output-spec.cc:242
#define ATTRIBUTE_GCC_DIAG(m, n)
Definition diagnostic-core.h:71
Definition output-spec.cc:49
Definition coretypes.h:167
static void const char va_list ap
Definition read-md.cc:205
dc_spec_context(diagnostics::context &dc, line_maps *affected_location_mgr, line_maps *control_location_mgr, location_t loc, const char *option_name)
Definition output-spec.h:90
void report_error_va(const char *gmsgid, va_list *ap) const final override ATTRIBUTE_GCC_DIAG(2
m_dc diagnostic_impl & richloc
Definition output-spec.h:106
void rich_location richloc(m_control_location_mgr, m_loc)
line_maps * m_control_location_mgr
Definition output-spec.h:111
location_t m_loc
Definition output-spec.h:112
diagnostics::context & m_dc
Definition output-spec.h:110