Mercurial > hg > CbC > CbC_gcc
diff gcc/pretty-print.c @ 131:84e7813d76e9
gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 07:37:49 +0900 |
parents | 04ced10e8804 |
children | 1830386684a0 |
line wrap: on
line diff
--- a/gcc/pretty-print.c Fri Oct 27 22:46:09 2017 +0900 +++ b/gcc/pretty-print.c Thu Oct 25 07:37:49 2018 +0900 @@ -1,5 +1,5 @@ /* Various declarations for language-independent pretty-print subroutines. - Copyright (C) 2003-2017 Free Software Foundation, Inc. + Copyright (C) 2003-2018 Free Software Foundation, Inc. Contributed by Gabriel Dos Reis <gdr@integrable-solutions.net> This file is part of GCC. @@ -640,6 +640,16 @@ { attrib_add |= sb.wAttributes & ~attrib_rm; } + if (attrib_add & COMMON_LVB_REVERSE_VIDEO) + { + /* COMMON_LVB_REVERSE_VIDEO is only effective for DBCS. + * Swap foreground and background colors by hand. + */ + attrib_add = (attrib_add & 0xFF00) + | ((attrib_add & 0x00F0) >> 4) + | ((attrib_add & 0x000F) << 4); + attrib_add &= ~COMMON_LVB_REVERSE_VIDEO; + } SetConsoleTextAttribute (h, attrib_add); break; } @@ -684,7 +694,6 @@ /* If it is not a console, write everything as-is. */ write_all (h, read, strlen (read)); - _close ((intptr_t) h); return 1; } @@ -696,10 +705,11 @@ For use e.g. when implementing "+" in client format decoders. */ void -text_info::set_location (unsigned int idx, location_t loc, bool show_caret_p) +text_info::set_location (unsigned int idx, location_t loc, + enum range_display_kind range_display_kind) { gcc_checking_assert (m_richloc); - m_richloc->set_range (line_table, idx, loc, show_caret_p); + m_richloc->set_range (idx, loc, range_display_kind); } location_t @@ -795,6 +805,30 @@ pp_indentation (pp) = 0; } +/* Print X to PP in decimal. */ +template<unsigned int N, typename T> +void +pp_wide_integer (pretty_printer *pp, const poly_int_pod<N, T> &x) +{ + if (x.is_constant ()) + pp_wide_integer (pp, x.coeffs[0]); + else + { + pp_left_bracket (pp); + for (unsigned int i = 0; i < N; ++i) + { + if (i != 0) + pp_comma (pp); + pp_wide_integer (pp, x.coeffs[i]); + } + pp_right_bracket (pp); + } +} + +template void pp_wide_integer (pretty_printer *, const poly_uint16_pod &); +template void pp_wide_integer (pretty_printer *, const poly_int64_pod &); +template void pp_wide_integer (pretty_printer *, const poly_uint64_pod &); + /* Flush the formatted text of PRETTY-PRINTER onto the attached stream. */ void pp_write_text_to_stream (pretty_printer *pp) @@ -1209,10 +1243,7 @@ gcc_assert (!wide || precision == 0); if (quote) - { - pp_string (pp, open_quote); - pp_string (pp, colorize_start (pp_show_color (pp), "quote")); - } + pp_begin_quote (pp, pp_show_color (pp)); switch (*p) { @@ -1345,19 +1376,21 @@ { bool ok; + /* Call the format decoder. + Pass the address of "quote" so that format decoders can + potentially disable printing of the closing quote + (e.g. when printing "'TYPEDEF' aka 'TYPE'" in the C family + of frontends). */ gcc_assert (pp_format_decoder (pp)); ok = pp_format_decoder (pp) (pp, text, p, - precision, wide, plus, hash, quote, + precision, wide, plus, hash, "e, formatters[argno]); gcc_assert (ok); } } if (quote) - { - pp_string (pp, colorize_stop (pp_show_color (pp))); - pp_string (pp, close_quote); - } + pp_end_quote (pp, pp_show_color (pp)); obstack_1grow (&buffer->chunk_obstack, '\0'); *formatters[argno] = XOBFINISH (&buffer->chunk_obstack, const char *); @@ -1459,23 +1492,38 @@ pp_buffer (pp)->line_length = 0; } -/* Set PREFIX for PRETTY-PRINTER. */ +/* Set PREFIX for PRETTY-PRINTER, taking ownership of PREFIX, which + will eventually be free-ed. */ + void -pp_set_prefix (pretty_printer *pp, const char *prefix) +pp_set_prefix (pretty_printer *pp, char *prefix) { + free (pp->prefix); pp->prefix = prefix; pp_set_real_maximum_length (pp); pp->emitted_prefix = false; pp_indentation (pp) = 0; } +/* Take ownership of PP's prefix, setting it to NULL. + This allows clients to save, overide, and then restore an existing + prefix, without it being free-ed. */ + +char * +pp_take_prefix (pretty_printer *pp) +{ + char *result = pp->prefix; + pp->prefix = NULL; + return result; +} + /* Free PRETTY-PRINTER's prefix, a previously malloc()'d string. */ void pp_destroy_prefix (pretty_printer *pp) { if (pp->prefix != NULL) { - free (CONST_CAST (char *, pp->prefix)); + free (pp->prefix); pp->prefix = NULL; } } @@ -1512,10 +1560,9 @@ } } -/* Construct a PRETTY-PRINTER with PREFIX and of MAXIMUM_LENGTH - characters per line. */ +/* Construct a PRETTY-PRINTER of MAXIMUM_LENGTH characters per line. */ -pretty_printer::pretty_printer (const char *p, int l) +pretty_printer::pretty_printer (int maximum_length) : buffer (new (XCNEW (output_buffer)) output_buffer ()), prefix (), padding (pp_none), @@ -1529,10 +1576,10 @@ translate_identifiers (true), show_color () { - pp_line_cutoff (this) = l; + pp_line_cutoff (this) = maximum_length; /* By default, we emit prefixes once per message. */ pp_prefixing_rule (this) = DIAGNOSTICS_SHOW_PREFIX_ONCE; - pp_set_prefix (this, p); + pp_set_prefix (this, NULL); } pretty_printer::~pretty_printer () @@ -1541,6 +1588,7 @@ delete m_format_postprocessor; buffer->~output_buffer (); XDELETE (buffer); + free (prefix); } /* Append a string delimited by START and END to the output area of @@ -1731,6 +1779,26 @@ pp_space (pp); } +/* Add a localized open quote, and if SHOW_COLOR is true, begin colorizing + using the "quote" color. */ + +void +pp_begin_quote (pretty_printer *pp, bool show_color) +{ + pp_string (pp, open_quote); + pp_string (pp, colorize_start (show_color, "quote")); +} + +/* If SHOW_COLOR is true, stop colorizing. + Add a localized close quote. */ + +void +pp_end_quote (pretty_printer *pp, bool show_color) +{ + pp_string (pp, colorize_stop (show_color)); + pp_string (pp, close_quote); +} + /* 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 @@ -2059,10 +2127,7 @@ { /* Avoid introducing locale-specific differences in the results by hardcoding open_quote and close_quote. */ - const char *old_open_quote = open_quote; - const char *old_close_quote = close_quote; - open_quote = "`"; - close_quote = "'"; + auto_fix_quotes fix_quotes; /* Verify that plain text is passed through unchanged. */ assert_pp_format (SELFTEST_LOCATION, "unformatted", "unformatted"); @@ -2144,10 +2209,6 @@ assert_pp_format (SELFTEST_LOCATION, "item 3 of 7", "item %i of %i", 3, 7); assert_pp_format (SELFTEST_LOCATION, "problem with `bar' at line 10", "problem with %qs at line %i", "bar", 10); - - /* Restore old values of open_quote and close_quote. */ - open_quote = old_open_quote; - close_quote = old_close_quote; } /* Run all of the selftests within this file. */