#include "cp-tree.h"
#include "stringpool.h"
#include "tree-diagnostic.h"
+#include "diagnostic-color.h"
#include "langhooks-def.h"
#include "intl.h"
#include "cxx-pretty-print.h"
static const char *args_to_string (tree, int);
static const char *code_to_string (enum tree_code);
static const char *cv_to_string (tree, int);
-static const char *decl_to_string (tree, int);
+static const char *decl_to_string (tree, int, bool);
static const char *fndecl_to_string (tree, int);
static const char *op_to_string (bool, enum tree_code);
static const char *parm_to_string (int);
else
{
pp_cxx_whitespace (pp);
+ pp_string (pp, colorize_start (pp_show_color (pp), "targs"));
pp_cxx_left_bracket (pp);
pp->translate_string ("with");
pp_cxx_whitespace (pp);
~prepost_semicolon ()
{
if (need_semicolon)
- pp_cxx_right_bracket (pp);
+ {
+ pp_cxx_right_bracket (pp);
+ pp_string (pp, colorize_stop (pp_show_color (pp)));
+ }
}
} semicolon_or_introducer = {pp, false};
dump_type_suffix (pp, type, flags);
}
+class colorize_guard
+{
+ bool colorize;
+ cxx_pretty_printer *pp;
+public:
+ colorize_guard (bool _colorize, cxx_pretty_printer *pp, const char *name)
+ : colorize (_colorize && pp_show_color (pp)), pp (pp)
+ {
+ pp_string (pp, colorize_start (colorize, name));
+ }
+ ~colorize_guard ()
+ {
+ pp_string (pp, colorize_stop (colorize));
+ }
+};
+
/* Print an IDENTIFIER_NODE that is the name of a declaration. */
static void
static void
dump_function_name (cxx_pretty_printer *pp, tree t, int flags)
{
+ /* Only colorize when we're printing something before the name; in
+ particular, not when printing a CALL_EXPR. */
+ bool colorize = flags & (TFF_DECL_SPECIFIERS | TFF_RETURN_TYPE
+ | TFF_TEMPLATE_HEADER);
+
+ colorize_guard g (colorize, pp, "fnname");
+
tree name = DECL_NAME (t);
/* We can get here with a decl that was synthesized by language-
cxx_pp->padding = pp_none;
pp_indentation (cxx_pp) = 0;
pp_needs_newline (cxx_pp) = false;
+ pp_show_color (cxx_pp) = false;
cxx_pp->enclosing_scope = current_function_decl;
}
function. */
static const char *
-decl_to_string (tree decl, int verbose)
+decl_to_string (tree decl, int verbose, bool show_color)
{
int flags = 0;
flags |= TFF_TEMPLATE_HEADER;
reinit_cxx_pp ();
+ pp_show_color (cxx_pp) = show_color;
dump_decl (cxx_pp, decl, flags);
return pp_ggc_formatted_text (cxx_pp);
}
flags |= TFF_TEMPLATE_HEADER;
reinit_cxx_pp ();
+ pp_show_color (cxx_pp) = show_color;
if (postprocessed && quote && *quote)
pp_begin_quote (cxx_pp, show_color);
arguments. */
static const char *
-subst_to_string (tree p)
+subst_to_string (tree p, bool show_color)
{
tree decl = TREE_PURPOSE (p);
tree targs = TREE_VALUE (p);
return "";
reinit_cxx_pp ();
+ pp_show_color (cxx_pp) = show_color;
dump_template_decl (cxx_pp, TREE_PURPOSE (p), flags);
dump_substitution (cxx_pp, NULL, tparms, targs, /*flags=*/0);
return pp_ggc_formatted_text (cxx_pp);
break;
}
}
- result = decl_to_string (temp, verbose);
+ result = decl_to_string (temp, verbose, pp_show_color (pp));
}
break;
case 'E': result = expr_to_string (next_tree); break;
case 'O': result = op_to_string (false, next_tcode); break;
case 'P': result = parm_to_string (next_int); break;
case 'Q': result = op_to_string (true, next_tcode); break;
- case 'S': result = subst_to_string (next_tree); break;
+ case 'S': result = subst_to_string (next_tree, pp_show_color (pp)); break;
case 'T':
{
result = type_to_string (next_tree, verbose, false, quoted,
{ "locus", SGR_SEQ (COLOR_BOLD), 5, false },
{ "quote", SGR_SEQ (COLOR_BOLD), 5, false },
{ "path", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_CYAN), 4, false },
+ { "fnname", SGR_SEQ (COLOR_BOLD COLOR_SEPARATOR COLOR_FG_GREEN), 6, false },
+ { "targs", SGR_SEQ (COLOR_FG_MAGENTA), 5, false },
{ "fixit-insert", SGR_SEQ (COLOR_FG_GREEN), 12, false },
{ "fixit-delete", SGR_SEQ (COLOR_FG_RED), 12, false },
{ "diff-filename", SGR_SEQ (COLOR_BOLD), 13, false },