From 8a64515099e64564542cbd09be7c9a21c2f580f3 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 6 Nov 2015 19:50:50 +0000 Subject: Reimplement diagnostic_show_locus, introducing rich_location classes gcc/ChangeLog: * diagnostic-color.c (color_dict): Eliminate "caret"; add "range1" and "range2". (parse_gcc_colors): Update comment to describe default GCC_COLORS. * diagnostic-core.h (warning_at_rich_loc): New declaration. (error_at_rich_loc): New declaration. (permerror_at_rich_loc): New declaration. (inform_at_rich_loc): New declaration. * diagnostic-show-locus.c (adjust_line): Delete. (struct point_state): New struct. (class colorizer): New class. (class layout_point): New class. (class layout_range): New class. (struct line_bounds): New. (class layout): New class. (colorizer::colorizer): New ctor. (colorizer::~colorizer): New dtor. (layout::layout): New ctor. (layout::print_source_line): New method. (layout::print_annotation_line): New method. (layout::get_state_at_point): New method. (layout::get_x_bound_for_row): New method. (diagnostic_show_locus): Reimplement in terms of class layout. (diagnostic_print_caret_line): Delete. * diagnostic.c (diagnostic_initialize): Replace MAX_LOCATIONS_PER_MESSAGE with rich_location::MAX_RANGES. (diagnostic_set_info_translated): Convert param from location_t to rich_location *. Eliminate calls to set_location on the message in favor of storing the rich_location ptr there. (diagnostic_set_info): Convert param from location_t to rich_location *. (diagnostic_build_prefix): Break out array into... (diagnostic_kind_color): New variable. (diagnostic_get_color_for_kind): New function. (diagnostic_report_diagnostic): Colorize the option_text using the color for the severity. (diagnostic_append_note): Update for change in signature of diagnostic_set_info. (diagnostic_append_note_at_rich_loc): New function. (emit_diagnostic): Update for change in signature of diagnostic_set_info. (inform): Likewise. (inform_at_rich_loc): New function. (inform_n): Update for change in signature of diagnostic_set_info. (warning): Likewise. (warning_at): Likewise. (warning_at_rich_loc): New function. (warning_n): Update for change in signature of diagnostic_set_info. (pedwarn): Likewise. (permerror): Likewise. (permerror_at_rich_loc): New function. (error): Update for change in signature of diagnostic_set_info. (error_n): Likewise. (error_at): Likewise. (error_at_rich_loc): New function. (sorry): Update for change in signature of diagnostic_set_info. (fatal_error): Likewise. (internal_error): Likewise. (internal_error_no_backtrace): Likewise. (source_range::debug): New function. * diagnostic.h (struct diagnostic_info): Eliminate field "override_column". Add field "richloc". (struct diagnostic_context): Add field "colorize_source_p". (diagnostic_override_column): Delete. (diagnostic_set_info): Convert param from location_t to rich_location *. (diagnostic_set_info_translated): Likewise. (diagnostic_append_note_at_rich_loc): New function. (diagnostic_num_locations): New function. (diagnostic_expand_location): Get the location from the rich_location. (diagnostic_print_caret_line): Delete. (diagnostic_get_color_for_kind): New declaration. * genmatch.c (linemap_client_expand_location_to_spelling_point): New. (error_cb): Update for change in signature of "error" callback. (fatal_at): Likewise. (warning_at): Likewise. * input.c (linemap_client_expand_location_to_spelling_point): New. * pretty-print.c (text_info::set_range): New method. (text_info::get_location): New method. * pretty-print.h (MAX_LOCATIONS_PER_MESSAGE): Eliminate this macro. (struct text_info): Eliminate "locations" array in favor of "m_richloc", a rich_location *. (textinfo::set_location): Add a "caret_p" param, and reimplement in terms of a call to set_range. (textinfo::get_location): Eliminate inline implementation in favor of an out-of-line reimplementation. (textinfo::set_range): New method. * rtl-error.c (diagnostic_for_asm): Update for change in signature of diagnostic_set_info. * tree-diagnostic.c (default_tree_printer): Update for new "caret_p" param for textinfo::set_location. * tree-pretty-print.c (percent_K_format): Likewise. gcc/c-family/ChangeLog: * c-common.c (c_cpp_error): Convert parameter from location_t to rich_location *. Eliminate the "column_override" parameter and the call to diagnostic_override_column. Update the "done_lexing" clause to set range 0 on the rich_location, rather than overwriting a location_t. * c-common.h (c_cpp_error): Convert parameter from location_t to rich_location *. Eliminate the "column_override" parameter. gcc/c/ChangeLog: * c-decl.c (warn_defaults_to): Update for change in signature of diagnostic_set_info. * c-errors.c (pedwarn_c99): Likewise. (pedwarn_c90): Likewise. * c-objc-common.c (c_tree_printer): Update for new "caret_p" param for textinfo::set_location. gcc/cp/ChangeLog: * error.c (cp_printer): Update for new "caret_p" param for textinfo::set_location. (pedwarn_cxx98): Update for change in signature of diagnostic_set_info. gcc/fortran/ChangeLog: * cpp.c (cb_cpp_error): Convert parameter from location_t to rich_location *. Eliminate the "column_override" parameter. * error.c (gfc_warning): Update for change in signature of diagnostic_set_info. (gfc_format_decoder): Update handling of %C/%L for changes to struct text_info. (gfc_diagnostic_starter): Use richloc when determining whether to print one locus or two. When handling a location that will involve a call to diagnostic_show_locus, only attempt to print the locus for the primary location, and don't call into diagnostic_print_caret_line. (gfc_warning_now_at): Update for change in signature of diagnostic_set_info. (gfc_warning_now): Likewise. (gfc_error_now): Likewise. (gfc_fatal_error): Likewise. (gfc_error): Likewise. (gfc_internal_error): Likewise. gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-show-locus-bw.c: New file. * gcc.dg/plugin/diagnostic-test-show-locus-color.c: New file. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c: New file. * gcc.dg/plugin/plugin.exp (plugin_test_list): Add the above. * lib/gcc-dg.exp: Load multiline.exp. libcpp/ChangeLog: * errors.c (cpp_diagnostic): Update for change in signature of "error" callback. (cpp_diagnostic_with_line): Likewise, calling override_column on the rich_location. * include/cpplib.h (struct cpp_callbacks): Within "error" callback, convert param from source_location to rich_location *, and drop column_override param. * include/line-map.h (struct source_range): New struct. (struct location_range): New struct. (class rich_location): New class. (linemap_client_expand_location_to_spelling_point): New declaration. * line-map.c (rich_location::rich_location): New ctors. (rich_location::lazily_expand_location): New method. (rich_location::override_column): New method. (rich_location::add_range): New methods. (rich_location::set_range): New method. From-SVN: r229884 --- gcc/fortran/ChangeLog | 21 ++++++++++ gcc/fortran/cpp.c | 13 +++---- gcc/fortran/error.c | 103 ++++++++++++++------------------------------------ 3 files changed, 54 insertions(+), 83 deletions(-) (limited to 'gcc/fortran') diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index bd3fa76..acbb1b7 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,24 @@ +2015-11-06 David Malcolm + + * cpp.c (cb_cpp_error): Convert parameter from location_t to + rich_location *. Eliminate the "column_override" parameter. + * error.c (gfc_warning): Update for change in signature of + diagnostic_set_info. + (gfc_format_decoder): Update handling of %C/%L for changes + to struct text_info. + (gfc_diagnostic_starter): Use richloc when determining whether to + print one locus or two. When handling a location that will + involve a call to diagnostic_show_locus, only attempt to print the + locus for the primary location, and don't call into + diagnostic_print_caret_line. + (gfc_warning_now_at): Update for change in signature of + diagnostic_set_info. + (gfc_warning_now): Likewise. + (gfc_error_now): Likewise. + (gfc_fatal_error): Likewise. + (gfc_error): Likewise. + (gfc_internal_error): Likewise. + 2015-11-05 Cesar Philippidis * openmp.c (gfc_match_omp_clauses): Update support for the tile diff --git a/gcc/fortran/cpp.c b/gcc/fortran/cpp.c index 7d29625..85a2c79 100644 --- a/gcc/fortran/cpp.c +++ b/gcc/fortran/cpp.c @@ -147,9 +147,9 @@ static void cb_include (cpp_reader *, source_location, const unsigned char *, static void cb_ident (cpp_reader *, source_location, const cpp_string *); static void cb_used_define (cpp_reader *, source_location, cpp_hashnode *); static void cb_used_undef (cpp_reader *, source_location, cpp_hashnode *); -static bool cb_cpp_error (cpp_reader *, int, int, location_t, unsigned int, +static bool cb_cpp_error (cpp_reader *, int, int, rich_location *, const char *, va_list *) - ATTRIBUTE_GCC_DIAG(6,0); + ATTRIBUTE_GCC_DIAG(5,0); void pp_dir_change (cpp_reader *, const char *); static int dump_macro (cpp_reader *, cpp_hashnode *, void *); @@ -1024,13 +1024,12 @@ cb_used_define (cpp_reader *pfile, source_location line ATTRIBUTE_UNUSED, /* Callback from cpp_error for PFILE to print diagnostics from the preprocessor. The diagnostic is of type LEVEL, with REASON set to the reason code if LEVEL is represents a warning, at location - LOCATION, with column number possibly overridden by COLUMN_OVERRIDE - if not zero; MSG is the translated message and AP the arguments. + RICHLOC; MSG is the translated message and AP the arguments. Returns true if a diagnostic was emitted, false otherwise. */ static bool cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason, - location_t location, unsigned int column_override, + rich_location *richloc, const char *msg, va_list *ap) { diagnostic_info diagnostic; @@ -1065,9 +1064,7 @@ cb_cpp_error (cpp_reader *pfile ATTRIBUTE_UNUSED, int level, int reason, gcc_unreachable (); } diagnostic_set_info_translated (&diagnostic, msg, ap, - location, dlevel); - if (column_override) - diagnostic_override_column (&diagnostic, column_override); + richloc, dlevel); if (reason == CPP_W_WARNING_DIRECTIVE) diagnostic_override_option_index (&diagnostic, OPT_Wcpp); ret = report_diagnostic (&diagnostic); diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c index 3825751..4b3d31c 100644 --- a/gcc/fortran/error.c +++ b/gcc/fortran/error.c @@ -773,6 +773,7 @@ gfc_warning (int opt, const char *gmsgid, va_list ap) va_copy (argp, ap); diagnostic_info diagnostic; + rich_location rich_loc (UNKNOWN_LOCATION); bool fatal_errors = global_dc->fatal_errors; pretty_printer *pp = global_dc->printer; output_buffer *tmp_buffer = pp->buffer; @@ -787,7 +788,7 @@ gfc_warning (int opt, const char *gmsgid, va_list ap) --werrorcount; } - diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, + diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING); diagnostic.option_index = opt; bool ret = report_diagnostic (&diagnostic); @@ -938,10 +939,12 @@ gfc_format_decoder (pretty_printer *pp, /* If location[0] != UNKNOWN_LOCATION means that we already processed one of %C/%L. */ int loc_num = text->get_location (0) == UNKNOWN_LOCATION ? 0 : 1; - text->set_location (loc_num, - linemap_position_for_loc_and_offset (line_table, - loc->lb->location, - offset)); + source_range range + = source_range::from_location ( + linemap_position_for_loc_and_offset (line_table, + loc->lb->location, + offset)); + text->set_range (loc_num, range, true); pp_string (pp, result[loc_num]); return true; } @@ -1024,48 +1027,21 @@ gfc_diagnostic_build_locus_prefix (diagnostic_context *context, } /* This function prints the locus (file:line:column), the diagnostic kind - (Error, Warning) and (optionally) the caret line (a source line - with '1' and/or '2' below it). + (Error, Warning) and (optionally) the relevant lines of code with + annotation lines with '1' and/or '2' below them. - With -fdiagnostic-show-caret (the default) and for valid locations, - it prints for one location: + With -fdiagnostic-show-caret (the default) it prints: - [locus]: + [locus of primary range]: some code 1 Error: Some error at (1) - for two locations that fit in the same locus line: + With -fno-diagnostic-show-caret or if the primary range is not + valid, it prints: - [locus]: - - some code and some more code - 1 2 - Error: Some error at (1) and (2) - - and for two locations that do not fit in the same locus line: - - [locus]: - - some code - 1 - [locus2]: - - some other code - 2 - Error: Some error at (1) and (2) - - With -fno-diagnostic-show-caret or if one of the locations is not - valid, it prints for one location (or for two locations that fit in - the same locus line): - - [locus]: Error: Some error at (1) and (2) - - and for two locations that do not fit in the same locus line: - - [name]:[locus]: Error: (1) - [name]:[locus2]: Error: Some error at (1) and (2) + [locus of primary range]: Error: Some error at (1) and (2) */ static void gfc_diagnostic_starter (diagnostic_context *context, @@ -1075,7 +1051,7 @@ gfc_diagnostic_starter (diagnostic_context *context, expanded_location s1 = diagnostic_expand_location (diagnostic); expanded_location s2; - bool one_locus = diagnostic_location (diagnostic, 1) == UNKNOWN_LOCATION; + bool one_locus = diagnostic->richloc->get_num_locations () < 2; bool same_locus = false; if (!one_locus) @@ -1125,35 +1101,6 @@ gfc_diagnostic_starter (diagnostic_context *context, /* If the caret line was shown, the prefix does not contain the locus. */ pp_set_prefix (context->printer, kind_prefix); - - if (one_locus || same_locus) - return; - - locus_prefix = gfc_diagnostic_build_locus_prefix (context, s2); - if (diagnostic_location (diagnostic, 1) <= BUILTINS_LOCATION) - { - /* No caret line for the second location. Override the previous - prefix with [locus2]:[prefix]. */ - pp_set_prefix (context->printer, - concat (locus_prefix, " ", kind_prefix, NULL)); - free (kind_prefix); - free (locus_prefix); - } - else - { - /* We print the caret for the second location. */ - pp_verbatim (context->printer, locus_prefix); - free (locus_prefix); - /* Fortran uses an empty line between locus and caret line. */ - pp_newline (context->printer); - s1.column = 0; /* Print only a caret line for s2. */ - diagnostic_print_caret_line (context, s2, s1, - context->caret_chars[1], '\0'); - pp_newline (context->printer); - /* If the caret line was shown, the prefix does not contain the - locus. */ - pp_set_prefix (context->printer, kind_prefix); - } } } @@ -1173,10 +1120,11 @@ gfc_warning_now_at (location_t loc, int opt, const char *gmsgid, ...) { va_list argp; diagnostic_info diagnostic; + rich_location rich_loc (loc); bool ret; va_start (argp, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &argp, loc, DK_WARNING); + diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING); diagnostic.option_index = opt; ret = report_diagnostic (&diagnostic); va_end (argp); @@ -1190,10 +1138,11 @@ gfc_warning_now (int opt, const char *gmsgid, ...) { va_list argp; diagnostic_info diagnostic; + rich_location rich_loc (UNKNOWN_LOCATION); bool ret; va_start (argp, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, + diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_WARNING); diagnostic.option_index = opt; ret = report_diagnostic (&diagnostic); @@ -1209,11 +1158,12 @@ gfc_error_now (const char *gmsgid, ...) { va_list argp; diagnostic_info diagnostic; + rich_location rich_loc (UNKNOWN_LOCATION); error_buffer.flag = true; va_start (argp, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_ERROR); + diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_ERROR); report_diagnostic (&diagnostic); va_end (argp); } @@ -1226,9 +1176,10 @@ gfc_fatal_error (const char *gmsgid, ...) { va_list argp; diagnostic_info diagnostic; + rich_location rich_loc (UNKNOWN_LOCATION); va_start (argp, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_FATAL); + diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_FATAL); report_diagnostic (&diagnostic); va_end (argp); @@ -1291,6 +1242,7 @@ gfc_error (const char *gmsgid, va_list ap) } diagnostic_info diagnostic; + rich_location richloc (UNKNOWN_LOCATION); bool fatal_errors = global_dc->fatal_errors; pretty_printer *pp = global_dc->printer; output_buffer *tmp_buffer = pp->buffer; @@ -1306,7 +1258,7 @@ gfc_error (const char *gmsgid, va_list ap) --errorcount; } - diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_ERROR); + diagnostic_set_info (&diagnostic, gmsgid, &argp, &richloc, DK_ERROR); report_diagnostic (&diagnostic); if (buffered_p) @@ -1336,9 +1288,10 @@ gfc_internal_error (const char *gmsgid, ...) { va_list argp; diagnostic_info diagnostic; + rich_location rich_loc (UNKNOWN_LOCATION); va_start (argp, gmsgid); - diagnostic_set_info (&diagnostic, gmsgid, &argp, UNKNOWN_LOCATION, DK_ICE); + diagnostic_set_info (&diagnostic, gmsgid, &argp, &rich_loc, DK_ICE); report_diagnostic (&diagnostic); va_end (argp); -- cgit v1.1