GCC Middle and Back End API Reference
diagnostics::text_sink Class Reference

#include <text-sink.h>

Inheritance diagram for diagnostics::text_sink:
Collaboration diagram for diagnostics::text_sink:

Public Member Functions

 text_sink (context &dc, source_printing_options *source_printing=nullptr, bool follows_reference_printer=false)
 ~text_sink ()
text_sinkdyn_cast_text_sink () final override
void dump_kind (FILE *out) const override
void dump (FILE *out, int indent) const override
std::unique_ptr< per_sink_buffermake_per_sink_buffer () final override
void set_buffer (per_sink_buffer *) final override
void on_begin_group () override
void on_end_group () override
void on_report_diagnostic (const diagnostic_info &, enum kind orig_diag_kind) override
void on_report_verbatim (text_info &) final override
void on_diagram (const diagram &d) 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
void report_global_digraph (const lazily_created< digraphs::digraph > &) final 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 paths::path &path)
bool show_column_p () const
const column_policyget_column_policy () const
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
source_printing_optionsget_source_printing_options ()
const source_printing_optionsget_source_printing_options () const
void DEBUG_FUNCTION dump () const
virtual void set_main_input_filename (const char *)
contextget_context () const
pretty_printerget_printer () const
text_art::themeget_diagram_theme () const
logging::loggerget_logger ()

Static Public Member Functions

static const char * maybe_line_and_column (int line, int col)

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, enum kind orig_diag_kind)
bool includes_seen_p (const line_map_ordinary *map)

Protected Attributes

output_bufferm_saved_output_buffer
column_policy m_column_policy
const line_map_ordinary * m_last_module
hash_set< location_t, false, location_hash > * m_includes_seen
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
contextm_context
std::unique_ptr< pretty_printerm_printer

Detailed Description

Subclass of diagnostics::sink for classic text-based output
to stderr.

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

Constructor & Destructor Documentation

◆ text_sink()

◆ ~text_sink()

diagnostics::text_sink::~text_sink ( )
class diagnostics::text_sink : public diagnostics::sink.   

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

Member Function Documentation

◆ after_diagnostic()

void diagnostics::text_sink::after_diagnostic ( const diagnostic_info & diagnostic)
overridevirtual

Implements diagnostics::sink.

References path, and print_path().

◆ append_note()

◆ build_indent_prefix()

char * diagnostics::text_sink::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 diagnostics::get_bullet_point_unichar(), diagnostics::sink::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 * diagnostics::text_sink::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(), free(), gcc_assert, diagnostics::get_color_for_kind(), diagnostics::sink::get_context(), get_location_text(), diagnostics::get_printer(), diagnostics::get_text_for_kind(), diagnostics::last_diagnostic_kind, m_show_nesting, and pp_show_color().

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

◆ dump() [1/2]

void DEBUG_FUNCTION diagnostics::sink::dump ( ) const
inlineinherited

◆ dump() [2/2]

◆ dump_kind()

void diagnostics::text_sink::dump_kind ( FILE * out) const
inlineoverridevirtual

Implements diagnostics::sink.

◆ dyn_cast_text_sink()

text_sink * diagnostics::text_sink::dyn_cast_text_sink ( )
inlinefinaloverridevirtual

Reimplemented from diagnostics::sink.

References final(), and text_sink().

◆ file_name_as_prefix()

char * diagnostics::text_sink::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(), diagnostics::get_printer(), and pp_show_color().

Referenced by lhd_print_error_function().

◆ follows_reference_printer_p()

bool diagnostics::text_sink::follows_reference_printer_p ( ) const
finaloverridevirtual

◆ get_column_policy()

const column_policy & diagnostics::text_sink::get_column_policy ( ) const
inline

References m_column_policy.

Referenced by report_current_module().

◆ get_context()

◆ get_diagram_theme()

text_art::theme * diagnostics::sink::get_diagram_theme ( ) const
inlineinherited

References m_context.

◆ get_location_print_policy()

location_print_policy diagnostics::text_sink::get_location_print_policy ( ) const

◆ get_location_text()

◆ get_logger()

◆ get_printer()

◆ get_source_printing_options() [1/2]

source_printing_options & diagnostics::text_sink::get_source_printing_options ( )
inline

◆ get_source_printing_options() [2/2]

const source_printing_options & diagnostics::text_sink::get_source_printing_options ( ) const
inline

References m_source_printing.

◆ includes_seen_p()

bool diagnostics::text_sink::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 diagnostics::text_sink::machine_readable_stderr_p ( ) const
inlinefinaloverridevirtual

Implements diagnostics::sink.

References final().

◆ make_per_sink_buffer()

std::unique_ptr< per_sink_buffer > diagnostics::text_sink::make_per_sink_buffer ( )
finaloverridevirtual

Implements diagnostics::sink.

◆ maybe_line_and_column()

const char * diagnostics::text_sink::maybe_line_and_column ( int line,
int col )
static
Helpers for writing lang-specific starters/finalizers for text output.   
Return a formatted line and column ':%line:%column'.  Elided if
line == 0 or col < 0.  (A column of 0 may be valid due to the
-fdiagnostics-column-origin option.)
The result is a statically allocated buffer.   

References gcc_checking_assert.

Referenced by diagnostics::column_policy::get_location_text(), and report_current_module().

◆ on_begin_group()

void diagnostics::text_sink::on_begin_group ( )
inlineoverridevirtual

Implements diagnostics::sink.

References on_begin_group().

Referenced by on_begin_group().

◆ on_diagram()

void diagnostics::text_sink::on_diagram ( const diagram & d)
overridevirtual

◆ on_end_group()

void diagnostics::text_sink::on_end_group ( )
inlineoverridevirtual

Implements diagnostics::sink.

◆ on_report_diagnostic()

◆ on_report_verbatim()

void diagnostics::text_sink::on_report_verbatim ( text_info & text)
finaloverridevirtual

◆ print_any_cwe()

void diagnostics::text_sink::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(), free(), diagnostics::get_color_for_kind(), diagnostics::metadata::get_cwe(), diagnostics::get_cwe_url(), diagnostics::get_printer(), diagnostic::m_metadata, 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 diagnostics::text_sink::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(), free(), diagnostics::get_color_for_kind(), diagnostics::metadata::get_num_rules(), diagnostics::get_printer(), diagnostics::metadata::get_rule(), diagnostic::m_metadata, diagnostics::metadata::rule::make_description(), diagnostics::metadata::rule::make_url(), 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 diagnostics::text_sink::print_option_information ( const diagnostic_info & diagnostic,
enum kind orig_diag_kind )
protected
Print any metadata about the option used to control DIAGNOSTIC to
the context's printer, e.g. " [-Werror=uninitialized]".   

References colorize_start(), colorize_stop(), free(), diagnostics::get_color_for_kind(), diagnostics::get_printer(), diagnostics::sink::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()

◆ report_current_module()

◆ report_global_digraph()

void diagnostics::text_sink::report_global_digraph ( const lazily_created< digraphs::digraph > & )
inlinefinaloverridevirtual

Implements diagnostics::sink.

References final(), and report_global_digraph().

Referenced by report_global_digraph().

◆ set_buffer()

void diagnostics::text_sink::set_buffer ( per_sink_buffer * base)
finaloverridevirtual

◆ set_main_input_filename()

virtual void diagnostics::sink::set_main_input_filename ( const char * )
inlinevirtualinherited

◆ set_show_locations_in_nesting()

void diagnostics::text_sink::set_show_locations_in_nesting ( bool val)
inline

◆ set_show_nesting()

void diagnostics::text_sink::set_show_nesting ( bool show_nesting)
inline

References m_show_nesting.

◆ set_show_nesting_levels()

void diagnostics::text_sink::set_show_nesting_levels ( bool show_nesting_levels)
inline

References m_show_nesting_levels.

◆ show_column_p()

bool diagnostics::text_sink::show_column_p ( ) const
inline

◆ show_locations_in_nesting_p()

bool diagnostics::text_sink::show_locations_in_nesting_p ( ) const
inline

◆ show_nesting_p()

bool diagnostics::text_sink::show_nesting_p ( ) const
inline

References m_show_nesting.

◆ update_printer()

Field Documentation

◆ m_column_policy

column_policy diagnostics::text_sink::m_column_policy
protected

Referenced by get_column_policy(), and text_sink().

◆ m_context

◆ m_follows_reference_printer

bool diagnostics::text_sink::m_follows_reference_printer
protected

◆ m_includes_seen

hash_set<location_t, false, location_hash>* diagnostics::text_sink::m_includes_seen
protected

◆ m_last_module

const line_map_ordinary* diagnostics::text_sink::m_last_module
protected

Referenced by report_current_module(), and text_sink().

◆ m_printer

◆ m_saved_output_buffer

output_buffer* diagnostics::text_sink::m_saved_output_buffer
protected

Referenced by dump(), set_buffer(), and text_sink().

◆ m_show_locations_in_nesting

bool diagnostics::text_sink::m_show_locations_in_nesting
protected

◆ m_show_nesting

bool diagnostics::text_sink::m_show_nesting
protected

◆ m_show_nesting_levels

bool diagnostics::text_sink::m_show_nesting_levels
protected

◆ m_source_printing

source_printing_options& diagnostics::text_sink::m_source_printing
protected

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