+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
{ "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 }
};
}
/* 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)
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,
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
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). */
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:
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. */
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 ();
|| 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 ();
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 ();
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
@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}
@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
+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.
/* { dg-begin-multiline-output "" }
int a[2][2] = { \e[01;35m\e[K0, 1\e[m\e[K , 2, 3 };
\e[01;35m\e[K^~~~\e[m\e[K
- \e[01;35m\e[K{\e[m\e[K \e[01;35m\e[K}\e[m\e[K
+ \e[32m\e[K{\e[m\e[K \e[32m\e[K}\e[m\e[K
{ dg-end-multiline-output "" } */
#endif
}
/* { dg-begin-multiline-output "" }
int a;\e[01;35m\e[K;\e[m\e[K
\e[01;35m\e[K^\e[m\e[K
- \e[01;35m\e[K-\e[m\e[K
+ \e[31m\e[K-\e[m\e[K
{ dg-end-multiline-output "" } */
#endif
}
/* { dg-begin-multiline-output "" }
\e[01;35m\e[Kgtk_widget_showall\e[m\e[K (dlg);
\e[01;35m\e[K^~~~~~~~~~~~~~~~~~\e[m\e[K
- \e[01;35m\e[Kgtk_widget_show_all\e[m\e[K
+ \e[32m\e[Kgtk_widget_show_all\e[m\e[K
{ dg-end-multiline-output "" } */
#endif
}