aboutsummaryrefslogtreecommitdiff
path: root/gcc/pretty-print.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2017-11-22 20:37:58 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2017-11-22 20:37:58 +0000
commitce95abc41e998c8d1e1b2112a634d5a6cdd9ede0 (patch)
tree1dfdcc2ae24d09d53824e4b7b34934a19d570519 /gcc/pretty-print.c
parentd8d9aa38aed6489fa28308d3955e3467c5eb935b (diff)
downloadgcc-ce95abc41e998c8d1e1b2112a634d5a6cdd9ede0.zip
gcc-ce95abc41e998c8d1e1b2112a634d5a6cdd9ede0.tar.gz
gcc-ce95abc41e998c8d1e1b2112a634d5a6cdd9ede0.tar.bz2
C/C++: fix quoting of "aka" typedef information (PR 62170)
PR 62170 describes a problem with how the quoting in pp_format interacts with the "aka" information for typedefs in %qT for the C family of frontends, and also now for %qH and %qI in the C++ frontend: we print: 'Py_ssize_t* {aka int*}' ^^^^^^^^^^^^^^^^^^^^^^ colorized as "quote" i.e. '[START_COLOR]Py_ssize_t* {aka int*}[END_COLOR]' when we should print: 'Py_ssize_t*' {aka 'int*'} ^^^^^^^^^^^ ^^^^ colorized as "quote" i.e. '[START_COLOR]Py_ssize_t*[END_COLOR]' {aka '[START_COLOR]int*[END_COLOR]'} where the opening and closing quote characters and colorization are added by the 'q' handling within pp_format. This patch fixes the quoting by updating the %T handling in C and C++ and the %H/%I handling in C++ to insert the quoting appropriately. It converts the "quote" param of the pp_format_decoder callback from bool to bool *, allowing for the %T and %H/%I handlers to write false back to it, to avoid printing the closing quote for the cases like the above where the trailing closing quote isn't needed. It introduces pp_begin_quote/pp_end_quote to simplify this. These take a "bool show_color", rather than using "pp_show_color (pp)" since cxx_pp's pp_show_color isn't currently initialized (since cxx_initialize_diagnostics happens before diagnostic_color_init). gcc/c/ChangeLog: PR c++/62170 * c-objc-common.c (c_tree_printer): Convert penultimate param from bool to bool *. Within '%T' handling, if showing an "aka", use "quoted" param to add appropriate quoting. gcc/cp/ChangeLog: PR c++/62170 * error.c (type_to_string): Add leading comment. Add params "postprocessed", "quote", and "show_color", using them to fix quoting of the "aka" for types involving typedefs. (arg_to_string): Update for new params to type_to_string. (cxx_format_postprocessor::handle): Likewise. (cp_printer): Convert penultimate param from bool to bool *. Update call to type_to_string and calls to defer_phase_2_of_type_diff. gcc/fortran/ChangeLog: PR c++/62170 * error.c (gfc_notify_std): Convert "quoted" param from bool to bool *. gcc/ChangeLog: PR c++/62170 * pretty-print.c (pp_format): Move quoting implementation to pp_begin_quote and pp_end_quote. Update pp_format_decoder call to pass address of "quote" local. (pp_begin_quote): New function. (pp_end_quote): New function. * pretty-print.h (printer_fn): Convert penultimate param from bool to bool *. (pp_begin_quote): New decl. (pp_end_quote): New decl. * tree-diagnostic.c (default_tree_printer): Convert penultimate param from bool to bool *. * tree-diagnostic.h (default_tree_printer): Likewise. gcc/testsuite/ChangeLog: PR c++/62170 * g++.dg/diagnostic/aka1.C: Update expected error messages to reflect fixes to quoting. * g++.dg/diagnostic/aka2.C: New test case. * g++.dg/parse/error55.C: Update expected error messages to reflect fixes to quoting. * gcc.dg/diag-aka-1.c: Likewise. * gcc.dg/diag-aka-2.c: New test case. * gcc.dg/pr13804-1.c: Update expected error messages to reflect fixes to quoting. * gcc.dg/pr56980.c: Likewise. * gcc.dg/pr65050.c: Likewise. * gcc.dg/redecl-14.c: Likewise. * gcc.dg/utf16-4.c Likewise. * gcc.target/i386/sse-vect-types.c (__m128d): Likewise. * obj-c++.dg/invalid-type-1.mm: Likewise. * objc.dg/proto-lossage-4.m: Likewise. From-SVN: r255076
Diffstat (limited to 'gcc/pretty-print.c')
-rw-r--r--gcc/pretty-print.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index e66d898..1fbd2fe 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -1209,10 +1209,7 @@ pp_format (pretty_printer *pp, text_info *text)
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 +1342,21 @@ pp_format (pretty_printer *pp, text_info *text)
{
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, &quote,
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 *);
@@ -1731,6 +1730,26 @@ pp_separate_with (pretty_printer *pp, char c)
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