Commit e6fc8353 by Martin Liska Committed by Martin Liska

Do a refactoring in linemap (PR preprocessor/90382).

2019-05-14  Martin Liska  <mliska@suse.cz>

	PR preprocessor/90382
	* include/line-map.h (get_data_from_adhoc_loc): Add const to
	the first argument.
	(get_location_from_adhoc_loc): Likewise.
	* line-map.c(get_data_from_adhoc_loc):  Add const to
	the first argument.
	(get_location_from_adhoc_loc): Likewise.
	(get_combined_adhoc_loc): Use get_location_from_adhoc_loc
	(or get_data_from_adhoc_loc).
	(get_range_from_adhoc_loc): Likewise.
	(get_pure_location): Likewise.
	(linemap_position_for_loc_and_offset): Likewise.
	(linemap_lookup): Likewise.
	(linemap_ordinary_map_lookup): Likewise.
	(linemap_macro_map_lookup): Likewise.
	(linemap_get_expansion_line): Likewise.
	(linemap_get_expansion_filename): Likewise.
	(linemap_location_in_system_header_p): Likewise.
	(linemap_location_from_macro_expansion_p): Likewise.
	(linemap_macro_loc_to_exp_point): Likewise.
	(linemap_resolve_location): Likewise.
	(linemap_unwind_toward_expansion): Likewise.
	(linemap_unwind_to_first_non_reserved_loc): Likewise.
	(linemap_expand_location): Likewise.
	(linemap_dump_location): Likewise.

From-SVN: r271162
parent c688848d
2019-05-14 Martin Liska <mliska@suse.cz>
PR preprocessor/90382
* include/line-map.h (get_data_from_adhoc_loc): Add const to
the first argument.
(get_location_from_adhoc_loc): Likewise.
* line-map.c(get_data_from_adhoc_loc): Add const to
the first argument.
(get_location_from_adhoc_loc): Likewise.
(get_combined_adhoc_loc): Use get_location_from_adhoc_loc
(or get_data_from_adhoc_loc).
(get_range_from_adhoc_loc): Likewise.
(get_pure_location): Likewise.
(linemap_position_for_loc_and_offset): Likewise.
(linemap_lookup): Likewise.
(linemap_ordinary_map_lookup): Likewise.
(linemap_macro_map_lookup): Likewise.
(linemap_get_expansion_line): Likewise.
(linemap_get_expansion_filename): Likewise.
(linemap_location_in_system_header_p): Likewise.
(linemap_location_from_macro_expansion_p): Likewise.
(linemap_macro_loc_to_exp_point): Likewise.
(linemap_resolve_location): Likewise.
(linemap_unwind_toward_expansion): Likewise.
(linemap_unwind_to_first_non_reserved_loc): Likewise.
(linemap_expand_location): Likewise.
(linemap_dump_location): Likewise.
2019-05-07 Nathan Sidwell <nathan@acm.org> 2019-05-07 Nathan Sidwell <nathan@acm.org>
* files.c (_cpp_stack_file): Empty filenames aren't dependencies. * files.c (_cpp_stack_file): Empty filenames aren't dependencies.
......
...@@ -1054,8 +1054,8 @@ extern location_t get_combined_adhoc_loc (struct line_maps *, ...@@ -1054,8 +1054,8 @@ extern location_t get_combined_adhoc_loc (struct line_maps *,
location_t, location_t,
source_range, source_range,
void *); void *);
extern void *get_data_from_adhoc_loc (struct line_maps *, location_t); extern void *get_data_from_adhoc_loc (const struct line_maps *, location_t);
extern location_t get_location_from_adhoc_loc (struct line_maps *, extern location_t get_location_from_adhoc_loc (const struct line_maps *,
location_t); location_t);
extern source_range get_range_from_loc (line_maps *set, location_t loc); extern source_range get_range_from_loc (line_maps *set, location_t loc);
......
...@@ -163,8 +163,7 @@ get_combined_adhoc_loc (struct line_maps *set, ...@@ -163,8 +163,7 @@ get_combined_adhoc_loc (struct line_maps *set,
struct location_adhoc_data **slot; struct location_adhoc_data **slot;
if (IS_ADHOC_LOC (locus)) if (IS_ADHOC_LOC (locus))
locus locus = get_location_from_adhoc_loc (set, locus);
= set->location_adhoc_data_map.data[locus & MAX_LOCATION_T].locus;
if (locus == 0 && data == NULL) if (locus == 0 && data == NULL)
return 0; return 0;
...@@ -243,7 +242,7 @@ get_combined_adhoc_loc (struct line_maps *set, ...@@ -243,7 +242,7 @@ get_combined_adhoc_loc (struct line_maps *set,
/* Return the data for the adhoc loc. */ /* Return the data for the adhoc loc. */
void * void *
get_data_from_adhoc_loc (struct line_maps *set, location_t loc) get_data_from_adhoc_loc (const struct line_maps *set, location_t loc)
{ {
linemap_assert (IS_ADHOC_LOC (loc)); linemap_assert (IS_ADHOC_LOC (loc));
return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].data; return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].data;
...@@ -252,7 +251,7 @@ get_data_from_adhoc_loc (struct line_maps *set, location_t loc) ...@@ -252,7 +251,7 @@ get_data_from_adhoc_loc (struct line_maps *set, location_t loc)
/* Return the location for the adhoc loc. */ /* Return the location for the adhoc loc. */
location_t location_t
get_location_from_adhoc_loc (struct line_maps *set, location_t loc) get_location_from_adhoc_loc (const struct line_maps *set, location_t loc)
{ {
linemap_assert (IS_ADHOC_LOC (loc)); linemap_assert (IS_ADHOC_LOC (loc));
return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus; return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus;
...@@ -261,7 +260,7 @@ get_location_from_adhoc_loc (struct line_maps *set, location_t loc) ...@@ -261,7 +260,7 @@ get_location_from_adhoc_loc (struct line_maps *set, location_t loc)
/* Return the source_range for adhoc location LOC. */ /* Return the source_range for adhoc location LOC. */
static source_range static source_range
get_range_from_adhoc_loc (struct line_maps *set, location_t loc) get_range_from_adhoc_loc (const struct line_maps *set, location_t loc)
{ {
linemap_assert (IS_ADHOC_LOC (loc)); linemap_assert (IS_ADHOC_LOC (loc));
return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].src_range; return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].src_range;
...@@ -321,8 +320,7 @@ location_t ...@@ -321,8 +320,7 @@ location_t
get_pure_location (line_maps *set, location_t loc) get_pure_location (line_maps *set, location_t loc)
{ {
if (IS_ADHOC_LOC (loc)) if (IS_ADHOC_LOC (loc))
loc loc = get_location_from_adhoc_loc (set, loc);
= set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus;
if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (set)) if (loc >= LINEMAPS_MACRO_LOWEST_LOCATION (set))
return loc; return loc;
...@@ -872,7 +870,7 @@ linemap_position_for_loc_and_offset (struct line_maps *set, ...@@ -872,7 +870,7 @@ linemap_position_for_loc_and_offset (struct line_maps *set,
const line_map_ordinary * map = NULL; const line_map_ordinary * map = NULL;
if (IS_ADHOC_LOC (loc)) if (IS_ADHOC_LOC (loc))
loc = set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus; loc = get_location_from_adhoc_loc (set, loc);
/* This function does not support virtual locations yet. */ /* This function does not support virtual locations yet. */
if (linemap_location_from_macro_expansion_p (set, loc)) if (linemap_location_from_macro_expansion_p (set, loc))
...@@ -934,7 +932,7 @@ const struct line_map* ...@@ -934,7 +932,7 @@ const struct line_map*
linemap_lookup (struct line_maps *set, location_t line) linemap_lookup (struct line_maps *set, location_t line)
{ {
if (IS_ADHOC_LOC (line)) if (IS_ADHOC_LOC (line))
line = set->location_adhoc_data_map.data[line & MAX_LOCATION_T].locus; line = get_location_from_adhoc_loc (set, line);
if (linemap_location_from_macro_expansion_p (set, line)) if (linemap_location_from_macro_expansion_p (set, line))
return linemap_macro_map_lookup (set, line); return linemap_macro_map_lookup (set, line);
return linemap_ordinary_map_lookup (set, line); return linemap_ordinary_map_lookup (set, line);
...@@ -952,7 +950,7 @@ linemap_ordinary_map_lookup (struct line_maps *set, location_t line) ...@@ -952,7 +950,7 @@ linemap_ordinary_map_lookup (struct line_maps *set, location_t line)
const line_map_ordinary *cached, *result; const line_map_ordinary *cached, *result;
if (IS_ADHOC_LOC (line)) if (IS_ADHOC_LOC (line))
line = set->location_adhoc_data_map.data[line & MAX_LOCATION_T].locus; line = get_location_from_adhoc_loc (set, line);
if (set == NULL || line < RESERVED_LOCATION_COUNT) if (set == NULL || line < RESERVED_LOCATION_COUNT)
return NULL; return NULL;
...@@ -1000,7 +998,7 @@ linemap_macro_map_lookup (struct line_maps *set, location_t line) ...@@ -1000,7 +998,7 @@ linemap_macro_map_lookup (struct line_maps *set, location_t line)
const struct line_map_macro *cached, *result; const struct line_map_macro *cached, *result;
if (IS_ADHOC_LOC (line)) if (IS_ADHOC_LOC (line))
line = set->location_adhoc_data_map.data[line & MAX_LOCATION_T].locus; line = get_location_from_adhoc_loc (set, line);
linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set)); linemap_assert (line >= LINEMAPS_MACRO_LOWEST_LOCATION (set));
...@@ -1130,8 +1128,7 @@ linemap_get_expansion_line (struct line_maps *set, ...@@ -1130,8 +1128,7 @@ linemap_get_expansion_line (struct line_maps *set,
const line_map_ordinary *map = NULL; const line_map_ordinary *map = NULL;
if (IS_ADHOC_LOC (location)) if (IS_ADHOC_LOC (location))
location = set->location_adhoc_data_map.data[location location = get_location_from_adhoc_loc (set, location);
& MAX_LOCATION_T].locus;
if (location < RESERVED_LOCATION_COUNT) if (location < RESERVED_LOCATION_COUNT)
return 0; return 0;
...@@ -1158,8 +1155,7 @@ linemap_get_expansion_filename (struct line_maps *set, ...@@ -1158,8 +1155,7 @@ linemap_get_expansion_filename (struct line_maps *set,
const struct line_map_ordinary *map = NULL; const struct line_map_ordinary *map = NULL;
if (IS_ADHOC_LOC (location)) if (IS_ADHOC_LOC (location))
location = set->location_adhoc_data_map.data[location location = get_location_from_adhoc_loc (set, location);
& MAX_LOCATION_T].locus;
if (location < RESERVED_LOCATION_COUNT) if (location < RESERVED_LOCATION_COUNT)
return NULL; return NULL;
...@@ -1196,8 +1192,7 @@ linemap_location_in_system_header_p (struct line_maps *set, ...@@ -1196,8 +1192,7 @@ linemap_location_in_system_header_p (struct line_maps *set,
const struct line_map *map = NULL; const struct line_map *map = NULL;
if (IS_ADHOC_LOC (location)) if (IS_ADHOC_LOC (location))
location = set->location_adhoc_data_map.data[location location = get_location_from_adhoc_loc (set, location);
& MAX_LOCATION_T].locus;
if (location < RESERVED_LOCATION_COUNT) if (location < RESERVED_LOCATION_COUNT)
return false; return false;
...@@ -1240,8 +1235,7 @@ linemap_location_from_macro_expansion_p (const struct line_maps *set, ...@@ -1240,8 +1235,7 @@ linemap_location_from_macro_expansion_p (const struct line_maps *set,
location_t location) location_t location)
{ {
if (IS_ADHOC_LOC (location)) if (IS_ADHOC_LOC (location))
location = set->location_adhoc_data_map.data[location location = get_location_from_adhoc_loc (set, location);
& MAX_LOCATION_T].locus;
return IS_MACRO_LOC (location); return IS_MACRO_LOC (location);
} }
...@@ -1467,8 +1461,7 @@ linemap_macro_loc_to_exp_point (struct line_maps *set, ...@@ -1467,8 +1461,7 @@ linemap_macro_loc_to_exp_point (struct line_maps *set,
struct line_map *map; struct line_map *map;
if (IS_ADHOC_LOC (location)) if (IS_ADHOC_LOC (location))
location = set->location_adhoc_data_map.data[location location = get_location_from_adhoc_loc (set, location);
& MAX_LOCATION_T].locus;
linemap_assert (set && location >= RESERVED_LOCATION_COUNT); linemap_assert (set && location >= RESERVED_LOCATION_COUNT);
...@@ -1542,7 +1535,7 @@ linemap_resolve_location (struct line_maps *set, ...@@ -1542,7 +1535,7 @@ linemap_resolve_location (struct line_maps *set,
{ {
location_t locus = loc; location_t locus = loc;
if (IS_ADHOC_LOC (loc)) if (IS_ADHOC_LOC (loc))
locus = set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus; locus = get_location_from_adhoc_loc (set, loc);
if (locus < RESERVED_LOCATION_COUNT) if (locus < RESERVED_LOCATION_COUNT)
{ {
...@@ -1624,7 +1617,7 @@ linemap_unwind_toward_expansion (struct line_maps *set, ...@@ -1624,7 +1617,7 @@ linemap_unwind_toward_expansion (struct line_maps *set,
const struct line_map *resolved_map; const struct line_map *resolved_map;
if (IS_ADHOC_LOC (loc)) if (IS_ADHOC_LOC (loc))
loc = set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus; loc = get_location_from_adhoc_loc (set, loc);
resolved_location = resolved_location =
linemap_macro_map_loc_unwind_toward_spelling (set, macro_map, loc); linemap_macro_map_loc_unwind_toward_spelling (set, macro_map, loc);
...@@ -1664,7 +1657,7 @@ linemap_unwind_to_first_non_reserved_loc (struct line_maps *set, ...@@ -1664,7 +1657,7 @@ linemap_unwind_to_first_non_reserved_loc (struct line_maps *set,
const line_map_ordinary *map1 = NULL; const line_map_ordinary *map1 = NULL;
if (IS_ADHOC_LOC (loc)) if (IS_ADHOC_LOC (loc))
loc = set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus; loc = get_location_from_adhoc_loc (set, loc);
map0 = linemap_lookup (set, loc); map0 = linemap_lookup (set, loc);
if (!linemap_macro_expansion_map_p (map0)) if (!linemap_macro_expansion_map_p (map0))
...@@ -1709,9 +1702,8 @@ linemap_expand_location (struct line_maps *set, ...@@ -1709,9 +1702,8 @@ linemap_expand_location (struct line_maps *set,
memset (&xloc, 0, sizeof (xloc)); memset (&xloc, 0, sizeof (xloc));
if (IS_ADHOC_LOC (loc)) if (IS_ADHOC_LOC (loc))
{ {
xloc.data xloc.data = get_data_from_adhoc_loc (set, loc);
= set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].data; loc = get_location_from_adhoc_loc (set, loc);
loc = set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus;
} }
if (loc < RESERVED_LOCATION_COUNT) if (loc < RESERVED_LOCATION_COUNT)
...@@ -1815,7 +1807,7 @@ linemap_dump_location (struct line_maps *set, ...@@ -1815,7 +1807,7 @@ linemap_dump_location (struct line_maps *set,
int l = -1, c = -1, s = -1, e = -1; int l = -1, c = -1, s = -1, e = -1;
if (IS_ADHOC_LOC (loc)) if (IS_ADHOC_LOC (loc))
loc = set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus; loc = get_location_from_adhoc_loc (set, loc);
if (loc == 0) if (loc == 0)
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment