[linemap PATCH] Constify lookup
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01080.html 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. * 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. From-SVN: r276994
This commit is contained in:
parent
d8955dc0f4
commit
9158f0ba97
@ -1,3 +1,16 @@
|
|||||||
|
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>
|
2019-10-11 Joseph Myers <joseph@codesourcery.com>
|
||||||
|
|
||||||
* include/cpplib.h (struct cpp_options): Add dfp_constants and
|
* include/cpplib.h (struct cpp_options): Add dfp_constants and
|
||||||
|
@ -724,7 +724,7 @@ struct GTY(()) maps_info_ordinary {
|
|||||||
or equal to ALLOCATED. */
|
or equal to ALLOCATED. */
|
||||||
unsigned int used;
|
unsigned int used;
|
||||||
|
|
||||||
unsigned int cache;
|
mutable unsigned int cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GTY(()) maps_info_macro {
|
struct GTY(()) maps_info_macro {
|
||||||
@ -739,7 +739,7 @@ struct GTY(()) maps_info_macro {
|
|||||||
or equal to ALLOCATED. */
|
or equal to ALLOCATED. */
|
||||||
unsigned int used;
|
unsigned int used;
|
||||||
|
|
||||||
unsigned int cache;
|
mutable unsigned int cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Data structure to associate a source_range together with an arbitrary
|
/* Data structure to associate a source_range together with an arbitrary
|
||||||
@ -865,19 +865,8 @@ LINEMAPS_USED (line_maps *set, bool map_kind)
|
|||||||
/* Returns the index of the last map that was looked up with
|
/* Returns the index of the last map that was looked up with
|
||||||
linemap_lookup. MAP_KIND shall be TRUE if we are interested in
|
linemap_lookup. MAP_KIND shall be TRUE if we are interested in
|
||||||
macro maps, FALSE otherwise. */
|
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 &
|
inline unsigned int &
|
||||||
LINEMAPS_CACHE (line_maps *set, bool map_kind)
|
LINEMAPS_CACHE (const line_maps *set, bool map_kind)
|
||||||
{
|
{
|
||||||
if (map_kind)
|
if (map_kind)
|
||||||
return set->info_macro.cache;
|
return set->info_macro.cache;
|
||||||
@ -927,9 +916,9 @@ LINEMAPS_ORDINARY_MAPS (const line_maps *set)
|
|||||||
inline line_map_ordinary *
|
inline line_map_ordinary *
|
||||||
LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index)
|
LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index)
|
||||||
{
|
{
|
||||||
linemap_assert (index >= 0);
|
linemap_assert (index >= 0
|
||||||
linemap_assert ((unsigned int)index < set->info_ordinary.used);
|
&& (unsigned int)index < LINEMAPS_USED (set, false));
|
||||||
return &set->info_ordinary.maps[index];
|
return (line_map_ordinary *)LINEMAPS_MAP_AT (set, false, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the number of ordinary maps allocated in the line table
|
/* Return the number of ordinary maps allocated in the line table
|
||||||
@ -949,16 +938,8 @@ LINEMAPS_ORDINARY_USED (const line_maps *set)
|
|||||||
|
|
||||||
/* Return the index of the last ordinary map that was looked up with
|
/* Return the index of the last ordinary map that was looked up with
|
||||||
linemap_lookup. */
|
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 &
|
inline unsigned int &
|
||||||
LINEMAPS_ORDINARY_CACHE (line_maps *set)
|
LINEMAPS_ORDINARY_CACHE (const line_maps *set)
|
||||||
{
|
{
|
||||||
return LINEMAPS_CACHE (set, false);
|
return LINEMAPS_CACHE (set, false);
|
||||||
}
|
}
|
||||||
@ -991,9 +972,9 @@ LINEMAPS_MACRO_MAPS (const line_maps *set)
|
|||||||
inline line_map_macro *
|
inline line_map_macro *
|
||||||
LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index)
|
LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index)
|
||||||
{
|
{
|
||||||
linemap_assert (index >= 0);
|
linemap_assert (index >= 0
|
||||||
linemap_assert ((unsigned int)index < set->info_macro.used);
|
&& (unsigned int)index < LINEMAPS_USED (set, true));
|
||||||
return &set->info_macro.maps[index];
|
return (line_map_macro *)LINEMAPS_MAP_AT (set, true, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the number of macro maps that were allocated in the line
|
/* Returns the number of macro maps that were allocated in the line
|
||||||
@ -1011,18 +992,10 @@ LINEMAPS_MACRO_USED (const line_maps *set)
|
|||||||
return LINEMAPS_USED (set, true);
|
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. */
|
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 &
|
inline unsigned int &
|
||||||
LINEMAPS_MACRO_CACHE (line_maps *set)
|
LINEMAPS_MACRO_CACHE (const line_maps *set)
|
||||||
{
|
{
|
||||||
return LINEMAPS_CACHE (set, true);
|
return LINEMAPS_CACHE (set, true);
|
||||||
}
|
}
|
||||||
@ -1130,7 +1103,7 @@ extern const line_map *linemap_add
|
|||||||
binary search. If no line map have been allocated yet, this
|
binary search. If no line map have been allocated yet, this
|
||||||
function returns NULL. */
|
function returns NULL. */
|
||||||
extern const line_map *linemap_lookup
|
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
|
/* Returns TRUE if the line table set tracks token locations across
|
||||||
macro expansion, FALSE otherwise. */
|
macro expansion, FALSE otherwise. */
|
||||||
|
@ -27,9 +27,9 @@ along with this program; see the file COPYING3. If not see
|
|||||||
#include "hashtab.h"
|
#include "hashtab.h"
|
||||||
|
|
||||||
static void trace_include (const line_maps *, const line_map_ordinary *);
|
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);
|
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);
|
location_t);
|
||||||
static location_t linemap_macro_map_loc_to_def_point
|
static location_t linemap_macro_map_loc_to_def_point
|
||||||
(const line_map_macro *, location_t);
|
(const line_map_macro *, location_t);
|
||||||
@ -937,7 +937,7 @@ linemap_position_for_loc_and_offset (line_maps *set,
|
|||||||
ordinary or a macro map), returns that map. */
|
ordinary or a macro map), returns that map. */
|
||||||
|
|
||||||
const struct line_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))
|
if (IS_ADHOC_LOC (line))
|
||||||
line = get_location_from_adhoc_loc (set, line);
|
line = get_location_from_adhoc_loc (set, line);
|
||||||
@ -952,7 +952,7 @@ linemap_lookup (line_maps *set, location_t line)
|
|||||||
binary search. */
|
binary search. */
|
||||||
|
|
||||||
static const line_map_ordinary *
|
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;
|
unsigned int md, mn, mx;
|
||||||
const line_map_ordinary *cached, *result;
|
const line_map_ordinary *cached, *result;
|
||||||
@ -1000,7 +1000,7 @@ linemap_ordinary_map_lookup (line_maps *set, location_t line)
|
|||||||
binary search. */
|
binary search. */
|
||||||
|
|
||||||
static const line_map_macro *
|
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;
|
unsigned int md, mn, mx;
|
||||||
const struct line_map_macro *cached, *result;
|
const struct line_map_macro *cached, *result;
|
||||||
|
Loading…
Reference in New Issue
Block a user