Commit d41e76cf by David Malcolm Committed by David Malcolm

Tweak to colors of fix-it hints

Previous, fix-it hints were printed using the color of the severity
of the diagnostic (magenta for warnings, red for errors, cyan for
notes).

This patch updates fix-it hints so that replacement text is printed in
green, to better distinguish the suggested improvement from
the current code.  For example:

spellcheck-fields.cc:52:13: error: 'struct s' has no member named 'colour'; did you mean 'color'?
   return ptr->colour;  <<< RED
               ^~~~~~   <<< RED
               color    <<< GREEN

It makes sense for the underlinings that indicate deletions to
be printed in red, so the patch changes that also.  For example:

diagnostic-test-show-locus-color.c:179:9: warning: example of a removal hint
   int a;;  <<< MAGENTA
         ^  <<< MAGENTA
         -  <<< RED

gcc/ChangeLog:
	* diagnostic-color.c (color_dict): Add "fixit-insert" and
	"fixit-delete".
	(parse_gcc_colors): Update description of default GCC_COLORS.
	* diagnostic-show-locus.c (colorizer::set_fixit_hint): Delete.
	(colorizer::set_fixit_insert): New method.
	(colorizer::set_fixit_delete): New method.
	(colorizer::get_color_by_name): New method.
	(colorizer::STATE_FIXIT_INSERT): New constant.
	(colorizer::STATE_FIXIT_DELETE): New constant.
	(class colorizer): Drop "_cs" suffix from fields.  Delete "_ce"
	fields in favor of new field "m_stop_color".  Add fields
	"m_fixit_insert" and "m_fixit_delete".
	(colorizer::colorizer): Update for above changes.  Replace
	colorize_start calls with calls to get_color_by_name.
	(colorizer::begin_state): Handle STATE_FIXIT_INSERT and
	STATE_FIXIT_DELETE.  Update for field renamings.
	(colorizer::finish_state): Simplify by using m_stop_color,
	rather than multiple identical "*_ce" fields.
	(colorizer::get_color_by_name): New method.
	(layout::print_any_fixits): Print insertions and replacements
	using the "fixit-insert" color, and deletions using the
	"fixit-delete" color.
	* doc/invoke.texi (-fdiagnostics-color): Update description of
	default GCC_COLORS, and of the supported capabilities.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic-test-show-locus-color.c
	(test_fixit_insert): Update expected output.
	(test_fixit_remove): Likewise.
	(test_fixit_replace): Likewise.

From-SVN: r239787
parent 524a4c96
2016-08-26 David Malcolm <dmalcolm@redhat.com>
* diagnostic-color.c (color_dict): Add "fixit-insert" and
"fixit-delete".
(parse_gcc_colors): Update description of default GCC_COLORS.
* diagnostic-show-locus.c (colorizer::set_fixit_hint): Delete.
(colorizer::set_fixit_insert): New method.
(colorizer::set_fixit_delete): New method.
(colorizer::get_color_by_name): New method.
(colorizer::STATE_FIXIT_INSERT): New constant.
(colorizer::STATE_FIXIT_DELETE): New constant.
(class colorizer): Drop "_cs" suffix from fields. Delete "_ce"
fields in favor of new field "m_stop_color". Add fields
"m_fixit_insert" and "m_fixit_delete".
(colorizer::colorizer): Update for above changes. Replace
colorize_start calls with calls to get_color_by_name.
(colorizer::begin_state): Handle STATE_FIXIT_INSERT and
STATE_FIXIT_DELETE. Update for field renamings.
(colorizer::finish_state): Simplify by using m_stop_color,
rather than multiple identical "*_ce" fields.
(colorizer::get_color_by_name): New method.
(layout::print_any_fixits): Print insertions and replacements
using the "fixit-insert" color, and deletions using the
"fixit-delete" color.
* doc/invoke.texi (-fdiagnostics-color): Update description of
default GCC_COLORS, and of the supported capabilities.
2016-08-26 Max Filippov <jcmvbkbc@gmail.com> 2016-08-26 Max Filippov <jcmvbkbc@gmail.com>
* config/xtensa/xtensa.c (xtensa_expand_prologue): Update * config/xtensa/xtensa.c (xtensa_expand_prologue): Update
......
...@@ -168,6 +168,8 @@ static struct color_cap color_dict[] = ...@@ -168,6 +168,8 @@ static struct color_cap color_dict[] =
{ "range2", SGR_SEQ (COLOR_FG_BLUE), 6, false }, { "range2", SGR_SEQ (COLOR_FG_BLUE), 6, false },
{ "locus", SGR_SEQ (COLOR_BOLD), 5, false }, { "locus", SGR_SEQ (COLOR_BOLD), 5, false },
{ "quote", SGR_SEQ (COLOR_BOLD), 5, false }, { "quote", SGR_SEQ (COLOR_BOLD), 5, false },
{ "fixit-insert", SGR_SEQ (COLOR_FG_GREEN), 12, false },
{ "fixit-delete", SGR_SEQ (COLOR_FG_RED), 12, false },
{ NULL, NULL, 0, false } { NULL, NULL, 0, false }
}; };
...@@ -196,7 +198,9 @@ colorize_stop (bool show_color) ...@@ -196,7 +198,9 @@ colorize_stop (bool show_color)
} }
/* Parse GCC_COLORS. The default would look like: /* 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' 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'
No character escaping is needed or supported. */ No character escaping is needed or supported. */
static bool static bool
parse_gcc_colors (void) parse_gcc_colors (void)
......
...@@ -79,24 +79,29 @@ class colorizer ...@@ -79,24 +79,29 @@ class colorizer
void set_range (int range_idx) { set_state (range_idx); } void set_range (int range_idx) { set_state (range_idx); }
void set_normal_text () { set_state (STATE_NORMAL_TEXT); } void set_normal_text () { set_state (STATE_NORMAL_TEXT); }
void set_fixit_hint () { set_state (0); } void set_fixit_insert () { set_state (STATE_FIXIT_INSERT); }
void set_fixit_delete () { set_state (STATE_FIXIT_DELETE); }
private: private:
void set_state (int state); void set_state (int state);
void begin_state (int state); void begin_state (int state);
void finish_state (int state); void finish_state (int state);
const char *get_color_by_name (const char *);
private: private:
static const int STATE_NORMAL_TEXT = -1; static const int STATE_NORMAL_TEXT = -1;
static const int STATE_FIXIT_INSERT = -2;
static const int STATE_FIXIT_DELETE = -3;
diagnostic_context *m_context; diagnostic_context *m_context;
diagnostic_t m_diagnostic_kind; diagnostic_t m_diagnostic_kind;
int m_current_state; int m_current_state;
const char *m_caret_cs; const char *m_caret;
const char *m_caret_ce; const char *m_range1;
const char *m_range1_cs; const char *m_range2;
const char *m_range2_cs; const char *m_fixit_insert;
const char *m_range_ce; const char *m_fixit_delete;
const char *m_stop_color;
}; };
/* A point within a layout_range; similar to an expanded_location, /* A point within a layout_range; similar to an expanded_location,
...@@ -247,10 +252,11 @@ colorizer::colorizer (diagnostic_context *context, ...@@ -247,10 +252,11 @@ colorizer::colorizer (diagnostic_context *context,
m_diagnostic_kind (diagnostic_kind), m_diagnostic_kind (diagnostic_kind),
m_current_state (STATE_NORMAL_TEXT) m_current_state (STATE_NORMAL_TEXT)
{ {
m_caret_ce = colorize_stop (pp_show_color (context->printer)); m_range1 = get_color_by_name ("range1");
m_range1_cs = colorize_start (pp_show_color (context->printer), "range1"); m_range2 = get_color_by_name ("range2");
m_range2_cs = colorize_start (pp_show_color (context->printer), "range2"); m_fixit_insert = get_color_by_name ("fixit-insert");
m_range_ce = colorize_stop (pp_show_color (context->printer)); m_fixit_delete = get_color_by_name ("fixit-delete");
m_stop_color = colorize_stop (pp_show_color (context->printer));
} }
/* The destructor for "colorize". If colorization is on, print a code to /* The destructor for "colorize". If colorization is on, print a code to
...@@ -285,6 +291,14 @@ colorizer::begin_state (int state) ...@@ -285,6 +291,14 @@ colorizer::begin_state (int state)
case STATE_NORMAL_TEXT: case STATE_NORMAL_TEXT:
break; break;
case STATE_FIXIT_INSERT:
pp_string (m_context->printer, m_fixit_insert);
break;
case STATE_FIXIT_DELETE:
pp_string (m_context->printer, m_fixit_delete);
break;
case 0: case 0:
/* Make range 0 be the same color as the "kind" text /* Make range 0 be the same color as the "kind" text
(error vs warning vs note). */ (error vs warning vs note). */
...@@ -295,11 +309,11 @@ colorizer::begin_state (int state) ...@@ -295,11 +309,11 @@ colorizer::begin_state (int state)
break; break;
case 1: case 1:
pp_string (m_context->printer, m_range1_cs); pp_string (m_context->printer, m_range1);
break; break;
case 2: case 2:
pp_string (m_context->printer, m_range2_cs); pp_string (m_context->printer, m_range2);
break; break;
default: default:
...@@ -314,21 +328,17 @@ colorizer::begin_state (int state) ...@@ -314,21 +328,17 @@ colorizer::begin_state (int state)
void void
colorizer::finish_state (int state) colorizer::finish_state (int state)
{ {
switch (state) if (state != STATE_NORMAL_TEXT)
{ pp_string (m_context->printer, m_stop_color);
case STATE_NORMAL_TEXT: }
break;
case 0: /* Get the color code for NAME (or the empty string if
pp_string (m_context->printer, m_caret_ce); colorization is disabled). */
break;
default: const char *
/* Within a range. */ colorizer::get_color_by_name (const char *name)
gcc_assert (state > 0); {
pp_string (m_context->printer, m_range_ce); return colorize_start (pp_show_color (m_context->printer), name);
break;
}
} }
/* Implementation of class layout_range. */ /* Implementation of class layout_range. */
...@@ -1098,7 +1108,7 @@ layout::print_any_fixits (int row, const rich_location *richloc) ...@@ -1098,7 +1108,7 @@ layout::print_any_fixits (int row, const rich_location *richloc)
int start_column int start_column
= LOCATION_COLUMN (insert->get_location ()); = LOCATION_COLUMN (insert->get_location ());
move_to_column (&column, start_column); move_to_column (&column, start_column);
m_colorizer.set_fixit_hint (); m_colorizer.set_fixit_insert ();
pp_string (m_pp, insert->get_string ()); pp_string (m_pp, insert->get_string ());
m_colorizer.set_normal_text (); m_colorizer.set_normal_text ();
column += insert->get_length (); column += insert->get_length ();
...@@ -1122,7 +1132,7 @@ layout::print_any_fixits (int row, const rich_location *richloc) ...@@ -1122,7 +1132,7 @@ layout::print_any_fixits (int row, const rich_location *richloc)
|| replace->get_length () == 0) || replace->get_length () == 0)
{ {
move_to_column (&column, start_column); move_to_column (&column, start_column);
m_colorizer.set_fixit_hint (); m_colorizer.set_fixit_delete ();
for (; column <= finish_column; column++) for (; column <= finish_column; column++)
pp_character (m_pp, '-'); pp_character (m_pp, '-');
m_colorizer.set_normal_text (); m_colorizer.set_normal_text ();
...@@ -1133,7 +1143,7 @@ layout::print_any_fixits (int row, const rich_location *richloc) ...@@ -1133,7 +1143,7 @@ layout::print_any_fixits (int row, const rich_location *richloc)
if (replace->get_length () > 0) if (replace->get_length () > 0)
{ {
move_to_column (&column, start_column); move_to_column (&column, start_column);
m_colorizer.set_fixit_hint (); m_colorizer.set_fixit_insert ();
pp_string (m_pp, replace->get_string ()); pp_string (m_pp, replace->get_string ());
m_colorizer.set_normal_text (); m_colorizer.set_normal_text ();
column += replace->get_length (); column += replace->get_length ();
......
...@@ -3343,13 +3343,13 @@ for 88-color and 256-color modes background colors. ...@@ -3343,13 +3343,13 @@ for 88-color and 256-color modes background colors.
The default @env{GCC_COLORS} is The default @env{GCC_COLORS} is
@smallexample @smallexample
error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01 error=01;31:warning=01;35:note=01;36:range1=32:range2=34:locus=01:quote=01:fixit-insert=32:fixit-delete=31
@end smallexample @end smallexample
@noindent @noindent
where @samp{01;31} is bold red, @samp{01;35} is bold magenta, where @samp{01;31} is bold red, @samp{01;35} is bold magenta,
@samp{01;36} is bold cyan, @samp{01;32} is bold green and @samp{01;36} is bold cyan, @samp{32} is green, @samp{34} is blue,
@samp{01} is bold. Setting @env{GCC_COLORS} to the empty @samp{01} is bold, and @samp{31} is red.
string disables colors. Setting @env{GCC_COLORS} to the empty string disables colors.
Supported capabilities are as follows. Supported capabilities are as follows.
@table @code @table @code
...@@ -3365,9 +3365,13 @@ SGR substring for warning: markers. ...@@ -3365,9 +3365,13 @@ SGR substring for warning: markers.
@vindex note GCC_COLORS @r{capability} @vindex note GCC_COLORS @r{capability}
SGR substring for note: markers. SGR substring for note: markers.
@item caret= @item range1=
@vindex caret GCC_COLORS @r{capability} @vindex range1 GCC_COLORS @r{capability}
SGR substring for caret line. SGR substring for first additional range.
@item range2=
@vindex range2 GCC_COLORS @r{capability}
SGR substring for second additional range.
@item locus= @item locus=
@vindex locus GCC_COLORS @r{capability} @vindex locus GCC_COLORS @r{capability}
...@@ -3377,6 +3381,16 @@ SGR substring for location information, @samp{file:line} or ...@@ -3377,6 +3381,16 @@ SGR substring for location information, @samp{file:line} or
@item quote= @item quote=
@vindex quote GCC_COLORS @r{capability} @vindex quote GCC_COLORS @r{capability}
SGR substring for information printed within quotes. SGR substring for information printed within quotes.
@item fixit-insert=
@vindex fixit-insert GCC_COLORS @r{capability}
SGR substring for fix-it hints suggesting text to
be inserted or replaced.
@item fixit-delete=
@vindex fixit-delete GCC_COLORS @r{capability}
SGR substring for fix-it hints suggesting text to
be deleted.
@end table @end table
@item -fno-diagnostics-show-option @item -fno-diagnostics-show-option
......
2016-08-26 David Malcolm <dmalcolm@redhat.com>
* gcc.dg/plugin/diagnostic-test-show-locus-color.c
(test_fixit_insert): Update expected output.
(test_fixit_remove): Likewise.
(test_fixit_replace): Likewise.
2016-08-26 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> 2016-08-26 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
* gcc.dg/ipa/propbits-2.c: Add -fdump-tree-optimized to dg-options. * gcc.dg/ipa/propbits-2.c: Add -fdump-tree-optimized to dg-options.
......
...@@ -161,7 +161,7 @@ void test_fixit_insert (void) ...@@ -161,7 +161,7 @@ void test_fixit_insert (void)
/* { dg-begin-multiline-output "" } /* { dg-begin-multiline-output "" }
int a[2][2] = { 0, 1 , 2, 3 }; int a[2][2] = { 0, 1 , 2, 3 };
^~~~ ^~~~
{ } { }
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
#endif #endif
} }
...@@ -175,7 +175,7 @@ void test_fixit_remove (void) ...@@ -175,7 +175,7 @@ void test_fixit_remove (void)
/* { dg-begin-multiline-output "" } /* { dg-begin-multiline-output "" }
int a;; int a;;
^ ^
- -
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
#endif #endif
} }
...@@ -189,7 +189,7 @@ void test_fixit_replace (void) ...@@ -189,7 +189,7 @@ void test_fixit_replace (void)
/* { dg-begin-multiline-output "" } /* { dg-begin-multiline-output "" }
gtk_widget_showall (dlg); gtk_widget_showall (dlg);
^~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~
gtk_widget_show_all gtk_widget_show_all
{ dg-end-multiline-output "" } */ { dg-end-multiline-output "" } */
#endif #endif
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment