diff options
author | Jason Merrill <jason@redhat.com> | 2016-09-21 15:59:29 -0400 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2016-09-21 15:59:29 -0400 |
commit | 63cb3926080e7f7e1b93dd94911ad4720813a081 (patch) | |
tree | 452d1f9ed62885789446c7406e5160af2992acdd /libcpp/line-map.c | |
parent | c67c64efbe7082e3453f24016795af52179317b2 (diff) | |
download | gcc-63cb3926080e7f7e1b93dd94911ad4720813a081.zip gcc-63cb3926080e7f7e1b93dd94911ad4720813a081.tar.gz gcc-63cb3926080e7f7e1b93dd94911ad4720813a081.tar.bz2 |
Add from_macro_definition_at predicate for locations.
gcc/
* input.h (from_macro_definition_at): New.
libcpp/
* line-map.c (linemap_location_from_macro_definition_p): New.
* line-map.h: Declare it.
From-SVN: r240330
Diffstat (limited to 'libcpp/line-map.c')
-rw-r--r-- | libcpp/line-map.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/libcpp/line-map.c b/libcpp/line-map.c index 07e3acb..c5c42f0 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -1223,9 +1223,8 @@ linemap_location_in_system_header_p (struct line_maps *set, return false; } -/* Return TRUE if LOCATION is a source code location of a token coming - from a macro replacement-list at a macro expansion point, FALSE - otherwise. */ +/* Return TRUE if LOCATION is a source code location of a token that is part of + a macro expansion, FALSE otherwise. */ bool linemap_location_from_macro_expansion_p (const struct line_maps *set, @@ -1570,6 +1569,37 @@ linemap_resolve_location (struct line_maps *set, return loc; } +/* TRUE if LOCATION is a source code location of a token that is part of the + definition of a macro, FALSE otherwise. */ + +bool +linemap_location_from_macro_definition_p (struct line_maps *set, + source_location loc) +{ + if (IS_ADHOC_LOC (loc)) + loc = get_location_from_adhoc_loc (set, loc); + + if (!linemap_location_from_macro_expansion_p (set, loc)) + return false; + + while (true) + { + const struct line_map_macro *map + = linemap_check_macro (linemap_lookup (set, loc)); + + source_location s_loc + = linemap_macro_map_loc_unwind_toward_spelling (set, map, loc); + if (linemap_location_from_macro_expansion_p (set, s_loc)) + loc = s_loc; + else + { + source_location def_loc + = linemap_macro_map_loc_to_def_point (map, loc); + return s_loc == def_loc; + } + } +} + /* Suppose that LOC is the virtual location of a token T coming from the expansion of a macro M. This function then steps up to get the |