On 10/23/2015 02:41 PM, David Malcolm wrote:
A previous patch introduced the ability to print one or more ranges
for a diagnostic via a rich_location class.
Another patch generalized source_location (aka location_t) to be both
a caret and a range, and generated range information for all tokens
coming out of libcpp's lexer.
The attached patch combines these efforts by updating the
rich_location constructor for a single source_location so that it
makes use of the range within the source_location. Doing so requires
passing the line_table to the ctor, so that it can extract the range
from there.
The effect of this is that all of the various "warning", "warning_at"
"error", "error_at" diagnostics now emit underlines showing the range
of the token associated with the location_t (or input_location), for
those frontends using libcpp. Similar things should happen for
expressions in the C FE for diagnostics using EXPR_LOCATION.
A test case is added showing various token-based warnings that now
have underlines (without having to go through and add range information
to them). For example:
diagnostic-token-ranges.c: In function ‘wide_string_literal_in_asm’:
diagnostic-token-ranges.c:68:8: error: wide string literal in ‘asm’
asm (L"nop");
^~~~~~
gcc/c-family/ChangeLog:
* c-opts.c (c_common_init_options): Set
global_dc->colorize_source_p.
gcc/c/ChangeLog:
* c-decl.c (warn_defaults_to): Pass line_table to
rich_location ctor.
* c-errors.c (pedwarn_c99): Likewise.
(pedwarn_c90): Likewise.
gcc/cp/ChangeLog:
* error.c (pedwarn_cxx98): Pass line_table to
rich_location ctor.
gcc/ChangeLog:
* diagnostic.c (diagnostic_append_note): Pass line_table to
rich_location ctor.
(emit_diagnostic): Likewise.
(inform): Likewise.
(inform_n): Likewise.
(warning): Likewise.
(warning_at): Likewise.
(warning_n): Likewise.
(pedwarn): Likewise.
(permerror): Likewise.
(error): Likewise.
(error_n): Likewise.
(error_at): Likewise.
(sorry): Likewise.
(fatal_error): Likewise.
(internal_error): Likewise.
(internal_error_no_backtrace): Likewise.
(real_abort): Likewise.
* gcc-rich-location.h (gcc_rich_location::gcc_rich_location):
Likewise.
* genmatch.c (fatal_at): Likewise.
(warning_at): Likewise.
* rtl-error.c (diagnostic_for_asm): Likewise.
gcc/fortran/ChangeLog:
* error.c (gfc_warning): Pass line_table to rich_location ctor.
(gfc_warning_now_at): Likewise.
(gfc_warning_now): Likewise.
(gfc_error_now): Likewise.
(gfc_fatal_error): Likewise.
(gfc_error): Likewise.
(gfc_internal_error): Likewise.
gcc/testsuite/ChangeLog:
* gcc.dg/diagnostic-token-ranges.c: New file.
* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
(test_show_locus): Pass line_table to rich_location ctors.
(plugin_init): Remove setting of global_dc->colorize_source_p.
* gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.c:
Remove include of gcc-rich-location.h.
(get_range_for_expr): Delete.
(gcc_rich_location::add_expr): Delete.
(emit_warning): Change param from rich_location * to location_t.
Require an ad-hoc location, and extract range from it.
Use warning_at directly, without using a rich_location.
(cb_walk_tree_fn): Pass EXPR_LOCATION (arg) directly to
emit_warning, without creating a rich_location.
libcpp/ChangeLog:
* errors.c (cpp_diagnostic): Pass pfile->line_table to
rich_location ctor.
(cpp_diagnostic_with_line): Likewise.
* include/line-map.h (rich_location::rich_location): Add
line_maps * param.
* line-map.c (rich_location::rich_location): Likewise; use
it to extract the range from the source_location.
OK. Commit with prereqs.
jeff