This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH 1/3] (v3) Non-C++ parts of template type diff printing
- From: David Malcolm <dmalcolm at redhat dot com>
- To: Nathan Sidwell <nathan at acm dot org>, gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Tue, 9 May 2017 21:41:06 -0400
- Subject: [PATCH 1/3] (v3) Non-C++ parts of template type diff printing
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=dmalcolm at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C83634E8AB
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C83634E8AB
- References: <6ef08fbf-845e-a7ab-dc18-eed8188aa53f@acm.org> <1494380468-40491-1-git-send-email-dmalcolm@redhat.com>
This patch is broken out from the C++ patch, for ease of review.
I believe I can self-approve this one, assuming the other patches
in the kit are OK.
The patch:
- adds the bool and const char ** params to the
pp_format_decoder callback
- adds the format_postprocessor class
- adds the "type-diff" colorization code.
All are unused until patch 2 in the kit.
gcc/c/ChangeLog:
* c-objc-common.c (c_tree_printer): Gain bool and const char **
parameters.
gcc/cp/ChangeLog:
* error.c (cp_printer): Gain bool and const char ** parameters.
gcc/ChangeLog:
* diagnostic-color.c (color_dict): Add "type-diff".
(parse_gcc_colors): Update comment.
* doc/invoke.texi (Diagnostic Message Formatting Options): Add
-fdiagnostics-show-template-tree and -fno-elide-type.
(GCC_COLORS): Add type-diff to example.
(type-diff=): New.
gcc/fortran/ChangeLog:
* error.c (gfc_format_decoder): Update for new bool and
const char ** params.
gcc/ChangeLog:
* pretty-print.c (pp_format): Pass quote and formatters[argno] to
the pp_format_decoder callback. Call any m_format_postprocessor's
"handle" method.
(pretty_printer::pretty_printer): Initialize
m_format_postprocessor.
(pretty_printer::~pretty_printer): Delete any
m_format_postprocessor.
* pretty-print.h (printer_fn): Add bool and const char **
parameters.
(class format_postprocessor): New class.
(struct pretty_printer::format_decoder): Document the new
parameters.
(struct pretty_printer::m_format_postprocessor): New field.
* tree-diagnostic.c (default_tree_printer): Update for new
bool and const char ** params.
* tree-diagnostic.h (default_tree_printer): Likewise.
---
gcc/c/c-objc-common.c | 5 +++--
gcc/cp/error.c | 5 +++--
gcc/diagnostic-color.c | 6 ++++--
gcc/doc/invoke.texi | 8 +++++++-
gcc/fortran/error.c | 5 +++--
gcc/pretty-print.c | 11 ++++++++++-
gcc/pretty-print.h | 20 ++++++++++++++++++--
gcc/tree-diagnostic.c | 3 ++-
gcc/tree-diagnostic.h | 2 +-
9 files changed, 51 insertions(+), 14 deletions(-)
diff --git a/gcc/c/c-objc-common.c b/gcc/c/c-objc-common.c
index 5e69488..05212b2 100644
--- a/gcc/c/c-objc-common.c
+++ b/gcc/c/c-objc-common.c
@@ -28,7 +28,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);
+ int, bool, bool, bool, bool, const char **);
bool
c_missing_noreturn_ok_p (tree decl)
@@ -75,7 +75,8 @@ c_objc_common_init (void)
diagnostic machinery. */
static bool
c_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
- int precision, bool wide, bool set_locus, bool hash)
+ int precision, bool wide, bool set_locus, bool hash,
+ bool, const char **)
{
tree t = NULL_TREE;
tree name;
diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index a83ecb2..4934c51 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -99,7 +99,7 @@ static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *);
static void cp_print_error_function (diagnostic_context *, diagnostic_info *);
static bool cp_printer (pretty_printer *, text_info *, const char *,
- int, bool, bool, bool);
+ int, bool, bool, bool, bool, const char **);
/* CONTEXT->printer is a basic pretty printer that was constructed
presumably by diagnostic_initialize(), called early in the
@@ -3582,7 +3582,8 @@ maybe_print_constexpr_context (diagnostic_context *context)
%X exception-specification. */
static bool
cp_printer (pretty_printer *pp, text_info *text, const char *spec,
- int precision, bool wide, bool set_locus, bool verbose)
+ int precision, bool wide, bool set_locus, bool verbose,
+ bool, const char **)
{
const char *result;
tree t = NULL;
diff --git a/gcc/diagnostic-color.c b/gcc/diagnostic-color.c
index 8353fe0..6adb872 100644
--- a/gcc/diagnostic-color.c
+++ b/gcc/diagnostic-color.c
@@ -174,6 +174,7 @@ static struct color_cap color_dict[] =
{ "diff-hunk", SGR_SEQ (COLOR_FG_CYAN), 9, false },
{ "diff-delete", SGR_SEQ (COLOR_FG_RED), 11, false },
{ "diff-insert", SGR_SEQ (COLOR_FG_GREEN), 11, false },
+ { "type-diff", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_GREEN), 9, false },
{ NULL, NULL, 0, false }
};
@@ -204,8 +205,9 @@ colorize_stop (bool show_color)
/* Parse GCC_COLORS. The default would look like:
GCC_COLORS='error=01;31:warning=01;35:note=01;36:\
range1=32:range2=34:locus=01:quote=01:\
- fixit-insert=32:fixit-delete=31'\
- diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32'
+ fixit-insert=32:fixit-delete=31:'\
+ diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32:\
+ type-diff=01;32'
No character escaping is needed or supported. */
static bool
parse_gcc_colors (void)
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 65308c9..1ba45cf 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -3442,7 +3442,8 @@ The default @env{GCC_COLORS} is
@smallexample
error=01;31:warning=01;35:note=01;36:range1=32:range2=34:locus=01:\
quote=01:fixit-insert=32:fixit-delete=31:\
-diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32
+diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32:\
+type-diff=01;32
@end smallexample
@noindent
where @samp{01;31} is bold red, @samp{01;35} is bold magenta,
@@ -3506,6 +3507,11 @@ SGR substring for deleted lines within generated patches.
@item diff-insert=
@vindex diff-insert GCC_COLORS @r{capability}
SGR substring for inserted lines within generated patches.
+
+@item type-diff=
+@vindex type-diff GCC_COLORS @r{capability}
+SGR substring for highlighting mismatching types within template
+arguments in the C++ frontend.
@end table
@item -fno-diagnostics-show-option
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index 0312499..af72581 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -917,7 +917,8 @@ gfc_notify_std (int std, const char *gmsgid, ...)
*/
static bool
gfc_format_decoder (pretty_printer *pp, text_info *text, const char *spec,
- int precision, bool wide, bool set_locus, bool hash)
+ int precision, bool wide, bool set_locus, bool hash,
+ bool quoted, const char **buffer_ptr)
{
switch (*spec)
{
@@ -948,7 +949,7 @@ gfc_format_decoder (pretty_printer *pp, text_info *text, const char *spec,
etc. diagnostics can use the FE printer while the FE is still
active. */
return default_tree_printer (pp, text, spec, precision, wide,
- set_locus, hash);
+ set_locus, hash, quoted, buffer_ptr);
}
}
diff --git a/gcc/pretty-print.c b/gcc/pretty-print.c
index bcb1a70..570dec7 100644
--- a/gcc/pretty-print.c
+++ b/gcc/pretty-print.c
@@ -677,7 +677,8 @@ pp_format (pretty_printer *pp, text_info *text)
gcc_assert (pp_format_decoder (pp));
ok = pp_format_decoder (pp) (pp, text, p,
- precision, wide, plus, hash);
+ precision, wide, plus, hash, quote,
+ formatters[argno]);
gcc_assert (ok);
}
}
@@ -696,6 +697,11 @@ pp_format (pretty_printer *pp, text_info *text)
for (; argno < PP_NL_ARGMAX; argno++)
gcc_assert (!formatters[argno]);
+ /* If the client supplied a postprocessing object, call its "handle"
+ hook here. */
+ if (pp->m_format_postprocessor)
+ pp->m_format_postprocessor->handle (pp);
+
/* Revert to normal obstack and wrapping mode. */
buffer->obstack = &buffer->formatted_obstack;
buffer->line_length = 0;
@@ -847,6 +853,7 @@ pretty_printer::pretty_printer (const char *p, int l)
indent_skip (),
wrapping (),
format_decoder (),
+ m_format_postprocessor (NULL),
emitted_prefix (),
need_newline (),
translate_identifiers (true),
@@ -860,6 +867,8 @@ pretty_printer::pretty_printer (const char *p, int l)
pretty_printer::~pretty_printer ()
{
+ if (m_format_postprocessor)
+ delete m_format_postprocessor;
buffer->~output_buffer ();
XDELETE (buffer);
}
diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h
index 2596678..40e56a3 100644
--- a/gcc/pretty-print.h
+++ b/gcc/pretty-print.h
@@ -180,11 +180,20 @@ struct pp_wrapping_mode_t
A client-supplied formatter returns true if everything goes well,
otherwise it returns false. */
typedef bool (*printer_fn) (pretty_printer *, text_info *, const char *,
- int, bool, bool, bool);
+ int, bool, bool, bool, bool, const char **);
/* Client supplied function used to decode formats. */
#define pp_format_decoder(PP) (PP)->format_decoder
+/* Base class for an optional client-supplied object for doing additional
+ processing between stages 2 and 3 of formatted printing. */
+class format_postprocessor
+{
+ public:
+ virtual ~format_postprocessor () {}
+ virtual void handle (pretty_printer *) = 0;
+};
+
/* TRUE if a newline character needs to be added before further
formatting. */
#define pp_needs_newline(PP) (PP)->need_newline
@@ -239,9 +248,16 @@ struct pretty_printer
If the BUFFER needs additional characters from the format string, it
should advance the TEXT->format_spec as it goes. When FORMAT_DECODER
returns, TEXT->format_spec should point to the last character processed.
- */
+ The QUOTE and BUFFER_PTR are passed in, to allow for deferring-handling
+ of format codes (e.g. %H and %I in the C++ frontend). */
printer_fn format_decoder;
+ /* If non-NULL, this is called by pp_format once after all format codes
+ have been processed, to allow for client-specific postprocessing.
+ This is used by the C++ frontend for handling the %H and %I
+ format codes (which interract with each other). */
+ format_postprocessor *m_format_postprocessor;
+
/* Nonzero if current PREFIX was emitted at least once. */
bool emitted_prefix;
diff --git a/gcc/tree-diagnostic.c b/gcc/tree-diagnostic.c
index 4f211ed..ebce1a4 100644
--- a/gcc/tree-diagnostic.c
+++ b/gcc/tree-diagnostic.c
@@ -245,7 +245,8 @@ virt_loc_aware_diagnostic_finalizer (diagnostic_context *context,
/* Default tree printer. Handles declarations only. */
bool
default_tree_printer (pretty_printer *pp, text_info *text, const char *spec,
- int precision, bool wide, bool set_locus, bool hash)
+ int precision, bool wide, bool set_locus, bool hash,
+ bool, const char **)
{
tree t;
diff --git a/gcc/tree-diagnostic.h b/gcc/tree-diagnostic.h
index e95183f..85aa980 100644
--- a/gcc/tree-diagnostic.h
+++ b/gcc/tree-diagnostic.h
@@ -55,6 +55,6 @@ void virt_loc_aware_diagnostic_finalizer (diagnostic_context *,
void tree_diagnostics_defaults (diagnostic_context *context);
bool default_tree_printer (pretty_printer *, text_info *, const char *,
- int, bool, bool, bool);
+ int, bool, bool, bool, bool, const char **);
#endif /* ! GCC_TREE_DIAGNOSTIC_H */
--
1.8.5.3