GCC Middle and Back End API Reference
diagnostic-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_DIAGNOSTIC_OUTPUT_SPEC_H
22#define GCC_DIAGNOSTIC_OUTPUT_SPEC_H
23
24#include "diagnostic-format.h"
26
28
29/* An abstract base class for handling the DSL of -fdiagnostics-add-output=
30 and -fdiagnostics-set-output=. */
31
33{
34 public:
35 std::unique_ptr<diagnostic_output_format>
36 parse_and_make_sink (const char *,
38
39 void
40 report_error (const char *gmsgid, ...) const
42
43 void
44 report_unknown_key (const char *unparsed_arg,
45 const std::string &key,
46 const std::string &scheme_name,
47 auto_vec<const char *> &known_keys) const;
48
49 void
50 report_missing_key (const char *unparsed_arg,
51 const std::string &key,
52 const std::string &scheme_name,
53 const char *metavar) const;
54
56 open_output_file (label_text &&filename) const;
57
58 const char *
59 get_option_name () const { return m_option_name; }
60
61 line_maps *
63
64 virtual ~context () {}
65
66 virtual void
67 report_error_va (const char *gmsgid, va_list *ap) const = 0;
68
69 virtual const char *
70 get_base_filename () const = 0;
71
72protected:
73 context (const char *option_name,
74 line_maps *affected_location_mgr)
75 : m_option_name (option_name),
76 m_affected_location_mgr (affected_location_mgr)
77 {
78 }
79
80 const char *m_option_name;
82};
83
84/* A subclass that implements reporting errors via a diagnostic_context. */
85
87{
88public:
90 line_maps *affected_location_mgr,
91 line_maps *control_location_mgr,
92 location_t loc,
93 const char *option_name)
94 : context (option_name, affected_location_mgr),
95 m_dc (dc),
96 m_control_location_mgr (control_location_mgr),
97 m_loc (loc)
98 {}
99
100 void report_error_va (const char *gmsgid, va_list *ap) const final override
102 {
103 m_dc.begin_group ();
105 m_dc.diagnostic_impl (&richloc, nullptr, -1, gmsgid, ap, DK_ERROR);
106 m_dc.end_group ();
107 }
108
111 location_t m_loc;
112};
113
114} // namespace diagnostics_output_spec
115
116#endif
Definition vec.h:1667
Definition diagnostic.h:551
Definition diagnostic-output-file.h:28
Definition diagnostic-output-spec.h:33
virtual void report_error_va(const char *gmsgid, va_list *ap) const =0
context(const char *option_name, line_maps *affected_location_mgr)
Definition diagnostic-output-spec.h:73
line_maps * get_affected_location_mgr() const
Definition diagnostic-output-spec.h:62
void report_missing_key(const char *unparsed_arg, const std::string &key, const std::string &scheme_name, const char *metavar) const
Definition diagnostic-output-spec.cc:230
const char * m_option_name
Definition diagnostic-output-spec.h:80
diagnostic_output_file open_output_file(label_text &&filename) const
Definition diagnostic-output-spec.cc:245
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 diagnostic-output-spec.cc:216
virtual const char * get_base_filename() const =0
std::unique_ptr< diagnostic_output_format > parse_and_make_sink(const char *, diagnostic_context &dc)
Definition diagnostic-output-spec.cc:307
line_maps * m_affected_location_mgr
Definition diagnostic-output-spec.h:81
virtual ~context()
Definition diagnostic-output-spec.h:64
void report_error(const char *gmsgid,...) const ATTRIBUTE_GCC_DIAG(2
Definition diagnostic-output-spec.cc:207
const char * get_option_name() const
Definition diagnostic-output-spec.h:59
#define ATTRIBUTE_GCC_DIAG(m, n)
Definition diagnostic-core.h:103
Definition diagnostic-output-spec.cc:48
static void const char va_list ap
Definition read-md.cc:205
diagnostic_context & m_dc
Definition diagnostic-output-spec.h:109
m_dc diagnostic_impl & richloc
Definition diagnostic-output-spec.h:105
void rich_location richloc(m_control_location_mgr, m_loc)
gcc_spec_context(diagnostic_context &dc, line_maps *affected_location_mgr, line_maps *control_location_mgr, location_t loc, const char *option_name)
Definition diagnostic-output-spec.h:89
location_t m_loc
Definition diagnostic-output-spec.h:111
void report_error_va(const char *gmsgid, va_list *ap) const final override ATTRIBUTE_GCC_DIAG(2
line_maps * m_control_location_mgr
Definition diagnostic-output-spec.h:110