Branch data Line data Source code
1 : : /* Support for -fdiagnostics-add-output= and -fdiagnostics-set-output=.
2 : : Copyright (C) 2024-2025 Free Software Foundation, Inc.
3 : :
4 : : This file is part of GCC.
5 : :
6 : : GCC is free software; you can redistribute it and/or modify it under
7 : : the terms of the GNU General Public License as published by the Free
8 : : Software Foundation; either version 3, or (at your option) any later
9 : : version.
10 : :
11 : : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 : : WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 : : FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 : : for more details.
15 : :
16 : : You should have received a copy of the GNU General Public License
17 : : along with GCC; see the file COPYING3. If not see
18 : : <http://www.gnu.org/licenses/>. */
19 : :
20 : :
21 : : /* This file implements the options -fdiagnostics-add-output=,
22 : : -fdiagnostics-set-output=. Most of the work is done
23 : : by diagnostics/output-spec.cc so it can be shared by libgdiagnostics. */
24 : :
25 : : #include "config.h"
26 : : #define INCLUDE_ARRAY
27 : : #define INCLUDE_STRING
28 : : #define INCLUDE_VECTOR
29 : : #include "system.h"
30 : : #include "coretypes.h"
31 : : #include "version.h"
32 : : #include "intl.h"
33 : : #include "diagnostic.h"
34 : : #include "diagnostics/output-spec.h"
35 : : #include "opts.h"
36 : : #include "options.h"
37 : :
38 : : /* Decls. */
39 : :
40 : : namespace {
41 : :
42 : 30 : struct opt_spec_context : public diagnostics::output_spec::dc_spec_context
43 : : {
44 : : public:
45 : 30 : opt_spec_context (const gcc_options &opts,
46 : : diagnostics::context &dc,
47 : : line_maps *location_mgr,
48 : : location_t loc,
49 : : const char *option_name)
50 : 30 : : dc_spec_context (dc,
51 : : location_mgr,
52 : : location_mgr,
53 : : loc,
54 : : option_name),
55 : 30 : m_opts (opts)
56 : : {}
57 : :
58 : : const char *
59 : 16 : get_base_filename () const final override
60 : : {
61 : 16 : return (m_opts.x_dump_base_name
62 : : ? m_opts.x_dump_base_name
63 : 16 : : m_opts.x_main_input_basename);
64 : : }
65 : :
66 : : const gcc_options &m_opts;
67 : : };
68 : :
69 : : } // anon namespace
70 : :
71 : : void
72 : 16 : handle_OPT_fdiagnostics_add_output_ (const gcc_options &opts,
73 : : diagnostics::context &dc,
74 : : const char *arg,
75 : : location_t loc)
76 : : {
77 : 16 : gcc_assert (arg);
78 : 16 : gcc_assert (line_table);
79 : :
80 : 16 : const char *const option_name = "-fdiagnostics-add-output=";
81 : 16 : opt_spec_context ctxt (opts, dc, line_table, loc, option_name);
82 : 16 : auto sink = ctxt.parse_and_make_sink (arg, dc);
83 : 16 : if (!sink)
84 : 0 : return;
85 : :
86 : 16 : sink->set_main_input_filename (opts.x_main_input_filename);
87 : 16 : dc.add_sink (std::move (sink));
88 : 16 : }
89 : :
90 : : void
91 : 14 : handle_OPT_fdiagnostics_set_output_ (const gcc_options &opts,
92 : : diagnostics::context &dc,
93 : : const char *arg,
94 : : location_t loc)
95 : : {
96 : 14 : gcc_assert (arg);
97 : 14 : gcc_assert (line_table);
98 : :
99 : 14 : const char *const option_name = "-fdiagnostics-set-output=";
100 : 14 : opt_spec_context ctxt (opts, dc, line_table, loc, option_name);
101 : 14 : auto sink = ctxt.parse_and_make_sink (arg, dc);
102 : 14 : if (!sink)
103 : 0 : return;
104 : :
105 : 14 : sink->set_main_input_filename (opts.x_main_input_filename);
106 : 14 : dc.set_sink (std::move (sink));
107 : 14 : }
|