+2019-10-15 Nathan Sidwell <nathan@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.
+
2019-10-11 Joseph Myers <joseph@codesourcery.com>
* include/cpplib.h (struct cpp_options): Add dfp_constants and
or equal to ALLOCATED. */
unsigned int used;
- unsigned int cache;
+ mutable unsigned int cache;
};
struct GTY(()) maps_info_macro {
or equal to ALLOCATED. */
unsigned int used;
- unsigned int cache;
+ mutable unsigned int cache;
};
/* Data structure to associate a source_range together with an arbitrary
/* Returns the index of the last map that was looked up with
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)
return set->info_macro.cache;
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);
}
/* Return the number of ordinary maps allocated in the line table
/* 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);
}
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);
}
/* Returns the number of macro maps that were allocated in the line
return LINEMAPS_USED (set, true);
}
-/* 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);
}
binary search. If no line map have been allocated yet, this
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
macro expansion, FALSE otherwise. */
#include "hashtab.h"
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
(const line_map_macro *, location_t);
ordinary or a macro map), returns that map. */
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))
line = get_location_from_adhoc_loc (set, line);
binary search. */
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;
const line_map_ordinary *cached, *result;
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. */
if (line >= MAP_START_LOCATION (cached))
binary search. */
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;
const struct line_map_macro *cached, *result;