looking up a line map takes a non-constant line_maps object, which is
confusing.
This makes the caching fields mutable, so permits a constant object, as
one might expect for a lookup.
The linemaps_info_{ordinary,macro} structures are crying out to be
templatized, but that kind of turns into a rathole cleaning up the C-era
accessors and like. I punted.
committing to trunk
nathan
--
Nathan Sidwell
2019-10-15 Nathan Sidwell <nat...@acm.org>
* include/line-map.h (struct maps_info_ordinary): Make cache
mutable.
(struct maps_info_macro): Likewise.
(LINEMAPS_CACHE): Remove non-ref accessor. Constify ref accessor.
(LINEMAPS_ORDINARY_CACHE, LINEMAPS_MACRO_CACHE): Likewise.
(LINEMAPS_ORDINARY_MAP_AT, LINEMAPS_MACRO_MAP_AT): Use
LINEMAPS_USED and LINEMAPS_MAP_AT.
(linemap_lookup): Constify line_map arg.
linemap.c (linemap_ordinary_map_lookup, linemap_macro_map_lookup):
Constify line_map arg.
Index: include/line-map.h
===================================================================
--- include/line-map.h (revision 276991)
+++ include/line-map.h (working copy)
@@ -725,5 +725,5 @@ struct GTY(()) maps_info_ordinary {
unsigned int used;
- unsigned int cache;
+ mutable unsigned int cache;
};
@@ -740,5 +740,5 @@ struct GTY(()) maps_info_macro {
unsigned int used;
- unsigned int cache;
+ mutable unsigned int cache;
};
@@ -866,17 +866,6 @@ LINEMAPS_USED (line_maps *set, bool map_
linemap_lookup. MAP_KIND shall be TRUE if we are interested in
macro maps, FALSE otherwise. */
-inline unsigned int
-LINEMAPS_CACHE (const line_maps *set, bool map_kind)
-{
- if (map_kind)
- return set->info_macro.cache;
- else
- return set->info_ordinary.cache;
-}
-
-/* As above, but by reference (e.g. as an lvalue). */
-
inline unsigned int &
-LINEMAPS_CACHE (line_maps *set, bool map_kind)
+LINEMAPS_CACHE (const line_maps *set, bool map_kind)
{
if (map_kind)
@@ -928,7 +917,7 @@ inline line_map_ordinary *
LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index)
{
- linemap_assert (index >= 0);
- linemap_assert ((unsigned int)index < set->info_ordinary.used);
- return &set->info_ordinary.maps[index];
+ linemap_assert (index >= 0
+ && (unsigned int)index < LINEMAPS_USED (set, false));
+ return (line_map_ordinary *)LINEMAPS_MAP_AT (set, false, index);
}
@@ -950,14 +939,6 @@ LINEMAPS_ORDINARY_USED (const line_maps
/* Return the index of the last ordinary map that was looked up with
linemap_lookup. */
-inline unsigned int
-LINEMAPS_ORDINARY_CACHE (const line_maps *set)
-{
- return LINEMAPS_CACHE (set, false);
-}
-
-/* As above, but by reference (e.g. as an lvalue). */
-
inline unsigned int &
-LINEMAPS_ORDINARY_CACHE (line_maps *set)
+LINEMAPS_ORDINARY_CACHE (const line_maps *set)
{
return LINEMAPS_CACHE (set, false);
@@ -992,7 +973,7 @@ inline line_map_macro *
LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index)
{
- linemap_assert (index >= 0);
- linemap_assert ((unsigned int)index < set->info_macro.used);
- return &set->info_macro.maps[index];
+ linemap_assert (index >= 0
+ && (unsigned int)index < LINEMAPS_USED (set, true));
+ return (line_map_macro *)LINEMAPS_MAP_AT (set, true, index);
}
@@ -1012,16 +993,8 @@ LINEMAPS_MACRO_USED (const line_maps *se
}
-/* Returns the index of the last macro map looked up with
+/* Return the index of the last macro map that was looked up with
linemap_lookup. */
-inline unsigned int
-LINEMAPS_MACRO_CACHE (const line_maps *set)
-{
- return LINEMAPS_CACHE (set, true);
-}
-
-/* As above, but by reference (e.g. as an lvalue). */
-
inline unsigned int &
-LINEMAPS_MACRO_CACHE (line_maps *set)
+LINEMAPS_MACRO_CACHE (const line_maps *set)
{
return LINEMAPS_CACHE (set, true);
@@ -1131,5 +1104,5 @@ extern const line_map *linemap_add
function returns NULL. */
extern const line_map *linemap_lookup
- (class line_maps *, location_t);
+ (const line_maps *, location_t);
/* Returns TRUE if the line table set tracks token locations across
Index: line-map.c
===================================================================
--- line-map.c (revision 276991)
+++ line-map.c (working copy)
@@ -28,7 +28,7 @@ along with this program; see the file CO
static void trace_include (const line_maps *, const line_map_ordinary *);
-static const line_map_ordinary * linemap_ordinary_map_lookup (line_maps *,
+static const line_map_ordinary * linemap_ordinary_map_lookup (const line_maps *,
location_t);
-static const line_map_macro* linemap_macro_map_lookup (line_maps *,
+static const line_map_macro* linemap_macro_map_lookup (const line_maps *,
location_t);
static location_t linemap_macro_map_loc_to_def_point
@@ -938,5 +938,5 @@ linemap_position_for_loc_and_offset (lin
const struct line_map*
-linemap_lookup (line_maps *set, location_t line)
+linemap_lookup (const line_maps *set, location_t line)
{
if (IS_ADHOC_LOC (line))
@@ -953,5 +953,5 @@ linemap_lookup (line_maps *set, location
static const line_map_ordinary *
-linemap_ordinary_map_lookup (line_maps *set, location_t line)
+linemap_ordinary_map_lookup (const line_maps *set, location_t line)
{
unsigned int md, mn, mx;
@@ -966,5 +966,5 @@ linemap_ordinary_map_lookup (line_maps *
mn = LINEMAPS_ORDINARY_CACHE (set);
mx = LINEMAPS_ORDINARY_USED (set);
-
+
cached = LINEMAPS_ORDINARY_MAP_AT (set, mn);
/* We should get a segfault if no line_maps have been added yet. */
@@ -1001,5 +1001,5 @@ linemap_ordinary_map_lookup (line_maps *
static const line_map_macro *
-linemap_macro_map_lookup (line_maps *set, location_t line)
+linemap_macro_map_lookup (const line_maps *set, location_t line)
{
unsigned int md, mn, mx;