1 /* Classic text-based output of 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_TEXT_H
22 #define GCC_DIAGNOSTIC_FORMAT_TEXT_H
24 #include "diagnostic-format.h"
26 /* Subclass of diagnostic_output_format for classic text-based output
29 Uses diagnostic_context.m_text_callbacks to provide client-specific
30 textual output (e.g. include paths, macro expansions, etc). */
32 class diagnostic_text_output_format
: public diagnostic_output_format
35 diagnostic_text_output_format (diagnostic_context
&context
)
36 : diagnostic_output_format (context
),
37 m_column_policy (context
),
38 m_last_module (nullptr),
39 m_includes_seen (nullptr)
41 ~diagnostic_text_output_format ();
42 void on_begin_group () override
{}
43 void on_end_group () override
{}
44 void on_report_diagnostic (const diagnostic_info
&,
45 diagnostic_t orig_diag_kind
) override
;
46 void on_diagram (const diagnostic_diagram
&diagram
) override
;
47 void after_diagnostic (const diagnostic_info
&) final override
;
48 bool machine_readable_stderr_p () const final override
53 /* Helpers for writing lang-specific starters/finalizers for text output. */
54 char *build_prefix (const diagnostic_info
&) const;
55 void report_current_module (location_t where
);
56 void append_note (location_t location
,
57 const char * gmsgid
, ...) ATTRIBUTE_GCC_DIAG(3,4);
60 char *file_name_as_prefix (const char *) const;
62 void print_path (const diagnostic_path
&path
);
64 bool show_column_p () const { return get_context ().m_show_column
; }
66 const diagnostic_column_policy
&get_column_policy () const
68 return m_column_policy
;
70 diagnostic_location_print_policy
get_location_print_policy () const;
73 void print_any_cwe (const diagnostic_info
&diagnostic
);
74 void print_any_rules (const diagnostic_info
&diagnostic
);
75 void print_option_information (const diagnostic_info
&diagnostic
,
76 diagnostic_t orig_diag_kind
);
78 label_text
get_location_text (const expanded_location
&s
) const;
79 bool includes_seen_p (const line_map_ordinary
*map
);
81 diagnostic_column_policy m_column_policy
;
83 /* Used to detect when the input file stack has changed since last
85 const line_map_ordinary
*m_last_module
;
87 /* Include files that report_current_module has already listed the
89 hash_set
<location_t
, false, location_hash
> *m_includes_seen
;
92 #endif /* ! GCC_DIAGNOSTIC_FORMAT_TEXT_H */