| 1 |
/* Declarations for managing different output formats for diagnostics. |
| 2 |
Copyright (C) 2023-2025 Free Software Foundation, Inc. |
| 3 |
Contributed by David Malcolm <[email protected]>. |
| 4 |
|
| 5 |
This file is part of GCC. |
| 6 |
|
| 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 |
| 10 |
version. |
| 11 |
|
| 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 |
| 15 |
for more details. |
| 16 |
|
| 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/>. */ |
| 20 |
|
| 21 |
#ifndef GCC_DIAGNOSTIC_FORMAT_H |
| 22 |
#define GCC_DIAGNOSTIC_FORMAT_H |
| 23 |
|
| 24 |
#include "diagnostic.h" |
| 25 |
|
| 26 |
class diagnostic_per_format_buffer; |
| 27 |
|
| 28 |
/* Abstract base class for a particular output format for diagnostics; |
| 29 |
each value of -fdiagnostics-output-format= will have its own |
| 30 |
implementation. */ |
| 31 |
|
| 32 |
class diagnostic_output_format |
| 33 |
{ |
| 34 |
public: |
| 35 |
virtual ~diagnostic_output_format () {} |
| 36 |
|
| 37 |
virtual void dump (FILE *out, int indent) const; |
| 38 |
|
| 39 |
/* Vfunc for making an appropriate diagnostic_per_format_buffer |
| 40 |
subclass for this format. */ |
| 41 |
virtual std::unique_ptr<diagnostic_per_format_buffer> |
| 42 |
make_per_format_buffer () = 0; |
| 43 |
|
| 44 |
/* Vfunc to be called when call a diagnostic_buffer is set on |
| 45 |
a diagnostic_context, to update this format. The per_format_buffer |
| 46 |
will be one created by make_per_format_buffer above and thus be |
| 47 |
of the correct subclass. */ |
| 48 |
virtual void set_buffer (diagnostic_per_format_buffer *) = 0; |
| 49 |
|
| 50 |
virtual void on_begin_group () = 0; |
| 51 |
virtual void on_end_group () = 0; |
| 52 |
|
| 53 |
/* Vfunc with responsibility for phase 3 of formatting the message |
| 54 |
and "printing" the result. */ |
| 55 |
virtual void on_report_diagnostic (const diagnostic_info &, |
| 56 |
diagnostic_t orig_diag_kind) = 0; |
| 57 |
|
| 58 |
virtual void on_report_verbatim (text_info &); |
| 59 |
|
| 60 |
virtual void on_diagram (const diagnostic_diagram &diagram) = 0; |
| 61 |
virtual void after_diagnostic (const diagnostic_info &) = 0; |
| 62 |
virtual bool machine_readable_stderr_p () const = 0; |
| 63 |
virtual bool follows_reference_printer_p () const = 0; |
| 64 |
|
| 65 |
/* Vfunc called when the diagnostic_context changes its |
| 66 |
reference printer (either to a new subclass of pretty_printer |
| 67 |
or when color/url options change). |
| 68 |
Subclasses should update their m_printer accordingly. */ |
| 69 |
virtual void update_printer () = 0; |
| 70 |
|
| 71 |
diagnostic_context &get_context () const { return m_context; } |
| 72 |
pretty_printer *get_printer () const { return m_printer.get (); } |
| 73 |
|
| 74 |
text_art::theme *get_diagram_theme () const |
| 75 |
{ |
| 76 |
return m_context.get_diagram_theme (); |
| 77 |
} |
| 78 |
|
| 79 |
void DEBUG_FUNCTION dump () const { dump (stderr, 0); } |
| 80 |
|
| 81 |
protected: |
| 82 |
diagnostic_output_format (diagnostic_context &context) |
| 83 |
: m_context (context), |
| 84 |
m_printer (context.clone_printer ()) |
| 85 |
{} |
| 86 |
|
| 87 |
protected: |
| 88 |
diagnostic_context &m_context; |
| 89 |
std::unique_ptr<pretty_printer> m_printer; |
| 90 |
}; |
| 91 |
|
| 92 |
extern void |
| 93 |
diagnostic_output_format_init (diagnostic_context &, |
| 94 |
const char *main_input_filename_, |
| 95 |
const char *base_file_name, |
| 96 |
enum diagnostics_output_format, |
| 97 |
bool json_formatting); |
| 98 |
extern void |
| 99 |
diagnostic_output_format_init_json_stderr (diagnostic_context &context, |
| 100 |
bool formatted); |
| 101 |
extern void |
| 102 |
diagnostic_output_format_init_json_file (diagnostic_context &context, |
| 103 |
bool formatted, |
| 104 |
const char *base_file_name); |
| 105 |
|
| 106 |
#endif /* ! GCC_DIAGNOSTIC_FORMAT_H */ |