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, 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
 
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
 
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-2024 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,
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 _, 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 print_path().

◆ append_note()

void diagnostic_text_output_format::append_note ( location_t location,
const char * gmsgid,
... )

◆ 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(), i, pp_formatted_text(), pp_printf(), pp_space, pp_string(), and pp_unicode_character().

◆ 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_message_string(), colorize_start(), colorize_stop(), diagnostic_expand_location(), diagnostic_get_color_for_kind(), DK_LAST_DIAGNOSTIC_KIND, free(), gcc_assert, get_diagnostic_kind_text(), and pp_show_color().

Referenced by default_diagnostic_text_starter(), default_tree_diagnostic_text_starter(), and diagnostic_text_sink::on_begin_text_diagnostic().

◆ dump() [1/2]

◆ 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(), 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.

◆ get_context()

◆ get_diagram_theme()

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

◆ get_location_print_policy()

diagnostic_location_print_policy diagnostic_text_output_format::get_location_print_policy ( ) const

◆ get_location_text()

label_text diagnostic_text_output_format::get_location_text ( const expanded_location & s) const

◆ get_printer()

◆ 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 hash_set< KeyId, Lazy, Traits >::add(), line_table, and map.

◆ machine_readable_stderr_p()

bool diagnostic_text_output_format::machine_readable_stderr_p ( ) const
inlinefinaloverridevirtual

◆ 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

◆ 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()

void diagnostic_text_output_format::on_report_diagnostic ( const diagnostic_info & diagnostic,
diagnostic_t orig_diag_kind )
overridevirtual
Implementation of diagnostic_output_format::on_report_diagnostic vfunc
for GCC's standard textual output.   

Implements diagnostic_output_format.

References BUILTINS_LOCATION, diagnostic_expand_location(), diagnostic_location(), diagnostic_text_finalizer(), diagnostic_text_starter(), pp_newline(), pp_output_formatted_text(), pp_printf(), and pp_set_prefix().

◆ 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(), 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().

◆ 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_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().

◆ 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(), pp_begin_url(), pp_character(), pp_end_url(), pp_show_color(), pp_string(), and pretty_printer::supports_urls_p().

◆ print_path()

void diagnostic_text_output_format::print_path ( const diagnostic_path & path)
Print PATH according to the context's path_format.   

References DPF_INLINE_EVENTS, DPF_NONE, DPF_SEPARATE_EVENTS, i, inform(), NULL, pp_flush(), pp_set_prefix(), pp_show_color(), and pp_take_prefix().

◆ report_current_module()

void diagnostic_text_output_format::report_current_module ( location_t where)

◆ set_buffer()

void diagnostic_text_output_format::set_buffer ( diagnostic_per_format_buffer * base)
finaloverridevirtual

◆ 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()

void diagnostic_text_output_format::update_printer ( )
overridevirtual

Field Documentation

◆ m_column_policy

diagnostic_column_policy diagnostic_text_output_format::m_column_policy
protected

Referenced by get_column_policy().

◆ 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

std::unique_ptr<pretty_printer> diagnostic_output_format::m_printer
protectedinherited

◆ 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

Referenced by set_show_nesting(), and show_nesting_p().

◆ m_show_nesting_levels

bool diagnostic_text_output_format::m_show_nesting_levels
protected

Referenced by set_show_nesting_levels().


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