diff options
Diffstat (limited to 'libcpp')
-rw-r--r-- | libcpp/ChangeLog | 14 | ||||
-rw-r--r-- | libcpp/include/line-map.h | 19 | ||||
-rw-r--r-- | libcpp/line-map.cc | 33 |
3 files changed, 64 insertions, 2 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index eef6ec7..3c5bae1 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,17 @@ +2025-06-17 Jason Merrill <jason@redhat.com> + + * line-map.cc (linemap_location_from_module_p): Add. + * include/line-map.h: Declare it. + +2025-06-11 David Malcolm <dmalcolm@redhat.com> + + PR other/116792 + * include/line-map.h (typedef expanded_location): Convert to... + (struct expanded_location): ...this. + (operator==): New decl, for expanded_location. + (operator!=): Likewise. + * line-map.cc (operator==): New decl, for expanded_location. + 2025-05-07 Jakub Jelinek <jakub@redhat.com> PR preprocessor/108900 diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 75cc1ad..21a59af 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -1111,6 +1111,10 @@ extern location_t linemap_module_loc extern void linemap_module_reparent (line_maps *, location_t loc, location_t new_parent); +/* TRUE iff the location comes from a module import. */ +extern bool linemap_location_from_module_p + (const line_maps *, location_t); + /* Restore the linemap state such that the map at LWM-1 continues. Return start location of the new map. */ extern location_t linemap_module_restore @@ -1280,7 +1284,7 @@ linemap_location_before_p (const line_maps *set, return linemap_compare_locations (set, loc_a, loc_b) >= 0; } -typedef struct +struct expanded_location { /* The name of the source file involved. */ const char *file; @@ -1294,7 +1298,18 @@ typedef struct /* In a system header?. */ bool sysp; -} expanded_location; +}; + +extern bool +operator== (const expanded_location &a, + const expanded_location &b); +inline bool +operator!= (const expanded_location &a, + const expanded_location &b) +{ + return !(a == b); +} + /* This is enum is used by the function linemap_resolve_location below. The meaning of the values is explained in the comment of diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc index cf65571..33701b5 100644 --- a/libcpp/line-map.cc +++ b/libcpp/line-map.cc @@ -767,6 +767,17 @@ linemap_module_restore (line_maps *set, line_map_uint_t lwm) return 0; } +/* TRUE iff the location comes from a module import. */ + +bool +linemap_location_from_module_p (const line_maps *set, location_t loc) +{ + const line_map_ordinary *map = linemap_ordinary_map_lookup (set, loc); + while (map && map->reason != LC_MODULE) + map = linemap_included_from_linemap (set, map); + return !!map; +} + /* Returns TRUE if the line table set tracks token locations across macro expansion, FALSE otherwise. */ @@ -1949,6 +1960,28 @@ linemap_expand_location (const line_maps *set, return xloc; } +bool +operator== (const expanded_location &a, + const expanded_location &b) +{ + /* "file" can be null; for them to be equal they must both + have either null or nonnull values, and if non-null + they must compare as equal. */ + if ((a.file == nullptr) != (b.file == nullptr)) + return false; + if (a.file && strcmp (a.file, b.file)) + return false; + + if (a.line != b.line) + return false; + if (a.column != b.column) + return false; + if (a.data != b.data) + return false; + if (a.sysp != b.sysp) + return false; + return true; +} /* Dump line map at index IX in line table SET to STREAM. If STREAM is NULL, use stderr. IS_MACRO is true if the caller wants to |