GCC Middle and Back End API Reference
diagnostic_text_output_format Class Reference

#include <diagnostic-format-text.h>

Inheritance diagram for diagnostic_text_output_format:
Collaboration diagram for diagnostic_text_output_format:

Public Member Functions

 diagnostic_text_output_format (diagnostic_context &context, diagnostic_source_printing_options *source_printing=nullptr, bool follows_reference_printer=false)
 
 ~diagnostic_text_output_format ()
 
void dump (FILE *out, int indent) const override
 
std::unique_ptr< diagnostic_per_format_buffermake_per_format_buffer () final override
 
void set_buffer (diagnostic_per_format_buffer *) final override
 
void on_begin_group () override
 
void on_end_group () override
 
void on_report_diagnostic (const diagnostic_info &, diagnostic_t orig_diag_kind) override
 
void on_report_verbatim (text_info &) final override
 
void on_diagram (const diagnostic_diagram &diagram) override
 
void after_diagnostic (const diagnostic_info &) override
 
bool machine_readable_stderr_p () const final override
 
bool follows_reference_printer_p () const final override
 
void update_printer () override
 
char * build_prefix (const diagnostic_info &) const
 
void report_current_module (location_t where)
 
void append_note (location_t location, const char *gmsgid,...) ATTRIBUTE_GCC_DIAG(3
 
void char * file_name_as_prefix (const char *) const
 
char * build_indent_prefix (bool with_bullet) const
 
void print_path (const diagnostic_path &path)
 
bool show_column_p () const
 
const diagnostic_column_policyget_column_policy () const
 
diagnostic_location_print_policy get_location_print_policy () const
 
bool show_nesting_p () const
 
bool show_locations_in_nesting_p () const
 
void set_show_nesting (bool show_nesting)
 
void set_show_locations_in_nesting (bool val)
 
void set_show_nesting_levels (bool show_nesting_levels)
 
label_text get_location_text (const expanded_location &s) const
 
diagnostic_source_printing_optionsget_source_printing_options ()
 
const diagnostic_source_printing_optionsget_source_printing_options () const
 
void DEBUG_FUNCTION dump () const
 
diagnostic_contextget_context () const
 
pretty_printerget_printer () const
 
text_art::theme * get_diagram_theme () const
 

Protected Member Functions

void print_any_cwe (const diagnostic_info &diagnostic)
 
void print_any_rules (const diagnostic_info &diagnostic)
 
void print_option_information (const diagnostic_info &diagnostic, diagnostic_t orig_diag_kind)
 
bool includes_seen_p (const line_map_ordinary *map)
 

Protected Attributes

output_bufferm_saved_output_buffer
 
diagnostic_column_policy m_column_policy
 
const line_map_ordinary * m_last_module
 
hash_set< location_t, false, location_hash > * m_includes_seen
 
diagnostic_source_printing_optionsm_source_printing
 
bool m_follows_reference_printer
 
bool m_show_nesting
 
bool m_show_locations_in_nesting
 
bool m_show_nesting_levels
 
diagnostic_contextm_context
 
std::unique_ptr< pretty_printerm_printer
 

Detailed Description

Classic text-based output of diagnostics.
   Copyright (C) 2023-2025 Free Software Foundation, Inc.
   Contributed by David Malcolm <dmalcolm@redhat.com>.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
Subclass of diagnostic_output_format for classic text-based output
to stderr.

Uses diagnostic_context.m_text_callbacks to provide client-specific
textual output (e.g. include paths, macro expansions, etc).   

Constructor & Destructor Documentation

◆ diagnostic_text_output_format()

diagnostic_text_output_format::diagnostic_text_output_format ( diagnostic_context & context,
diagnostic_source_printing_options * source_printing = nullptr,
bool follows_reference_printer = false )
inline

◆ ~diagnostic_text_output_format()

diagnostic_text_output_format::~diagnostic_text_output_format ( )
class diagnostic_text_output_format : public diagnostic_output_format.   

References _, diagnostic_output_format::get_printer(), diagnostic_output_format::m_context, m_includes_seen, pp_newline_and_flush(), pp_verbatim(), and progname.

Member Function Documentation

◆ after_diagnostic()

void diagnostic_text_output_format::after_diagnostic ( const diagnostic_info & diagnostic)
overridevirtual

Implements diagnostic_output_format.

References path, and print_path().

◆ append_note()

◆ build_indent_prefix()

char * diagnostic_text_output_format::build_indent_prefix ( bool with_bullet) const
Return a malloc'd string for use as a prefix to show indentation.
If m_show_nesting is false, or we're at the top-level, then the
result will be the empty string.

If m_show_nesting, then the result will contain indentation to show
the nesting level, then either a bullet point (if WITH_BULLET is true),
or a space.

The caller is responsible for freeing the memory.   

References get_bullet_point_unichar(), diagnostic_output_format::get_context(), i, m_show_nesting, m_show_nesting_levels, pp_formatted_text(), pp_printf(), pp_space, pp_string(), and pp_unicode_character().

Referenced by build_prefix(), and on_report_diagnostic().

◆ build_prefix()

char * diagnostic_text_output_format::build_prefix ( const diagnostic_info & diagnostic) const
Return a malloc'd string describing a location and the severity of the
diagnostic, e.g. "foo.c:42:10: error: ".

If m_show_nesting, then the above will be preceded by indentation to show
the level, and a bullet point.

The caller is responsible for freeing the memory.   

References _, build_indent_prefix(), build_message_string(), colorize_start(), colorize_stop(), diagnostic_expand_location(), diagnostic_get_color_for_kind(), DK_LAST_DIAGNOSTIC_KIND, free(), gcc_assert, diagnostic_output_format::get_context(), get_diagnostic_kind_text(), get_location_text(), diagnostic_output_format::get_printer(), m_show_nesting, and pp_show_color().

Referenced by append_note(), default_diagnostic_text_starter(), default_tree_diagnostic_text_starter(), and diagnostic_text_sink::text_starter().

◆ dump() [1/2]

void DEBUG_FUNCTION diagnostic_output_format::dump ( ) const
inlineinherited

◆ dump() [2/2]

void diagnostic_text_output_format::dump ( FILE * out,
int indent ) const
overridevirtual

◆ file_name_as_prefix()

char * diagnostic_text_output_format::file_name_as_prefix ( const char * f) const
Same as build_prefix, but only the source FILE is given.   

References build_message_string(), colorize_start(), colorize_stop(), diagnostic_output_format::get_printer(), and pp_show_color().

Referenced by lhd_print_error_function().

◆ follows_reference_printer_p()

bool diagnostic_text_output_format::follows_reference_printer_p ( ) const
finaloverridevirtual

◆ get_column_policy()

const diagnostic_column_policy & diagnostic_text_output_format::get_column_policy ( ) const
inline

References m_column_policy.

Referenced by report_current_module().

◆ get_context()

◆ get_diagram_theme()

text_art::theme * diagnostic_output_format::get_diagram_theme ( ) const
inlineinherited

References m_context.

◆ get_location_print_policy()

diagnostic_location_print_policy diagnostic_text_output_format::get_location_print_policy ( ) const

◆ get_location_text()

◆ get_printer()

◆ get_source_printing_options() [1/2]

diagnostic_source_printing_options & diagnostic_text_output_format::get_source_printing_options ( )
inline

◆ get_source_printing_options() [2/2]

const diagnostic_source_printing_options & diagnostic_text_output_format::get_source_printing_options ( ) const
inline

References m_source_printing.

◆ includes_seen_p()

bool diagnostic_text_output_format::includes_seen_p ( const line_map_ordinary * map)
protected
Only dump the "In file included from..." stack once for each file.   

References line_table, m_includes_seen, and map.

Referenced by report_current_module().

◆ machine_readable_stderr_p()

bool diagnostic_text_output_format::machine_readable_stderr_p ( ) const
inlinefinaloverridevirtual

Implements diagnostic_output_format.

References final().

◆ make_per_format_buffer()

std::unique_ptr< diagnostic_per_format_buffer > diagnostic_text_output_format::make_per_format_buffer ( )
finaloverridevirtual

◆ on_begin_group()

void diagnostic_text_output_format::on_begin_group ( )
inlineoverridevirtual

Implements diagnostic_output_format.

References on_begin_group().

Referenced by on_begin_group().

◆ on_diagram()

void diagnostic_text_output_format::on_diagram ( const diagnostic_diagram & diagram)
overridevirtual

◆ on_end_group()

void diagnostic_text_output_format::on_end_group ( )
inlineoverridevirtual

◆ on_report_diagnostic()

◆ on_report_verbatim()

void diagnostic_text_output_format::on_report_verbatim ( text_info & text)
finaloverridevirtual

◆ print_any_cwe()

void diagnostic_text_output_format::print_any_cwe ( const diagnostic_info & diagnostic)
protected
If DIAGNOSTIC has a CWE identifier, print it.

For example, if the diagnostic metadata associates it with CWE-119,
" [CWE-119]" will be printed, suitably colorized, and with a URL of a
description of the security issue.   

References colorize_start(), colorize_stop(), diagnostic_get_color_for_kind(), free(), get_cwe_url(), diagnostic_output_format::get_printer(), NULL, pp_begin_url(), pp_character(), pp_end_url(), pp_printf(), pp_set_prefix(), pp_show_color(), pp_string(), pp_take_prefix(), and pretty_printer::supports_urls_p().

Referenced by on_report_diagnostic().

◆ print_any_rules()

void diagnostic_text_output_format::print_any_rules ( const diagnostic_info & diagnostic)
protected
If DIAGNOSTIC has any rules associated with it, print them.

For example, if the diagnostic metadata associates it with a rule
named "STR34-C", then " [STR34-C]" will be printed, suitably colorized,
with any URL provided by the rule.   

References colorize_start(), colorize_stop(), diagnostic_get_color_for_kind(), free(), diagnostic_output_format::get_printer(), diagnostic_metadata::rule::make_description(), diagnostic_metadata::rule::make_url(), NULL, pp_begin_url(), pp_character(), pp_end_url(), pp_set_prefix(), pp_show_color(), pp_string(), pp_take_prefix(), and pretty_printer::supports_urls_p().

Referenced by on_report_diagnostic().

◆ print_option_information()

void diagnostic_text_output_format::print_option_information ( const diagnostic_info & diagnostic,
diagnostic_t orig_diag_kind )
protected
Print any metadata about the option used to control DIAGNOSTIC to CONTEXT's
printer, e.g. " [-Werror=uninitialized]".
Subroutine of diagnostic_context::report_diagnostic.   

References colorize_start(), colorize_stop(), diagnostic_get_color_for_kind(), free(), diagnostic_output_format::get_printer(), diagnostic_output_format::m_context, pp_begin_url(), pp_character(), pp_end_url(), pp_show_color(), pp_string(), and pretty_printer::supports_urls_p().

Referenced by on_report_diagnostic().

◆ print_path()

void diagnostic_text_output_format::print_path ( const diagnostic_path & path)

◆ report_current_module()

◆ set_buffer()

◆ set_show_locations_in_nesting()

void diagnostic_text_output_format::set_show_locations_in_nesting ( bool val)
inline

◆ set_show_nesting()

void diagnostic_text_output_format::set_show_nesting ( bool show_nesting)
inline

References m_show_nesting.

◆ set_show_nesting_levels()

void diagnostic_text_output_format::set_show_nesting_levels ( bool show_nesting_levels)
inline

References m_show_nesting_levels.

◆ show_column_p()

bool diagnostic_text_output_format::show_column_p ( ) const
inline

◆ show_locations_in_nesting_p()

bool diagnostic_text_output_format::show_locations_in_nesting_p ( ) const
inline

◆ show_nesting_p()

bool diagnostic_text_output_format::show_nesting_p ( ) const
inline

References m_show_nesting.

◆ update_printer()

Field Documentation

◆ m_column_policy

diagnostic_column_policy diagnostic_text_output_format::m_column_policy
protected

◆ m_context

◆ m_follows_reference_printer

bool diagnostic_text_output_format::m_follows_reference_printer
protected

◆ m_includes_seen

hash_set<location_t, false, location_hash>* diagnostic_text_output_format::m_includes_seen
protected

◆ m_last_module

const line_map_ordinary* diagnostic_text_output_format::m_last_module
protected

◆ m_printer

◆ m_saved_output_buffer

output_buffer* diagnostic_text_output_format::m_saved_output_buffer
protected

◆ m_show_locations_in_nesting

bool diagnostic_text_output_format::m_show_locations_in_nesting
protected

◆ m_show_nesting

bool diagnostic_text_output_format::m_show_nesting
protected

◆ m_show_nesting_levels

bool diagnostic_text_output_format::m_show_nesting_levels
protected

◆ m_source_printing


The documentation for this class was generated from the following files: