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 "diagnostics/logging.h"
36 : : #include "opts.h"
37 : : #include "options.h"
38 : :
39 : : /* Decls. */
40 : :
41 : : namespace {
42 : :
43 : 37 : struct opt_spec_context : public diagnostics::output_spec::dc_spec_context
44 : : {
45 : : public:
46 : 37 : opt_spec_context (const gcc_options &opts,
47 : : diagnostics::context &dc,
48 : : line_maps *location_mgr,
49 : : location_t loc,
50 : : const char *option_name)
51 : 37 : : dc_spec_context (dc,
52 : : location_mgr,
53 : : location_mgr,
54 : : loc,
55 : : option_name),
56 : 37 : m_opts (opts)
57 : : {}
58 : :
59 : : const char *
60 : 23 : get_base_filename () const final override
61 : : {
62 : 23 : return (m_opts.x_dump_base_name
63 : : ? m_opts.x_dump_base_name
64 : 23 : : m_opts.x_main_input_basename);
65 : : }
66 : :
67 : : const gcc_options &m_opts;
68 : : };
69 : :
70 : : } // anon namespace
71 : :
72 : : void
73 : 23 : handle_OPT_fdiagnostics_add_output_ (const gcc_options &opts,
74 : : diagnostics::context &dc,
75 : : const char *arg,
76 : : location_t loc)
77 : : {
78 : 23 : gcc_assert (arg);
79 : 23 : gcc_assert (line_table);
80 : :
81 : 23 : const char *const option_name = "-fdiagnostics-add-output=";
82 : 23 : DIAGNOSTICS_LOG_SCOPE_PRINTF2 (dc.get_logger (),
83 : 23 : "handling: %s%s", option_name, arg);
84 : 23 : opt_spec_context ctxt (opts, dc, line_table, loc, option_name);
85 : 23 : auto sink = ctxt.parse_and_make_sink (arg, dc);
86 : 23 : if (!sink)
87 : 0 : return;
88 : :
89 : 23 : sink->set_main_input_filename (opts.x_main_input_filename);
90 : 23 : dc.add_sink (std::move (sink));
91 : 23 : }
92 : :
93 : : void
94 : 14 : handle_OPT_fdiagnostics_set_output_ (const gcc_options &opts,
95 : : diagnostics::context &dc,
96 : : const char *arg,
97 : : location_t loc)
98 : : {
99 : 14 : gcc_assert (arg);
100 : 14 : gcc_assert (line_table);
101 : :
102 : 14 : const char *const option_name = "-fdiagnostics-set-output=";
103 : 14 : DIAGNOSTICS_LOG_SCOPE_PRINTF2 (dc.get_logger (),
104 : 14 : "handling: %s%s", option_name, arg);
105 : 14 : opt_spec_context ctxt (opts, dc, line_table, loc, option_name);
106 : 14 : auto sink = ctxt.parse_and_make_sink (arg, dc);
107 : 14 : if (!sink)
108 : 0 : return;
109 : :
110 : 14 : sink->set_main_input_filename (opts.x_main_input_filename);
111 : 14 : dc.set_sink (std::move (sink));
112 : 14 : }
|