GCC Middle and Back End API Reference
diagnostic-format-text.h
Go to the documentation of this file.
1/* Classic text-based output of diagnostics.
2 Copyright (C) 2023-2025 Free Software Foundation, Inc.
3 Contributed by David Malcolm <dmalcolm@redhat.com>.
4
5This file is part of GCC.
6
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
11
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
16
17You should have received a copy of the GNU General Public License
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
20
21#ifndef GCC_DIAGNOSTIC_FORMAT_TEXT_H
22#define GCC_DIAGNOSTIC_FORMAT_TEXT_H
23
24#include "diagnostic-format.h"
25
26/* Subclass of diagnostic_output_format for classic text-based output
27 to stderr.
28
29 Uses diagnostic_context.m_text_callbacks to provide client-specific
30 textual output (e.g. include paths, macro expansions, etc). */
31
33{
34public:
36 diagnostic_source_printing_options *source_printing = nullptr,
37 bool follows_reference_printer = false)
38 : diagnostic_output_format (context),
39 m_saved_output_buffer (nullptr),
40 m_column_policy (context),
41 m_last_module (nullptr),
42 m_includes_seen (nullptr),
43 m_source_printing (source_printing
44 ? *source_printing
45 : context.m_source_printing),
46 m_follows_reference_printer (follows_reference_printer),
49 {}
51
52 void dump (FILE *out, int indent) const override;
53
54 std::unique_ptr<diagnostic_per_format_buffer>
55 make_per_format_buffer () final override;
57
58 void on_begin_group () override {}
59 void on_end_group () override {}
61 diagnostic_t orig_diag_kind) override;
62 void on_report_verbatim (text_info &) final override;
63 void on_diagram (const diagnostic_diagram &diagram) override;
64 void after_diagnostic (const diagnostic_info &) override;
65 bool machine_readable_stderr_p () const final override
66 {
67 return false;
68 }
69 bool follows_reference_printer_p () const final override;
70
71 void update_printer () override;
72
73 /* Helpers for writing lang-specific starters/finalizers for text output. */
74 char *build_prefix (const diagnostic_info &) const;
75 void report_current_module (location_t where);
76 void append_note (location_t location,
77 const char * gmsgid, ...) ATTRIBUTE_GCC_DIAG(3,4);
78
79
80 char *file_name_as_prefix (const char *) const;
81
82 char *build_indent_prefix (bool with_bullet) const;
83
84 void print_path (const diagnostic_path &path);
85
86 bool show_column_p () const { return get_context ().m_show_column; }
87
89 {
90 return m_column_policy;
91 }
93
94 bool show_nesting_p () const { return m_show_nesting; }
96 {
98 }
99
100 void set_show_nesting (bool show_nesting) { m_show_nesting = show_nesting; }
102 {
104 }
105 void set_show_nesting_levels (bool show_nesting_levels)
106 {
107 m_show_nesting_levels = show_nesting_levels;
108 }
109
110 label_text get_location_text (const expanded_location &s) const;
111
120
121protected:
125 diagnostic_t orig_diag_kind);
126
127 bool includes_seen_p (const line_map_ordinary *map);
128
129 /* For handling diagnostic_buffer. */
131
133
134 /* Used to detect when the input file stack has changed since last
135 described. */
136 const line_map_ordinary *m_last_module;
137
138 /* Include files that report_current_module has already listed the
139 include path for. */
141
143
144 /* If true, this is the initial default text output format created
145 when the diagnostic_context was created, and, in particular, before
146 initializations of color and m_url_format. Hence this should follow
147 the dc's reference printer for these.
148 If false, this text output was created after the dc was created, and
149 thus tracks its own values for color and m_url_format. */
151
152 /* If true, then use indentation to show the nesting structure of
153 nested diagnostics, and print locations on separate lines after the
154 diagnostic message, rather than as a prefix to the message. */
156
157 /* Set to false to suppress location-printing when showing nested
158 diagnostics, for use in DejaGnu tests. */
160
161 /* If true, then add "(level N):" when printing nested diagnostics. */
163};
164
165#endif /* ! GCC_DIAGNOSTIC_FORMAT_TEXT_H */
Definition diagnostic.h:358
Definition diagnostic.h:506
bool m_show_column
Definition diagnostic.h:832
Definition diagnostic-diagram.h:33
Definition diagnostic.h:382
Definition diagnostic-format.h:33
diagnostic_context & get_context() const
Definition diagnostic-format.h:71
void DEBUG_FUNCTION dump() const
Definition diagnostic-format.h:79
Definition diagnostic-path.h:188
Definition diagnostic-buffer.h:96
Definition diagnostic-format-text.h:33
void report_current_module(location_t where)
Definition diagnostic-format-text.cc:640
bool follows_reference_printer_p() const final override
Definition diagnostic-format-text.cc:441
const diagnostic_source_printing_options & get_source_printing_options() const
Definition diagnostic-format-text.h:116
label_text get_location_text(const expanded_location &s) const
Definition diagnostic-format-text.cc:607
bool m_follows_reference_printer
Definition diagnostic-format-text.h:150
void after_diagnostic(const diagnostic_info &) override
Definition diagnostic-format-text.cc:279
void on_begin_group() override
Definition diagnostic-format-text.h:58
void set_show_nesting(bool show_nesting)
Definition diagnostic-format-text.h:100
void print_any_cwe(const diagnostic_info &diagnostic)
Definition diagnostic-format-text.cc:473
char * build_prefix(const diagnostic_info &) const
Definition diagnostic-format-text.cc:294
void on_report_diagnostic(const diagnostic_info &, diagnostic_t orig_diag_kind) override
Definition diagnostic-format-text.cc:204
bool show_nesting_p() const
Definition diagnostic-format-text.h:94
diagnostic_source_printing_options & get_source_printing_options()
Definition diagnostic-format-text.h:112
char * build_indent_prefix(bool with_bullet) const
Definition diagnostic-format-text.cc:386
std::unique_ptr< diagnostic_per_format_buffer > make_per_format_buffer() final override
Definition diagnostic-format-text.cc:194
void print_option_information(const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind)
Definition diagnostic-format-text.cc:552
void set_show_nesting_levels(bool show_nesting_levels)
Definition diagnostic-format-text.h:105
bool m_show_nesting
Definition diagnostic-format-text.h:155
bool machine_readable_stderr_p() const final override
Definition diagnostic-format-text.h:65
void on_report_verbatim(text_info &) final override
Definition diagnostic-format-text.cc:255
bool show_column_p() const
Definition diagnostic-format-text.h:86
output_buffer * m_saved_output_buffer
Definition diagnostic-format-text.h:130
diagnostic_column_policy m_column_policy
Definition diagnostic-format-text.h:132
void print_path(const diagnostic_path &path)
Definition diagnostic-path.cc:1145
diagnostic_text_output_format(diagnostic_context &context, diagnostic_source_printing_options *source_printing=nullptr, bool follows_reference_printer=false)
Definition diagnostic-format-text.h:35
hash_set< location_t, false, location_hash > * m_includes_seen
Definition diagnostic-format-text.h:140
bool m_show_locations_in_nesting
Definition diagnostic-format-text.h:159
void on_end_group() override
Definition diagnostic-format-text.h:59
void char * file_name_as_prefix(const char *) const
Definition diagnostic-format-text.cc:334
void print_any_rules(const diagnostic_info &diagnostic)
Definition diagnostic-format-text.cc:509
bool m_show_nesting_levels
Definition diagnostic-format-text.h:162
diagnostic_source_printing_options & m_source_printing
Definition diagnostic-format-text.h:142
void append_note(location_t location, const char *gmsgid,...) ATTRIBUTE_GCC_DIAG(3
Definition diagnostic-format-text.cc:411
diagnostic_location_print_policy get_location_print_policy() const
const diagnostic_column_policy & get_column_policy() const
Definition diagnostic-format-text.h:88
void set_buffer(diagnostic_per_format_buffer *) final override
Definition diagnostic-format-text.cc:174
void update_printer() override
Definition diagnostic-format-text.cc:448
const line_map_ordinary * m_last_module
Definition diagnostic-format-text.h:136
bool show_locations_in_nesting_p() const
Definition diagnostic-format-text.h:95
~diagnostic_text_output_format()
Definition diagnostic-format-text.cc:132
void set_show_locations_in_nesting(bool val)
Definition diagnostic-format-text.h:101
bool includes_seen_p(const line_map_ordinary *map)
Definition diagnostic-format-text.cc:583
void on_diagram(const diagnostic_diagram &diagram) override
Definition diagnostic-format-text.cc:262
Definition hash-set.h:37
Definition pretty-print.h:84
static struct string2counter_map map[debug_counter_number_of_counters]
Definition dbgcnt.cc:39
diagnostic_t
Definition diagnostic-core.h:29
#define ATTRIBUTE_GCC_DIAG(m, n)
Definition diagnostic-core.h:100
void final(rtx_insn *first, FILE *file, int optimize_p)
Definition final.cc:2008
Definition diagnostic.h:137
Definition diagnostic.h:308
Definition libgdiagnostics.cc:824
Definition pretty-print.h:34
#define false
Definition system.h:888