Fortran: Fix PR 47485.
[official-gcc.git] / gcc / diagnostic-format-text.h
blob64f8e13ebe955500df13b6d2ba8e29270d22c8cc
1 /* Classic text-based output of diagnostics.
2 Copyright (C) 2023-2025 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
10 version.
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.
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
27 to stderr.
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
34 public:
35 diagnostic_text_output_format (diagnostic_context &context,
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),
47 m_show_nesting (false),
48 m_show_nesting_levels (false)
50 ~diagnostic_text_output_format ();
52 void dump (FILE *out, int indent) const override;
54 std::unique_ptr<diagnostic_per_format_buffer>
55 make_per_format_buffer () final override;
56 void set_buffer (diagnostic_per_format_buffer *) final override;
58 void on_begin_group () override {}
59 void on_end_group () override {}
60 void on_report_diagnostic (const diagnostic_info &,
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
67 return false;
69 bool follows_reference_printer_p () const final override;
71 void update_printer () override;
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);
80 char *file_name_as_prefix (const char *) const;
82 char *build_indent_prefix (bool with_bullet) const;
84 void print_path (const diagnostic_path &path);
86 bool show_column_p () const { return get_context ().m_show_column; }
88 const diagnostic_column_policy &get_column_policy () const
90 return m_column_policy;
92 diagnostic_location_print_policy get_location_print_policy () const;
94 bool show_nesting_p () const { return m_show_nesting; }
95 bool show_locations_in_nesting_p () const
97 return m_show_locations_in_nesting;
100 void set_show_nesting (bool show_nesting) { m_show_nesting = show_nesting; }
101 void set_show_locations_in_nesting (bool val)
103 m_show_locations_in_nesting = val;
105 void set_show_nesting_levels (bool show_nesting_levels)
107 m_show_nesting_levels = show_nesting_levels;
110 label_text get_location_text (const expanded_location &s) const;
112 diagnostic_source_printing_options &get_source_printing_options ()
114 return m_source_printing;
116 const diagnostic_source_printing_options &get_source_printing_options () const
118 return m_source_printing;
121 protected:
122 void print_any_cwe (const diagnostic_info &diagnostic);
123 void print_any_rules (const diagnostic_info &diagnostic);
124 void print_option_information (const diagnostic_info &diagnostic,
125 diagnostic_t orig_diag_kind);
127 bool includes_seen_p (const line_map_ordinary *map);
129 /* For handling diagnostic_buffer. */
130 output_buffer *m_saved_output_buffer;
132 diagnostic_column_policy m_column_policy;
134 /* Used to detect when the input file stack has changed since last
135 described. */
136 const line_map_ordinary *m_last_module;
138 /* Include files that report_current_module has already listed the
139 include path for. */
140 hash_set<location_t, false, location_hash> *m_includes_seen;
142 diagnostic_source_printing_options &m_source_printing;
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. */
150 bool m_follows_reference_printer;
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. */
155 bool m_show_nesting;
157 /* Set to false to suppress location-printing when showing nested
158 diagnostics, for use in DejaGnu tests. */
159 bool m_show_locations_in_nesting;
161 /* If true, then add "(level N):" when printing nested diagnostics. */
162 bool m_show_nesting_levels;
165 #endif /* ! GCC_DIAGNOSTIC_FORMAT_TEXT_H */