aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authordmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2019-09-25 19:32:44 +0000
committerdmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4>2019-09-25 19:32:44 +0000
commit3770798685c6b254d8424431c477c1faed72e6bc (patch)
tree9c982d5d3ca7868104c59fbad0c96cbeb8e422df /gcc
parentf2e61afa97856a6c96f6093c13f74e447084be3a (diff)
Colorize %L and %C text to match diagnostic_show_locus (PR fortran/91426)
gcc/fortran/ChangeLog: PR fortran/91426 * error.c (curr_diagnostic): New static variable. (gfc_report_diagnostic): New static function. (gfc_warning): Replace call to diagnostic_report_diagnostic with call to gfc_report_diagnostic. (gfc_format_decoder): Colorize the text of %L and %C to match the colorization used by diagnostic_show_locus. (gfc_warning_now_at): Replace call to diagnostic_report_diagnostic with call to gfc_report_diagnostic. (gfc_warning_now): Likewise. (gfc_warning_internal): Likewise. (gfc_error_now): Likewise. (gfc_fatal_error): Likewise. (gfc_error_opt): Likewise. (gfc_internal_error): Likewise. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@276132 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/fortran/ChangeLog18
-rw-r--r--gcc/fortran/error.c44
2 files changed, 54 insertions, 8 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index cd1ca756d0f..d4946bd2bb0 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,3 +1,21 @@
+2019-09-25 David Malcolm <dmalcolm@redhat.com>
+
+ PR fortran/91426
+ * error.c (curr_diagnostic): New static variable.
+ (gfc_report_diagnostic): New static function.
+ (gfc_warning): Replace call to diagnostic_report_diagnostic with
+ call to gfc_report_diagnostic.
+ (gfc_format_decoder): Colorize the text of %L and %C to match the
+ colorization used by diagnostic_show_locus.
+ (gfc_warning_now_at): Replace call to diagnostic_report_diagnostic with
+ call to gfc_report_diagnostic.
+ (gfc_warning_now): Likewise.
+ (gfc_warning_internal): Likewise.
+ (gfc_error_now): Likewise.
+ (gfc_fatal_error): Likewise.
+ (gfc_error_opt): Likewise.
+ (gfc_internal_error): Likewise.
+
2019-09-23 Paul Thomas <pault@gcc.gnu.org>
PR fortran/91729
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c
index 68a27911c8d..a0ce7a6b190 100644
--- a/gcc/fortran/error.c
+++ b/gcc/fortran/error.c
@@ -760,6 +760,23 @@ gfc_clear_pp_buffer (output_buffer *this_buffer)
global_dc->last_location = UNKNOWN_LOCATION;
}
+/* The currently-printing diagnostic, for use by gfc_format_decoder,
+ for colorizing %C and %L. */
+
+static diagnostic_info *curr_diagnostic;
+
+/* A helper function to call diagnostic_report_diagnostic, while setting
+ curr_diagnostic for the duration of the call. */
+
+static bool
+gfc_report_diagnostic (diagnostic_info *diagnostic)
+{
+ gcc_assert (diagnostic != NULL);
+ curr_diagnostic = diagnostic;
+ bool ret = diagnostic_report_diagnostic (global_dc, diagnostic);
+ curr_diagnostic = NULL;
+ return ret;
+}
/* This is just a helper function to avoid duplicating the logic of
gfc_warning. */
@@ -789,7 +806,7 @@ gfc_warning (int opt, const char *gmsgid, va_list ap)
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
DK_WARNING);
diagnostic.option_index = opt;
- bool ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
+ bool ret = gfc_report_diagnostic (&diagnostic);
if (buffered_p)
{
@@ -954,7 +971,18 @@ gfc_format_decoder (pretty_printer *pp, text_info *text, const char *spec,
loc->lb->location,
offset);
text->set_location (loc_num, src_loc, SHOW_RANGE_WITH_CARET);
+ /* Colorize the markers to match the color choices of
+ diagnostic_show_locus (the initial location has a color given
+ by the "kind" of the diagnostic, the secondary location has
+ color "range1"). */
+ gcc_assert (curr_diagnostic != NULL);
+ const char *color
+ = (loc_num
+ ? "range1"
+ : diagnostic_get_color_for_kind (curr_diagnostic->kind));
+ pp_string (pp, colorize_start (pp_show_color (pp), color));
pp_string (pp, result[loc_num]);
+ pp_string (pp, colorize_stop (pp_show_color (pp)));
return true;
}
default:
@@ -1153,7 +1181,7 @@ gfc_warning_now_at (location_t loc, int opt, const char *gmsgid, ...)
va_start (argp, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING);
diagnostic.option_index = opt;
- ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
+ ret = gfc_report_diagnostic (&diagnostic);
va_end (argp);
return ret;
}
@@ -1172,7 +1200,7 @@ gfc_warning_now (int opt, const char *gmsgid, ...)
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
DK_WARNING);
diagnostic.option_index = opt;
- ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
+ ret = gfc_report_diagnostic (&diagnostic);
va_end (argp);
return ret;
}
@@ -1191,7 +1219,7 @@ gfc_warning_internal (int opt, const char *gmsgid, ...)
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc,
DK_WARNING);
diagnostic.option_index = opt;
- ret = diagnostic_report_diagnostic (global_dc, &diagnostic);
+ ret = gfc_report_diagnostic (&diagnostic);
va_end (argp);
return ret;
}
@@ -1209,7 +1237,7 @@ gfc_error_now (const char *gmsgid, ...)
va_start (argp, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_ERROR);
- diagnostic_report_diagnostic (global_dc, &diagnostic);
+ gfc_report_diagnostic (&diagnostic);
va_end (argp);
}
@@ -1225,7 +1253,7 @@ gfc_fatal_error (const char *gmsgid, ...)
va_start (argp, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_FATAL);
- diagnostic_report_diagnostic (global_dc, &diagnostic);
+ gfc_report_diagnostic (&diagnostic);
va_end (argp);
gcc_unreachable ();
@@ -1310,7 +1338,7 @@ gfc_error_opt (int opt, const char *gmsgid, va_list ap)
}
diagnostic_set_info (&diagnostic, gmsgid, &argp, &richloc, DK_ERROR);
- diagnostic_report_diagnostic (global_dc, &diagnostic);
+ gfc_report_diagnostic (&diagnostic);
if (buffered_p)
{
@@ -1360,7 +1388,7 @@ gfc_internal_error (const char *gmsgid, ...)
va_start (argp, gmsgid);
diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_ICE);
- diagnostic_report_diagnostic (global_dc, &diagnostic);
+ gfc_report_diagnostic (&diagnostic);
va_end (argp);
gcc_unreachable ();