summaryrefslogtreecommitdiff
path: root/libcpp
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2019-10-15 12:03:04 +0000
committerNathan Sidwell <nathan@gcc.gnu.org>2019-10-15 12:03:04 +0000
commit9158f0ba97ff987948cd5ce8391a546751c6dff3 (patch)
tree23993f28ac6545c0a27d83cecfcfe29a6cd27608 /libcpp
parentd8955dc0f4583317c4d6a65d17c92c538f46a60c (diff)
[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
Diffstat (limited to 'libcpp')
-rw-r--r--libcpp/ChangeLog13
-rw-r--r--libcpp/include/line-map.h53
-rw-r--r--libcpp/line-map.c12
3 files changed, 32 insertions, 46 deletions
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index e8d2e488588..670e97b039a 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -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>
* include/cpplib.h (struct cpp_options): Add dfp_constants and
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index bde5e533c2b..6f4cf5b9c95 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -724,7 +724,7 @@ struct GTY(()) maps_info_ordinary {
or equal to ALLOCATED. */
unsigned int used;
- unsigned int cache;
+ mutable unsigned int cache;
};
struct GTY(()) maps_info_macro {
@@ -739,7 +739,7 @@ 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
@@ -865,19 +865,8 @@ LINEMAPS_USED (line_maps *set, bool map_kind)
/* 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;
@@ -927,9 +916,9 @@ LINEMAPS_ORDINARY_MAPS (const line_maps *set)
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
@@ -949,16 +938,8 @@ LINEMAPS_ORDINARY_USED (const line_maps *set)
/* 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);
}
@@ -991,9 +972,9 @@ LINEMAPS_MACRO_MAPS (const line_maps *set)
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
@@ -1011,18 +992,10 @@ LINEMAPS_MACRO_USED (const line_maps *set)
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);
}
@@ -1130,7 +1103,7 @@ extern const line_map *linemap_add
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. */
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index feeb7480876..b86a116bfdd 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -27,9 +27,9 @@ along with this program; see the file COPYING3. If not see
#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);
@@ -937,7 +937,7 @@ linemap_position_for_loc_and_offset (line_maps *set,
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);
@@ -952,7 +952,7 @@ linemap_lookup (line_maps *set, location_t 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;
@@ -965,7 +965,7 @@ linemap_ordinary_map_lookup (line_maps *set, location_t line)
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))
@@ -1000,7 +1000,7 @@ linemap_ordinary_map_lookup (line_maps *set, location_t line)
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;