I noticed whilst working on another issue that in diagnostic-show-locus
within the quoted source lines and the annotation underlines that when
we're showing highlight-{a,b} that we emit
start-colorization-code, character, end-colorization-code
per *character*, rather than just when the colorization changes.
This was due to me failing to implement consolidation of such changes in
colorizer::set_named_color in
r15-2015-g7d73c01ce6d1ab.
Fixed thusly, simplifying the output.
I manually inspected all of the changed testcases in a terminal with
color enabled and verified that the output is visually identical to
before.
gcc/ChangeLog:
* diagnostic-show-locus.cc (colorizer::m_current_named_color): New
field.
(colorizer::set_named_color): Use it to consolidate repeated calls
to the same color.
gcc/testsuite/ChangeLog:
* g++.dg/diagnostic/bad-binary-ops-highlight-colors.C: Update
expected multiline output for quoted source and underlines to
reflect emitting color codes when changes happen, rather than
per character.
* g++.dg/diagnostic/long-short-colorization.C: Likewise.
* g++.dg/plugin/show-template-tree-color-labels.C: Likewise.
* gcc.dg/bad-binary-ops-highlight-colors.c: Likewise.
* gcc.dg/format/colors.c: Likewise.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
const char *m_fixit_insert;
const char *m_fixit_delete;
const char *m_stop_color;
+ std::string m_current_named_color;
};
/* In order to handle multibyte sources properly, all of this logic needs to be
void
colorizer::set_named_color (const char *color)
{
+ if (m_current_state == STATE_NAMED_COLOR
+ && color == m_current_named_color)
+ return;
finish_state (m_current_state);
m_current_state = STATE_NAMED_COLOR;
pp_string (&m_pp, colorize_start (pp_show_color (&m_pp), color));
+ m_current_named_color = color;
}
/* Update state, printing color codes if necessary if there's a state
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
- return \e[01;32m\e[Kc\e[m\e[K\e[01;32m\e[Ka\e[m\e[K\e[01;32m\e[Kl\e[m\e[K\e[01;32m\e[Kl\e[m\e[K\e[01;32m\e[Ke\e[m\e[K\e[01;32m\e[Ke\e[m\e[K\e[01;32m\e[K_\e[m\e[K\e[01;32m\e[K4\e[m\e[K\e[01;32m\e[Ka\e[m\e[K\e[01;32m\e[K \e[m\e[K\e[01;32m\e[K(\e[m\e[K\e[01;32m\e[K)\e[m\e[K \e[01;31m\e[K+\e[m\e[K \e[01;34m\e[Kc\e[m\e[K\e[01;34m\e[Ka\e[m\e[K\e[01;34m\e[Kl\e[m\e[K\e[01;34m\e[Kl\e[m\e[K\e[01;34m\e[Ke\e[m\e[K\e[01;34m\e[Ke\e[m\e[K\e[01;34m\e[K_\e[m\e[K\e[01;34m\e[K4\e[m\e[K\e[01;34m\e[Kb\e[m\e[K\e[01;34m\e[K \e[m\e[K\e[01;34m\e[K(\e[m\e[K\e[01;34m\e[K)\e[m\e[K;
- \e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K \e[01;31m\e[K^\e[m\e[K \e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K
+ return \e[01;32m\e[Kcallee_4a ()\e[m\e[K \e[01;31m\e[K+\e[m\e[K \e[01;34m\e[Kcallee_4b ()\e[m\e[K;
+ \e[01;32m\e[K~~~~~~~~~~~~\e[m\e[K \e[01;31m\e[K^\e[m\e[K \e[01;34m\e[K~~~~~~~~~~~~\e[m\e[K
\e[01;32m\e[K|\e[m\e[K \e[01;34m\e[K|\e[m\e[K
\e[01;32m\e[KS {aka s}\e[m\e[K \e[01;34m\e[KT {aka t}\e[m\e[K
{ dg-end-multiline-output "" } */
long short int a;
/* { dg-begin-multiline-output "" }
\e[m\e[K'\e[01m\e[K\e[01;32m\e[Klong\e[m\e[K\e[m\e[K' and '\e[01m\e[K\e[01;34m\e[Kshort\e[m\e[K\e[m\e[K' specified together
- \e[01;32m\e[Kl\e[m\e[K\e[01;32m\e[Ko\e[m\e[K\e[01;32m\e[Kn\e[m\e[K\e[01;32m\e[Kg\e[m\e[K \e[01;34m\e[Ks\e[m\e[K\e[01;34m\e[Kh\e[m\e[K\e[01;34m\e[Ko\e[m\e[K\e[01;34m\e[Kr\e[m\e[K\e[01;34m\e[Kt\e[m\e[K int a;
- \e[01;32m\e[K^\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K \e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K
+ \e[01;32m\e[Klong\e[m\e[K \e[01;34m\e[Kshort\e[m\e[K int a;
+ \e[01;32m\e[K^~~~\e[m\e[K \e[01;34m\e[K~~~~~\e[m\e[K
{ dg-end-multiline-output "" } */
short long int b;
/* { dg-begin-multiline-output "" }
\e[m\e[K'\e[01m\e[K\e[01;32m\e[Klong\e[m\e[K\e[m\e[K' and '\e[01m\e[K\e[01;34m\e[Kshort\e[m\e[K\e[m\e[K' specified together
- \e[01;34m\e[Ks\e[m\e[K\e[01;34m\e[Kh\e[m\e[K\e[01;34m\e[Ko\e[m\e[K\e[01;34m\e[Kr\e[m\e[K\e[01;34m\e[Kt\e[m\e[K \e[01;32m\e[Kl\e[m\e[K\e[01;32m\e[Ko\e[m\e[K\e[01;32m\e[Kn\e[m\e[K\e[01;32m\e[Kg\e[m\e[K int b;
- \e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K \e[01;32m\e[K^\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K
+ \e[01;34m\e[Kshort\e[m\e[K \e[01;32m\e[Klong\e[m\e[K int b;
+ \e[01;34m\e[K~~~~~\e[m\e[K \e[01;32m\e[K^~~~\e[m\e[K
{ dg-end-multiline-output "" } */
// Discard the remaining colorized output that confuses dejagnu.
fn_1 (vec);
/* { dg-begin-multiline-output "" }
could not convert '\e[01m\e[Kvec\e[m\e[K' from '\e[01m\e[Kvector<\e[01;32m\e[Kdouble\e[m\e[K>\e[m\e[K' to '\e[01m\e[Kvector<\e[01;34m\e[Kint\e[m\e[K>\e[m\e[K'
- fn_1 (\e[01;32m\e[Kv\e[m\e[K\e[01;32m\e[Ke\e[m\e[K\e[01;32m\e[Kc\e[m\e[K);
- \e[01;32m\e[K^\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K
+ fn_1 (\e[01;32m\e[Kvec\e[m\e[K);
+ \e[01;32m\e[K^~~\e[m\e[K
\e[01;32m\e[K|\e[m\e[K
\e[01;32m\e[Kvector<double>\e[m\e[K
{ dg-end-multiline-output "" } */
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
- return \e[01;32m\e[Kc\e[m\e[K\e[01;32m\e[Ka\e[m\e[K\e[01;32m\e[Kl\e[m\e[K\e[01;32m\e[Kl\e[m\e[K\e[01;32m\e[Ke\e[m\e[K\e[01;32m\e[Ke\e[m\e[K\e[01;32m\e[K_\e[m\e[K\e[01;32m\e[K4\e[m\e[K\e[01;32m\e[Ka\e[m\e[K\e[01;32m\e[K \e[m\e[K\e[01;32m\e[K(\e[m\e[K\e[01;32m\e[K)\e[m\e[K \e[01;31m\e[K+\e[m\e[K \e[01;34m\e[Kc\e[m\e[K\e[01;34m\e[Ka\e[m\e[K\e[01;34m\e[Kl\e[m\e[K\e[01;34m\e[Kl\e[m\e[K\e[01;34m\e[Ke\e[m\e[K\e[01;34m\e[Ke\e[m\e[K\e[01;34m\e[K_\e[m\e[K\e[01;34m\e[K4\e[m\e[K\e[01;34m\e[Kb\e[m\e[K\e[01;34m\e[K \e[m\e[K\e[01;34m\e[K(\e[m\e[K\e[01;34m\e[K)\e[m\e[K;
- \e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K~\e[m\e[K \e[01;31m\e[K^\e[m\e[K \e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K
+ return \e[01;32m\e[Kcallee_4a ()\e[m\e[K \e[01;31m\e[K+\e[m\e[K \e[01;34m\e[Kcallee_4b ()\e[m\e[K;
+ \e[01;32m\e[K~~~~~~~~~~~~\e[m\e[K \e[01;31m\e[K^\e[m\e[K \e[01;34m\e[K~~~~~~~~~~~~\e[m\e[K
\e[01;32m\e[K|\e[m\e[K \e[01;34m\e[K|\e[m\e[K
\e[01;32m\e[K|\e[m\e[K \e[01;34m\e[KT {aka struct t}\e[m\e[K
\e[01;32m\e[KS {aka struct s}\e[m\e[K
warning: \e[m\e[Kformat '\e[01m\e[K\e[01;32m\e[K%i\e[m\e[K\e[m\e[K' expects argument of type '\e[01m\e[K\e[01;32m\e[Kint\e[m\e[K\e[m\e[K', but argument 2 has type '\e[01m\e[K\e[01;34m\e[Kconst char *\e[m\e[K\e[m\e[K' [\e[01;35m\e[K-Wformat=\e[m\e[K]
{ dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
- printf("hello \e[01;32m\e[K%\e[m\e[K\e[01;32m\e[Ki\e[m\e[K", \e[01;34m\e[Km\e[m\e[K\e[01;34m\e[Ks\e[m\e[K\e[01;34m\e[Kg\e[m\e[K);
- \e[01;32m\e[K~\e[m\e[K\e[01;32m\e[K^\e[m\e[K \e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K\e[01;34m\e[K~\e[m\e[K
+ printf("hello \e[01;32m\e[K%i\e[m\e[K", \e[01;34m\e[Kmsg\e[m\e[K);
+ \e[01;32m\e[K~^\e[m\e[K \e[01;34m\e[K~~~\e[m\e[K
\e[01;32m\e[K|\e[m\e[K \e[01;34m\e[K|\e[m\e[K
\e[01;32m\e[Kint\e[m\e[K \e[01;34m\e[Kconst char *\e[m\e[K
\e[32m\e[K%s\e[m\e[K