aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-objc-common.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/c/c-objc-common.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/c/c-objc-common.c')
-rw-r--r--gcc/c/c-objc-common.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/gcc/c/c-objc-common.c b/gcc/c/c-objc-common.c
index 8f4d3eb..6d923eb 100644
--- a/gcc/c/c-objc-common.c
+++ b/gcc/c/c-objc-common.c
@@ -29,7 +29,7 @@ along with GCC; see the file COPYING3. If not see
#include "c-objc-common.h"
static bool c_tree_printer (pretty_printer *, text_info *, const char *,
- int, bool, bool, bool, bool, const char **);
+ int, bool, bool, bool, bool *, const char **);
bool
c_missing_noreturn_ok_p (tree decl)
@@ -79,7 +79,7 @@ c_objc_common_init (void)
static bool
c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
int precision, bool wide, bool set_locus, bool hash,
- bool, const char **)
+ bool *quoted, const char **)
{
tree t = NULL_TREE;
tree name;
@@ -166,12 +166,20 @@ c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
return true;
/* They're not, print the stripped version now. */
+ if (*quoted)
+ pp_end_quote (pp, pp_show_color (pp));
pp_c_whitespace (cpp);
pp_left_brace (cpp);
pp_c_ws_string (cpp, _("aka"));
pp_c_whitespace (cpp);
+ if (*quoted)
+ pp_begin_quote (pp, pp_show_color (pp));
cpp->type_id (TYPE_CANONICAL (t));
+ if (*quoted)
+ pp_end_quote (pp, pp_show_color (pp));
pp_right_brace (cpp);
+ /* No further closing quotes are needed. */
+ *quoted = false;
}
return true;
}