diff options
author | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-08-29 20:42:57 +0000 |
---|---|---|
committer | dmalcolm <dmalcolm@138bc75d-0d04-0410-961f-82ee72b054a4> | 2016-08-29 20:42:57 +0000 |
commit | a02b4eaefbd72ca7bbe26b9c8aad90ee18f9c506 (patch) | |
tree | 6d574e6eb977268815029f2ec08618e51a518b9a /libcpp | |
parent | 2db6ea891ce7ea8147948e48a9f45145bfcdeb5d (diff) | |
download | gcc-a02b4eaefbd72ca7bbe26b9c8aad90ee18f9c506.tar.gz |
Allow the use of ad-hoc locations for fix-it hints
Currently the fix-it validator rejects ad-hoc locations.
Fix this by calling get_pure_location on the input locations to
add_fixit_insert/replace. Doing so requires moving get_pure_location
from gcc to libcpp.
gcc/ChangeLog:
* diagnostic-show-locus.c
(selftest::test_one_liner_fixit_validation_adhoc_locations): New
function.
(selftest::test_diagnostic_show_locus_one_liner): Call it.
* input.c (get_pure_location): Move to libcpp/line-map.c.
* input.h (get_pure_location): Convert decl to an inline function
calling implementation in libcpp.
libcpp/ChangeLog:
* include/line-map.h (get_pure_location): New decl.
* line-map.c (get_pure_location): Move here, from gcc/input.c, adding
a line_maps * param.
(rich_location::add_fixit_insert): Call get_pure_location on "where".
(rich_location::add_fixit_replace): Call get_pure_location on the
end-points.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@239843 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 9 | ||||
-rw-r--r-- | libcpp/include/line-map.h | 6 | ||||
-rw-r--r-- | libcpp/line-map.c | 27 |
3 files changed, 42 insertions, 0 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 56971ad8e0c..37825f524d3 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,5 +1,14 @@ 2016-08-26 David Malcolm <dmalcolm@redhat.com> + * include/line-map.h (get_pure_location): New decl. + * line-map.c (get_pure_location): Move here, from gcc/input.c, adding + a line_maps * param. + (rich_location::add_fixit_insert): Call get_pure_location on "where". + (rich_location::add_fixit_replace): Call get_pure_location on the + end-points. + +2016-08-26 David Malcolm <dmalcolm@redhat.com> + * include/line-map.h (rich_location): Eliminate unimplemented constructor based on source_range. (rich_location::get_last_fixit_hint): New method. diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 0fc4848bf5b..d9c31deb977 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1002,6 +1002,12 @@ IS_ADHOC_LOC (source_location loc) bool pure_location_p (line_maps *set, source_location loc); +/* Given location LOC within SET, strip away any packed range information + or ad-hoc information. */ + +extern source_location get_pure_location (line_maps *set, + source_location loc); + /* Combine LOC and BLOCK, giving a combined adhoc location. */ inline source_location diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 8fe48bdbf63..f5b15867a62 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -311,6 +311,28 @@ pure_location_p (line_maps *set, source_location loc) return true; } +/* Given location LOC within SET, strip away any packed range information + or ad-hoc information. */ + +source_location +get_pure_location (line_maps *set, source_location loc) +{ + if (IS_ADHOC_LOC (loc)) + loc + = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; + + if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (set)) + return loc; + + if (loc < RESERVED_LOCATION_COUNT) + return loc; + + const line_map *map = linemap_lookup (set, loc); + const line_map_ordinary *ordmap = linemap_check_ordinary (map); + + return loc & ~((1 << ordmap->m_range_bits) - 1); +} + /* Finalize the location_adhoc_data structure. */ void location_adhoc_data_fini (struct line_maps *set) @@ -2077,6 +2099,8 @@ void rich_location::add_fixit_insert (source_location where, const char *new_content) { + where = get_pure_location (m_line_table, where); + if (reject_impossible_fixit (where)) return; @@ -2141,6 +2165,9 @@ rich_location::add_fixit_replace (source_range src_range, { linemap_assert (m_num_fixit_hints < MAX_FIXIT_HINTS); + src_range.m_start = get_pure_location (m_line_table, src_range.m_start); + src_range.m_finish = get_pure_location (m_line_table, src_range.m_finish); + if (reject_impossible_fixit (src_range.m_start)) return; if (reject_impossible_fixit (src_range.m_finish)) |