mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-21 14:50:57 +08:00
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
This commit is contained in:
parent
524a4c966c
commit
d41e76cf75
@ -1,3 +1,30 @@
|
||||
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>
|
||||
|
||||
* config/xtensa/xtensa.c (xtensa_expand_prologue): Update
|
||||
|
@ -168,6 +168,8 @@ static struct color_cap color_dict[] =
|
||||
{ "range2", SGR_SEQ (COLOR_FG_BLUE), 6, false },
|
||||
{ "locus", 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 }
|
||||
};
|
||||
|
||||
@ -196,7 +198,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'
|
||||
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. */
|
||||
static bool
|
||||
parse_gcc_colors (void)
|
||||
|
@ -79,24 +79,29 @@ class colorizer
|
||||
|
||||
void set_range (int range_idx) { set_state (range_idx); }
|
||||
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:
|
||||
void set_state (int state);
|
||||
void begin_state (int state);
|
||||
void finish_state (int state);
|
||||
const char *get_color_by_name (const char *);
|
||||
|
||||
private:
|
||||
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_t m_diagnostic_kind;
|
||||
int m_current_state;
|
||||
const char *m_caret_cs;
|
||||
const char *m_caret_ce;
|
||||
const char *m_range1_cs;
|
||||
const char *m_range2_cs;
|
||||
const char *m_range_ce;
|
||||
const char *m_caret;
|
||||
const char *m_range1;
|
||||
const char *m_range2;
|
||||
const char *m_fixit_insert;
|
||||
const char *m_fixit_delete;
|
||||
const char *m_stop_color;
|
||||
};
|
||||
|
||||
/* A point within a layout_range; similar to an expanded_location,
|
||||
@ -247,10 +252,11 @@ colorizer::colorizer (diagnostic_context *context,
|
||||
m_diagnostic_kind (diagnostic_kind),
|
||||
m_current_state (STATE_NORMAL_TEXT)
|
||||
{
|
||||
m_caret_ce = colorize_stop (pp_show_color (context->printer));
|
||||
m_range1_cs = colorize_start (pp_show_color (context->printer), "range1");
|
||||
m_range2_cs = colorize_start (pp_show_color (context->printer), "range2");
|
||||
m_range_ce = colorize_stop (pp_show_color (context->printer));
|
||||
m_range1 = get_color_by_name ("range1");
|
||||
m_range2 = get_color_by_name ("range2");
|
||||
m_fixit_insert = get_color_by_name ("fixit-insert");
|
||||
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
|
||||
@ -285,6 +291,14 @@ colorizer::begin_state (int state)
|
||||
case STATE_NORMAL_TEXT:
|
||||
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:
|
||||
/* Make range 0 be the same color as the "kind" text
|
||||
(error vs warning vs note). */
|
||||
@ -295,11 +309,11 @@ colorizer::begin_state (int state)
|
||||
break;
|
||||
|
||||
case 1:
|
||||
pp_string (m_context->printer, m_range1_cs);
|
||||
pp_string (m_context->printer, m_range1);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
pp_string (m_context->printer, m_range2_cs);
|
||||
pp_string (m_context->printer, m_range2);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -314,21 +328,17 @@ colorizer::begin_state (int state)
|
||||
void
|
||||
colorizer::finish_state (int state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case STATE_NORMAL_TEXT:
|
||||
break;
|
||||
if (state != STATE_NORMAL_TEXT)
|
||||
pp_string (m_context->printer, m_stop_color);
|
||||
}
|
||||
|
||||
case 0:
|
||||
pp_string (m_context->printer, m_caret_ce);
|
||||
break;
|
||||
/* Get the color code for NAME (or the empty string if
|
||||
colorization is disabled). */
|
||||
|
||||
default:
|
||||
/* Within a range. */
|
||||
gcc_assert (state > 0);
|
||||
pp_string (m_context->printer, m_range_ce);
|
||||
break;
|
||||
}
|
||||
const char *
|
||||
colorizer::get_color_by_name (const char *name)
|
||||
{
|
||||
return colorize_start (pp_show_color (m_context->printer), name);
|
||||
}
|
||||
|
||||
/* Implementation of class layout_range. */
|
||||
@ -1098,7 +1108,7 @@ layout::print_any_fixits (int row, const rich_location *richloc)
|
||||
int start_column
|
||||
= LOCATION_COLUMN (insert->get_location ());
|
||||
move_to_column (&column, start_column);
|
||||
m_colorizer.set_fixit_hint ();
|
||||
m_colorizer.set_fixit_insert ();
|
||||
pp_string (m_pp, insert->get_string ());
|
||||
m_colorizer.set_normal_text ();
|
||||
column += insert->get_length ();
|
||||
@ -1122,7 +1132,7 @@ layout::print_any_fixits (int row, const rich_location *richloc)
|
||||
|| replace->get_length () == 0)
|
||||
{
|
||||
move_to_column (&column, start_column);
|
||||
m_colorizer.set_fixit_hint ();
|
||||
m_colorizer.set_fixit_delete ();
|
||||
for (; column <= finish_column; column++)
|
||||
pp_character (m_pp, '-');
|
||||
m_colorizer.set_normal_text ();
|
||||
@ -1133,7 +1143,7 @@ layout::print_any_fixits (int row, const rich_location *richloc)
|
||||
if (replace->get_length () > 0)
|
||||
{
|
||||
move_to_column (&column, start_column);
|
||||
m_colorizer.set_fixit_hint ();
|
||||
m_colorizer.set_fixit_insert ();
|
||||
pp_string (m_pp, replace->get_string ());
|
||||
m_colorizer.set_normal_text ();
|
||||
column += replace->get_length ();
|
||||
|
@ -3343,13 +3343,13 @@ for 88-color and 256-color modes background colors.
|
||||
|
||||
The default @env{GCC_COLORS} is
|
||||
@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
|
||||
@noindent
|
||||
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} is bold. Setting @env{GCC_COLORS} to the empty
|
||||
string disables colors.
|
||||
@samp{01;36} is bold cyan, @samp{32} is green, @samp{34} is blue,
|
||||
@samp{01} is bold, and @samp{31} is red.
|
||||
Setting @env{GCC_COLORS} to the empty string disables colors.
|
||||
Supported capabilities are as follows.
|
||||
|
||||
@table @code
|
||||
@ -3365,9 +3365,13 @@ SGR substring for warning: markers.
|
||||
@vindex note GCC_COLORS @r{capability}
|
||||
SGR substring for note: markers.
|
||||
|
||||
@item caret=
|
||||
@vindex caret GCC_COLORS @r{capability}
|
||||
SGR substring for caret line.
|
||||
@item range1=
|
||||
@vindex range1 GCC_COLORS @r{capability}
|
||||
SGR substring for first additional range.
|
||||
|
||||
@item range2=
|
||||
@vindex range2 GCC_COLORS @r{capability}
|
||||
SGR substring for second additional range.
|
||||
|
||||
@item locus=
|
||||
@vindex locus GCC_COLORS @r{capability}
|
||||
@ -3377,6 +3381,16 @@ SGR substring for location information, @samp{file:line} or
|
||||
@item quote=
|
||||
@vindex quote GCC_COLORS @r{capability}
|
||||
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
|
||||
|
||||
@item -fno-diagnostics-show-option
|
||||
|
@ -1,3 +1,10 @@
|
||||
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>
|
||||
|
||||
* gcc.dg/ipa/propbits-2.c: Add -fdump-tree-optimized to dg-options.
|
||||
|
@ -161,7 +161,7 @@ void test_fixit_insert (void)
|
||||
/* { dg-begin-multiline-output "" }
|
||||
int a[2][2] = { [01;35m[K0, 1[m[K , 2, 3 };
|
||||
[01;35m[K^~~~[m[K
|
||||
[01;35m[K{[m[K [01;35m[K}[m[K
|
||||
[32m[K{[m[K [32m[K}[m[K
|
||||
{ dg-end-multiline-output "" } */
|
||||
#endif
|
||||
}
|
||||
@ -175,7 +175,7 @@ void test_fixit_remove (void)
|
||||
/* { dg-begin-multiline-output "" }
|
||||
int a;[01;35m[K;[m[K
|
||||
[01;35m[K^[m[K
|
||||
[01;35m[K-[m[K
|
||||
[31m[K-[m[K
|
||||
{ dg-end-multiline-output "" } */
|
||||
#endif
|
||||
}
|
||||
@ -189,7 +189,7 @@ void test_fixit_replace (void)
|
||||
/* { dg-begin-multiline-output "" }
|
||||
[01;35m[Kgtk_widget_showall[m[K (dlg);
|
||||
[01;35m[K^~~~~~~~~~~~~~~~~~[m[K
|
||||
[01;35m[Kgtk_widget_show_all[m[K
|
||||
[32m[Kgtk_widget_show_all[m[K
|
||||
{ dg-end-multiline-output "" } */
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user