GCC Middle and Back End API Reference
pretty_printer Class Reference

#include <pretty-print.h>

Inheritance diagram for pretty_printer:
Collaboration diagram for pretty_printer:

Public Member Functions

 pretty_printer (int=0)
 
 pretty_printer (const pretty_printer &other)
 
virtual ~pretty_printer ()
 
virtual std::unique_ptr< pretty_printerclone () const
 
void set_output_stream (FILE *outfile)
 
void set_token_printer (token_printer *tp)
 
void set_prefix (char *prefix)
 
void emit_prefix ()
 
void format (text_info &text)
 
void maybe_space ()
 
bool supports_urls_p () const
 
diagnostic_url_format get_url_format () const
 
void set_url_format (diagnostic_url_format url_format)
 
void begin_url (const char *url)
 
void end_url ()
 
pp_wrapping_mode_t set_verbatim_wrapping ()
 
void set_padding (pp_padding padding)
 
pp_padding get_padding () const
 
void clear_state ()
 
void set_real_maximum_length ()
 
int remaining_character_count_for_line ()
 
void dump (FILE *out, int indent) const
 
void DEBUG_FUNCTION dump () const
 

Private Attributes

output_bufferm_buffer
 
char * m_prefix
 
pp_padding m_padding
 
int m_maximum_length
 
int m_indent_skip
 
pp_wrapping_mode_t m_wrapping
 
printer_fn m_format_decoder
 
format_postprocessorm_format_postprocessor
 
token_printerm_token_printer
 
bool m_emitted_prefix
 
bool m_need_newline
 
bool m_translate_identifiers
 
bool m_show_color
 
bool m_show_highlight_colors
 
diagnostic_url_format m_url_format
 
bool m_skipping_null_url
 

Friends

output_buffer *& pp_buffer (pretty_printer *pp)
 
output_bufferpp_buffer (const pretty_printer *pp)
 
const char * pp_get_prefix (const pretty_printer *pp)
 
char * pp_take_prefix (pretty_printer *pp)
 
void pp_destroy_prefix (pretty_printer *pp)
 
int & pp_line_cutoff (pretty_printer *pp)
 
diagnostic_prefixing_rule_tpp_prefixing_rule (pretty_printer *pp)
 
const diagnostic_prefixing_rule_tpp_prefixing_rule (const pretty_printer *pp)
 
pp_wrapping_mode_tpp_wrapping_mode (pretty_printer *pp)
 
boolpp_needs_newline (pretty_printer *pp)
 
int & pp_indentation (pretty_printer *pp)
 
boolpp_translate_identifiers (pretty_printer *pp)
 
boolpp_show_color (pretty_printer *pp)
 
printer_fnpp_format_decoder (pretty_printer *pp)
 
format_postprocessor *& pp_format_postprocessor (pretty_printer *pp)
 
boolpp_show_highlight_colors (pretty_printer *pp)
 
void pp_output_formatted_text (pretty_printer *pp, const urlifier *urlifier=nullptr)
 

Detailed Description

The data structure that contains the bare minimum required to do
proper pretty-printing.  Clients may derive from this structure
and add additional fields they need.   

Constructor & Destructor Documentation

◆ pretty_printer() [1/2]

pretty_printer::pretty_printer ( int maximum_length = 0)
explicit
Construct a PRETTY-PRINTER of MAXIMUM_LENGTH characters per line.   

References DIAGNOSTICS_SHOW_PREFIX_ONCE, NULL, pp_line_cutoff, pp_prefixing_rule, and pp_set_prefix().

◆ pretty_printer() [2/2]

pretty_printer::pretty_printer ( const pretty_printer & other)
explicit

◆ ~pretty_printer()

pretty_printer::~pretty_printer ( )
virtual

Member Function Documentation

◆ begin_url()

void pretty_printer::begin_url ( const char * url)
Support for encoding URLs.
See egmontkob/Hyperlinks_in_Terminal_Emulators.md
( https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda ).

> A hyperlink is opened upon encountering an OSC 8 escape sequence with
> the target URI. The syntax is
>
>  OSC 8 ; params ; URI ST
>
> A hyperlink is closed with the same escape sequence, omitting the
> parameters and the URI but keeping the separators:
>
> OSC 8 ; ; ST
>
> OSC (operating system command) is typically ESC ].

Use BEL instead of ST, as that is currently rendered better in some
terminal emulators that don't support OSC 8, like konsole.   
If URL-printing is enabled, write an "open URL" escape sequence to PP
for the given URL.   

References gcc_unreachable, m_skipping_null_url, m_url_format, pp_string(), URL_FORMAT_BEL, URL_FORMAT_NONE, and URL_FORMAT_ST.

◆ clear_state()

void pretty_printer::clear_state ( )
inline
Clear this pretty_printer's output state.   

References m_emitted_prefix, and pp_indentation.

Referenced by format(), pp_flush(), and pp_really_flush().

◆ clone()

std::unique_ptr< pretty_printer > pretty_printer::clone ( ) const
virtual

◆ dump() [1/2]

void DEBUG_FUNCTION pretty_printer::dump ( ) const
inline

References dump().

Referenced by dump().

◆ dump() [2/2]

void pretty_printer::dump ( FILE * out,
int indent ) const
Dump state of this pretty_printer to OUT, for debugging.   

References output_buffer::dump(), gcc_unreachable, m_buffer, m_show_color, m_url_format, URL_FORMAT_BEL, URL_FORMAT_NONE, and URL_FORMAT_ST.

Referenced by diagnostic_context::dump().

◆ emit_prefix()

void pretty_printer::emit_prefix ( )

◆ end_url()

void pretty_printer::end_url ( )
If URL-printing is enabled, write a "close URL" escape sequence to PP.   

References get_end_url_string(), m_skipping_null_url, m_url_format, pp_string(), and URL_FORMAT_NONE.

◆ format()

◆ get_padding()

pp_padding pretty_printer::get_padding ( ) const
inline

References m_padding.

◆ get_url_format()

◆ maybe_space()

void pretty_printer::maybe_space ( )
Maybe print out a whitespace if needed.   

References m_padding, pp_none, and pp_space.

◆ remaining_character_count_for_line()

int pretty_printer::remaining_character_count_for_line ( )
Return the amount of characters PRETTY-PRINTER can accept to
make a full line.  Meaningful only in line-wrapping mode.   

References output_buffer::m_line_length, m_maximum_length, and pp_buffer.

Referenced by pp_character(), and pp_wrap_text().

◆ set_output_stream()

◆ set_padding()

void pretty_printer::set_padding ( pp_padding padding)
inline

References m_padding.

◆ set_prefix()

void pretty_printer::set_prefix ( char * prefix)
Set PREFIX for PRETTY-PRINTER, taking ownership of PREFIX, which
will eventually be free-ed.   

References free(), m_emitted_prefix, m_prefix, pp_indentation, and set_real_maximum_length().

Referenced by lhd_print_error_function().

◆ set_real_maximum_length()

void pretty_printer::set_real_maximum_length ( )
Subroutine of pp_set_maximum_length.  Set up PRETTY-PRINTER's
internal maximum characters per line.   

References DIAGNOSTICS_SHOW_PREFIX_NEVER, DIAGNOSTICS_SHOW_PREFIX_ONCE, m_maximum_length, m_prefix, pp_is_wrapping_line, pp_line_cutoff, and pp_prefixing_rule.

Referenced by pp_set_line_maximum_length(), and set_prefix().

◆ set_token_printer()

void pretty_printer::set_token_printer ( token_printer * tp)
inline

◆ set_url_format()

void pretty_printer::set_url_format ( diagnostic_url_format url_format)
inline

References m_url_format.

Referenced by diagnostic_context::urls_init().

◆ set_verbatim_wrapping()

pp_wrapping_mode_t pretty_printer::set_verbatim_wrapping ( )
inline

◆ supports_urls_p()

Friends And Related Symbol Documentation

◆ pp_buffer [1/2]

output_buffer * pp_buffer ( const pretty_printer * pp)
friend

◆ pp_buffer [2/2]

◆ pp_destroy_prefix

void pp_destroy_prefix ( pretty_printer * pp)
friend
Free PRETTY-PRINTER's prefix, a previously malloc()'d string.   

◆ pp_format_decoder

◆ pp_format_postprocessor

format_postprocessor *& pp_format_postprocessor ( pretty_printer * pp)
friend

◆ pp_get_prefix

const char * pp_get_prefix ( const pretty_printer * pp)
friend

◆ pp_indentation

int & pp_indentation ( pretty_printer * pp)
friend
The amount of whitespace to be emitted when starting a new line.   

Referenced by clear_state(), emit_prefix(), and set_prefix().

◆ pp_line_cutoff

int & pp_line_cutoff ( pretty_printer * pp)
friend
Maximum characters per line in automatic line wrapping mode.
Zero means don't wrap lines.   

Referenced by pretty_printer(), pretty_printer(), set_real_maximum_length(), and set_verbatim_wrapping().

◆ pp_needs_newline

bool & pp_needs_newline ( pretty_printer * pp)
friend
TRUE if a newline character needs to be added before further
formatting.   

◆ pp_output_formatted_text

void pp_output_formatted_text ( pretty_printer * pp,
const urlifier * urlifier = nullptr )
friend
Phase 3 of formatting a message (phases 1 and 2 done by pp_format).

Pop a pp_formatted_chunks from chunk_obstack, collecting all the tokens from
phases 1 and 2 of formatting, and writing into text in formatted_obstack.

If URLIFIER is non-null then use it on any quoted text that was not
handled in phases 1 or 2 to potentially add URLs.   

Referenced by dump_context::dump_printf_va().

◆ pp_prefixing_rule [1/2]

const diagnostic_prefixing_rule_t & pp_prefixing_rule ( const pretty_printer * pp)
friend

◆ pp_prefixing_rule [2/2]

diagnostic_prefixing_rule_t & pp_prefixing_rule ( pretty_printer * pp)
friend
Prefixing rule used in formatting a diagnostic message.   

Referenced by emit_prefix(), pretty_printer(), pretty_printer(), set_real_maximum_length(), and set_verbatim_wrapping().

◆ pp_show_color

bool & pp_show_color ( pretty_printer * pp)
friend

◆ pp_show_highlight_colors

bool & pp_show_highlight_colors ( pretty_printer * pp)
friend

◆ pp_take_prefix

char * pp_take_prefix ( pretty_printer * pp)
friend
Take ownership of PP's prefix, setting it to NULL.
This allows clients to save, override, and then restore an existing
prefix, without it being free-ed.   

◆ pp_translate_identifiers

bool & pp_translate_identifiers ( pretty_printer * pp)
friend
True if identifiers are translated to the locale character set on
output.   

◆ pp_wrapping_mode

pp_wrapping_mode_t & pp_wrapping_mode ( pretty_printer * pp)
friend
Get or set the wrapping mode as a single entity.   

Referenced by format(), and set_verbatim_wrapping().

Field Documentation

◆ m_buffer

output_buffer* pretty_printer::m_buffer
private

◆ m_emitted_prefix

bool pretty_printer::m_emitted_prefix
private

◆ m_format_decoder

printer_fn pretty_printer::m_format_decoder
private

◆ m_format_postprocessor

format_postprocessor* pretty_printer::m_format_postprocessor
private

◆ m_indent_skip

int pretty_printer::m_indent_skip
private

◆ m_maximum_length

int pretty_printer::m_maximum_length
private

◆ m_need_newline

bool pretty_printer::m_need_newline
private

◆ m_padding

pp_padding pretty_printer::m_padding
private

◆ m_prefix

char* pretty_printer::m_prefix
private

◆ m_show_color

bool pretty_printer::m_show_color
private

Referenced by dump().

◆ m_show_highlight_colors

bool pretty_printer::m_show_highlight_colors
private

◆ m_skipping_null_url

bool pretty_printer::m_skipping_null_url
private

Referenced by begin_url(), and end_url().

◆ m_token_printer

token_printer* pretty_printer::m_token_printer
private

Referenced by set_token_printer().

◆ m_translate_identifiers

bool pretty_printer::m_translate_identifiers
private

◆ m_url_format

diagnostic_url_format pretty_printer::m_url_format
private

◆ m_wrapping

pp_wrapping_mode_t pretty_printer::m_wrapping
private

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