libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / diagnostic-format-text.h
blob2e57e27c739d3064a76dc0c46c48ad4c7b6b868d
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
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_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
50 return false;
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;
72 private:
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
84 described. */
85 const line_map_ordinary *m_last_module;
87 /* Include files that report_current_module has already listed the
88 include path for. */
89 hash_set<location_t, false, location_hash> *m_includes_seen;
92 #endif /* ! GCC_DIAGNOSTIC_FORMAT_TEXT_H */