1 /* Declarations for managing different output formats for diagnostics.
2 Copyright (C) 2023-2024 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_DIAGNOSTIC_FORMAT_H
22 #define GCC_DIAGNOSTIC_FORMAT_H
24 /* Abstract base class for a particular output format for diagnostics;
25 each value of -fdiagnostics-output-format= will have its own
28 class diagnostic_output_format
31 virtual ~diagnostic_output_format () {}
33 virtual void on_begin_group () = 0;
34 virtual void on_end_group () = 0;
36 /* Vfunc with responsibility for phase 3 of formatting the message
37 and "printing" the result. */
38 virtual void on_report_diagnostic (const diagnostic_info
&,
39 diagnostic_t orig_diag_kind
) = 0;
41 virtual void on_diagram (const diagnostic_diagram
&diagram
) = 0;
42 virtual bool machine_readable_stderr_p () const = 0;
44 pretty_printer
*get_printer () const { return m_context
.m_printer
; }
47 diagnostic_output_format (diagnostic_context
&context
)
51 diagnostic_context
&m_context
;
55 diagnostic_output_format_init (diagnostic_context
&,
56 const char *main_input_filename_
,
57 const char *base_file_name
,
58 enum diagnostics_output_format
,
59 bool json_formatting
);
61 diagnostic_output_format_init_json_stderr (diagnostic_context
&context
,
64 diagnostic_output_format_init_json_file (diagnostic_context
&context
,
66 const char *base_file_name
);
68 diagnostic_output_format_init_sarif_stderr (diagnostic_context
&context
,
69 const line_maps
*line_maps
,
70 const char *main_input_filename_
,
73 diagnostic_output_format_init_sarif_file (diagnostic_context
&context
,
74 const line_maps
*line_maps
,
75 const char *main_input_filename_
,
77 const char *base_file_name
);
79 diagnostic_output_format_init_sarif_stream (diagnostic_context
&context
,
80 const line_maps
*line_maps
,
81 const char *main_input_filename_
,
85 #endif /* ! GCC_DIAGNOSTIC_FORMAT_H */