GCC Middle and Back End API Reference
pretty-print.c File Reference
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "intl.h"
#include "pretty-print.h"
#include "diagnostic-color.h"
#include <new>
Include dependency graph for pretty-print.c:

Macros

#define pp_formatted_text_data(PP)   ((const char *) obstack_base (pp_buffer (PP)->obstack))
#define pp_integer_with_precision(PP, ARG, PREC, T, F)

Functions

static void pp_set_real_maximum_length ()
static void pp_clear_state ()
void pp_write_text_to_stream ()
void pp_write_text_as_dot_label_to_stream ()
static void pp_wrap_text ()
static void pp_maybe_wrap_text ()
static void pp_append_r ()
void pp_indent ()
void pp_format ()
void pp_output_formatted_text ()
void pp_format_verbatim ()
void pp_flush ()
void pp_set_line_maximum_length ()
void pp_clear_output_area ()
void pp_set_prefix ()
void pp_destroy_prefix ()
void pp_emit_prefix ()
void pp_append_text ()
const char * pp_formatted_text ()
const char * pp_last_position_in_text ()
int pp_remaining_character_count_for_line ()
void pp_printf ()
void pp_verbatim ()
void pp_newline ()
void pp_character ()
void pp_string ()
void pp_maybe_space ()
void pp_newline_and_flush ()
void pp_newline_and_indent ()
void pp_separate_with ()
static int decode_utf8_char ()
const char * identifier_to_locale ()

Variables

void *(* identifier_to_locale_alloc )(size_t) = xmalloc
void(* identifier_to_locale_free )(void *) = free

Macro Definition Documentation

#define pp_formatted_text_data (   PP)    ((const char *) obstack_base (pp_buffer (PP)->obstack))

A pointer to the formatted diagnostic message.

Referenced by pretty_printer::pretty_printer().

#define pp_integer_with_precision (   PP,
  ARG,
  PREC,
  T,
 
)
Value:
do \
switch (PREC) \
{ \
case 0: \
pp_scalar (PP, "%" F, va_arg (ARG, T)); \
break; \
\
case 1: \
pp_scalar (PP, "%l" F, va_arg (ARG, long T)); \
break; \
\
case 2: \
pp_scalar (PP, "%" HOST_LONG_LONG_FORMAT F, va_arg (ARG, long long T)); \
break; \
\
default: \
break; \
} \
while (0)

Format an integer given by va_arg (ARG, type-specifier T) where type-specifier is a precision modifier as indicated by PREC. F is a string used to construct the appropriate format-specifier.


Function Documentation

static int decode_utf8_char ( )
static

The string starting at P has LEN (at least 1) bytes left; if they start with a valid UTF-8 sequence, return the length of that sequence and set *VALUE to the value of that sequence, and otherwise return 0 and set *VALUE to (unsigned int) -1.

References identifier_to_locale_alloc, and locale_utf8.

const char* identifier_to_locale ( )

Given IDENT, an identifier in the internal encoding, return a version of IDENT suitable for diagnostics in the locale character set: either IDENT itself, or a string, allocated using identifier_to_locale_alloc, converted to the locale character set and using escape sequences if not representable in the locale character set or containing control characters or invalid byte sequences. Existing backslashes in IDENT are not doubled, so the result may not uniquely specify the contents of an arbitrary byte sequence identifier.

 If IDENT contains invalid UTF-8 sequences (which may occur with
 attributes putting arbitrary byte sequences in identifiers), or
 control characters, we use octal escape sequences for all bytes
 outside printable ASCII.   
 Otherwise, if it is valid printable ASCII, or printable UTF-8
 with the locale character set being UTF-8, IDENT is used.   
 Otherwise IDENT is converted to the locale character set if
 possible.   
 Otherwise, convert non-ASCII characters in IDENT to UCNs.   

Referenced by lhd_print_error_function().

static void pp_append_r ( )
inlinestatic

Append to the output area of PRETTY-PRINTER a string specified by its STARTing character and LENGTH.

void pp_append_text ( )

Append a string delimited by START and END to the output area of PRETTY-PRINTER. No line wrapping is done. However, if beginning a new line then emit PRETTY-PRINTER's prefix and skip any leading whitespace if appropriate. The caller must ensure that it is safe to do so.

Emit prefix and skip whitespace if we're starting a new line.

References errno.

void pp_character ( )

Have PRETTY-PRINTER add a CHARACTER.

References pp_space.

Referenced by dump_gimple_omp_target().

void pp_clear_output_area ( )

Clear PRETTY-PRINTER output area text info.

References pp_indent().

Referenced by pp_clear_state().

static void pp_clear_state ( )
inlinestatic

Clear PRETTY-PRINTER's output state.

References pp_buffer, pp_clear_output_area(), and pp_formatted_text().

void pp_destroy_prefix ( )

Free PRETTY-PRINTER's prefix, a previously malloc()'d string.

Referenced by trim_filename().

void pp_emit_prefix ( )

Write out PRETTY-PRINTER's prefix.

Fall through.

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

void pp_flush ( )

Flush the content of BUFFER onto the attached stream.

References CONST_CAST, NULL, and pretty_printer::prefix.

void pp_format ( )

The following format specifiers are recognized as being client independent: d, i: (signed) integer in base ten. u: unsigned integer in base ten. o: unsigned integer in base eight. x: unsigned integer in base sixteen. ld, li, lo, lu, lx: long versions of the above. lld, lli, llo, llu, llx: long long versions. wd, wi, wo, wu, wx: HOST_WIDE_INT versions. c: character. s: string. p: pointer. r: if pp_show_color(pp), switch to color identified by const char *. R: if pp_show_color(pp), reset color. m: strerror(text->err_no) - does not consume a value from args_ptr. %%: ''. %<: opening quote. %>: closing quote. ': apostrophe (should only be used in untranslated messages; translations should use appropriate punctuation directly). %.*s: a substring the length of which is specified by an argument integer. Ns: likewise, but length specified as constant in the format string. Flag 'q': quote formatted text (must come immediately after '').

Arguments can be used sequentially, or through N$ resp. *N$ notation Nth argument after the format string. If N$ / *N$ notation is used, it must be used for all arguments, except m, %%, %<, %> and ', which may not have a number, as they do not consume an argument. When M$.*N$s is used, M must be N + 1. (This may also be written M$.*s, provided N is not otherwise used.) The format string must have conversion specifiers with argument numbers 1 up to highest argument; each argument may only be used once. A format string can have at most 30 arguments. Formatting phases 1 and 2: render TEXT->format_spec plus TEXT->args_ptr into a series of chunks in pp_buffer (PP)->args[]. Phase 3 is in pp_format_text.

 Allocate a new chunk structure.   
 Formatting phase 1: split up TEXT->format_spec into chunks in
 pp_buffer (PP)->args[].  Even-numbered chunks are to be output
 verbatim, odd-numbered chunks are format specifiers.
 %m, %%, %<, %>, and %' are replaced with the appropriate text at
 this point.   
         FALLTHRU  
         Handled in phase 2.  Terminate the plain chunk here.   
         We handle '%.Ns' and '%.*s' or '%M$.*N$s'
         (where M == N + 1).   
 Set output to the argument obstack, and switch line-wrapping and
 prefixing off.   
 Second phase.  Replace each formatter with the formatted text it
 corresponds to.   
     We do not attempt to enforce any ordering on the modifier
     characters.   
             We don't support precision beyond that of "long long".   
           We handle '%.Ns' and '%.*s' or '%M$.*N$s'
           (where M == N + 1).  The format string should be verified
           already from the first phase.   
               This consumes a second entry in the formatters array.   
 Revert to normal obstack and wrapping mode.   

Referenced by trim_filename().

void pp_format_verbatim ( )

Helper subroutine of output_verbatim and verbatim. Do the appropriate settings needed by BUFFER for a verbatim formatting.

 Set verbatim mode.   
 Do the actual formatting.   
 Restore previous settings.   
const char* pp_formatted_text ( )

Finishes constructing a NULL-terminated character string representing the PRETTY-PRINTED text.

References errno.

Referenced by pp_clear_state(), pp_write_text_to_stream(), and rtl_dump_bb_for_graph().

void pp_indent ( )

Insert enough spaces into the output area of PRETTY-PRINTER to bring the column position to the current indentation level, assuming that a newline has just been written to the buffer.

References chunk_info::args, buffer, output_buffer::chunk_obstack, output_buffer::cur_chunk_array, pp_buffer, PP_NL_ARGMAX, and chunk_info::prev.

Referenced by pp_clear_output_area(), and pp_newline().

const char* pp_last_position_in_text ( )

Return a pointer to the last character emitted in PRETTY-PRINTER's output area. A NULL pointer means no character available.

References obstack, pp_buffer, and pp_needs_newline.

void pp_maybe_space ( )

Maybe print out a whitespace if needed.

static void pp_maybe_wrap_text ( )
inlinestatic

Same as pp_wrap_text but wrap text only when in line-wrapping mode.

References pp_indentation, and pp_space.

void pp_newline_and_flush ( )

Referenced by print_generic_decl().

void pp_newline_and_indent ( )
void pp_output_formatted_text ( )

Format of a message pointed to by TEXT.

This is a third phase, first 2 phases done in pp_format_args. Now we actually print it.

 Deallocate the chunk structure and everything after it (i.e. the
 associated series of formatted strings).   

Referenced by trim_filename().

void pp_printf ( )

Format a message into BUFFER a la printf.

Referenced by draw_cfg_node_succ_edges(), draw_cfg_nodes(), lhd_print_error_function(), print_insn(), and print_value().

int pp_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 pp_is_wrapping_line, and pp_newline().

void pp_separate_with ( )
void pp_set_line_maximum_length ( )

Sets the number of maximum characters per line PRETTY-PRINTER can output in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping.

References DIAGNOSTICS_SHOW_PREFIX_NEVER, DIAGNOSTICS_SHOW_PREFIX_ONCE, pretty_printer::emitted_prefix, and pp_prefixing_rule.

void pp_set_prefix ( )

Set PREFIX for PRETTY-PRINTER.

Referenced by default_tree_diagnostic_starter(), pp_emit_prefix(), and trim_filename().

static void pp_set_real_maximum_length ( )
static

Subroutine of pp_set_maximum_length. Set up PRETTY-PRINTER's internal maximum characters per line.

If we're told not to wrap lines then do the obvious thing. In case we'll emit prefix only once per message, it is appropriate not to increase unnecessarily the line-length cut-off.

     If the prefix is ridiculously too long, output at least
     32 characters.   
void pp_verbatim ( )

Output MESSAGE verbatim into BUFFER.

Referenced by diagnostic_report_current_module().

static void pp_wrap_text ( )
static

Wrap a text delimited by START and END into PRETTY-PRINTER.

Dump anything bordered by whitespaces.

void pp_write_text_as_dot_label_to_stream ( )

As pp_write_text_to_stream, but for GraphViz label output.

Flush the formatted text of pretty-printer PP onto the attached stream. Replace characters in PPF that have special meaning in a GraphViz .dot file.

This routine is not very fast, but it doesn't have to be as this is only be used by routines dumping intermediate representations in graph form.

       Print newlines as a left-aligned newline.   
       A pipe is only special for record-shape nodes.   
       The following characters always have to be escaped
       for use in labels.   
         fall through  

Referenced by dump_rtl_slim().

void pp_write_text_to_stream ( )

Flush the formatted text of PRETTY-PRINTER onto the attached stream.

References pp_buffer, and pp_formatted_text().

Referenced by dump_rtl_slim().


Variable Documentation

void*(* identifier_to_locale_alloc)(size_t) = xmalloc

Allocator for identifier_to_locale and corresponding function to free memory.

Referenced by decode_utf8_char().

void(* identifier_to_locale_free)(void *) = free