diff options
author | David Malcolm <dmalcolm@redhat.com> | 2015-05-19 13:18:01 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2015-05-19 13:18:01 +0000 |
commit | 0e50b62468123005202598f2a88b59f9ca695eb8 (patch) | |
tree | e2d180805e415627804e234a9039e9ff18e5130e /libcpp/line-map.c | |
parent | 49c65434500d0bcd66bb0f3cea11b0fe1da6e130 (diff) | |
download | gcc-0e50b62468123005202598f2a88b59f9ca695eb8.zip gcc-0e50b62468123005202598f2a88b59f9ca695eb8.tar.gz gcc-0e50b62468123005202598f2a88b59f9ca695eb8.tar.bz2 |
Replace line_map union with C++ class hierarchy
gcc/ChangeLog:
* diagnostic.c (diagnostic_report_current_module): Strengthen
local "new_map" from const line_map * to
const line_map_ordinary *.
* genmatch.c (error_cb): Likewise for local "map".
(output_line_directive): Likewise for local "map".
* input.c (expand_location_1): Likewise for local "map".
Pass NULL rather than &map to
linemap_unwind_to_first_non_reserved_loc, since the value is never
read from there, and the value written back not read from here.
(is_location_from_builtin_token): Strengthen local "map" from
const line_map * to const line_map_ordinary *.
(dump_location_info): Strengthen locals "map" from
line_map *, one to const line_map_ordinary *, the other
to const line_map_macro *.
* tree-diagnostic.c (loc_map_pair): Strengthen field "map" from
const line_map * to const line_map_macro *.
(maybe_unwind_expanded_macro_loc): Add a call to
linemap_check_macro when writing to the "map" field of the
loc_map_pair.
Introduce local const line_map_ordinary * "ord_map", using it in
place of "map" in the part of the function where we know we have
an ordinary map. Strengthen local "m" from const line_map * to
const line_map_ordinary *.
gcc/ada/ChangeLog:
* gcc-interface/trans.c (Sloc_to_locus1): Strenghthen local "map"
from line_map * to line_map_ordinary *.
gcc/c-family/ChangeLog:
* c-common.h (fe_file_change): Strengthen param from
const line_map * to const line_map_ordinary *.
(pp_file_change): Likewise.
* c-lex.c (fe_file_change): Likewise.
(cb_define): Use linemap_check_ordinary when invoking
SOURCE_LINE.
(cb_undef): Likewise.
* c-opts.c (c_finish_options): Use linemap_check_ordinary when
invoking cb_file_change.
(c_finish_options): Likewise.
(push_command_line_include): Likewise.
(cb_file_change): Strengthen param "new_map" from
const line_map * to const line_map_ordinary *.
* c-ppoutput.c (cb_define): Likewise for local "map".
(pp_file_change): Likewise for param "map" and local "from".
gcc/fortran/ChangeLog:
* cpp.c (maybe_print_line): Strengthen local "map" from
const line_map * to const line_map_ordinary *.
(cb_file_change): Likewise for param "map" and local "from".
(cb_line_change): Likewise for local "map".
libcpp/ChangeLog:
* directives.c (do_line): Strengthen local "map" from
const line_map * to const line_map_ordinary *.
(do_linemarker): Likewise.
(_cpp_do_file_change): Assert that we're not dealing with
a macro map. Introduce local "ord_map" via a call to
linemap_check_ordinary, guarded within the check for
non-NULL. Use it for typesafety.
* files.c (cpp_make_system_header): Strengthen local "map" from
const line_map * to const line_map_ordinary *.
* include/cpplib.h (struct cpp_callbacks): Likewise for second
parameter of "file_change" callback.
* include/line-map.h (struct line_map): Convert from a struct
containing a union to a base class.
(struct line_map_ordinary): Convert to a subclass of line_map.
(struct line_map_macro): Likewise.
(linemap_check_ordinary): Strengthen return type from line_map *
to line_map_ordinary *, and add a const-variant.
(linemap_check_macro): New pair of functions.
(ORDINARY_MAP_STARTING_LINE_NUMBER): Strengthen param from
const line_map * to const line_map_ordinary *, eliminating call
to linemap_check_ordinary. Likewise for the non-const variant.
(ORDINARY_MAP_INCLUDER_FILE_INDEX): Likewise.
(ORDINARY_MAP_IN_SYSTEM_HEADER_P): Likewise.
(ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): Likewise.
(ORDINARY_MAP_FILE_NAME): Likewise.
(MACRO_MAP_MACRO): Strengthen param from const line_map * to
const line_map_macro *. Likewise for the non-const variant.
(MACRO_MAP_NUM_MACRO_TOKENS): Likewise.
(MACRO_MAP_LOCATIONS): Likewise.
(MACRO_MAP_EXPANSION_POINT_LOCATION): Likewise.
(struct maps_info): Replace with...
(struct maps_info_ordinary):...this and...
(struct maps_info_macro): ...this.
(struct line_maps): Convert fields "info_ordinary" and
"info_macro" to the above new structs.
(LINEMAPS_MAP_INFO): Delete both functions.
(LINEMAPS_MAPS): Likewise.
(LINEMAPS_ALLOCATED): Rewrite both variants to avoid using
LINEMAPS_MAP_INFO.
(LINEMAPS_USED): Likewise.
(LINEMAPS_CACHE): Likewise.
(LINEMAPS_MAP_AT): Likewise.
(LINEMAPS_ORDINARY_MAPS): Strengthen return type from line_map *
to line_map_ordinary *.
(LINEMAPS_ORDINARY_MAP_AT): Likewise.
(LINEMAPS_LAST_ORDINARY_MAP): Likewise.
(LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP): Likewise.
(LINEMAPS_MACRO_MAPS): Strengthen return type from line_map * to
line_map_macro *.
(LINEMAPS_MACRO_MAP_AT): Likewise.
(LINEMAPS_LAST_MACRO_MAP): Likewise.
(LINEMAPS_LAST_ALLOCATED_MACRO_MAP): Likewise.
(linemap_map_get_macro_name): Strengthen param from
const line_map * to const line_map_macro *.
(SOURCE_LINE): Strengthen first param from const line_map * to
const line_map_ordinary *, removing call to
linemap_check_ordinary.
(SOURCE_COLUMN): Likewise.
(LAST_SOURCE_LINE_LOCATION): Likewise.
(LAST_SOURCE_LINE): Strengthen first param from const line_map *
to const line_map_ordinary *.
(LAST_SOURCE_COLUMN): Likewise.
(INCLUDED_FROM): Strengthen return type from line_map * to
line_map_ordinary *., and second param from const line_map *
to const line_map_ordinary *, removing call to
linemap_check_ordinary.
(MAIN_FILE_P): Strengthen param from const line_map * to
const line_map_ordinary *, removing call to
linemap_check_ordinary.
(linemap_position_for_line_and_column): Strengthen param from
const line_map * to const line_map_ordinary *.
(LINEMAP_FILE): Strengthen param from const line_map * to
const line_map_ordinary *, removing call to
linemap_check_ordinary.
(LINEMAP_LINE): Likewise.
(LINEMAP_SYSP): Likewise.
(linemap_resolve_location): Strengthen final param from
const line_map ** to const line_map_ordinary **.
* internal.h (CPP_INCREMENT_LINE): Likewise for local "map".
(linemap_enter_macro): Strengthen return type from
const line_map * to const line_map_macro *.
(linemap_add_macro_token): Likewise for first param.
* line-map.c (linemap_check_files_exited): Strengthen local "map"
from const line_map * to const line_map_ordinary *.
(new_linemap): Introduce local "map_size" and use it when
calculating how large the buffer should be. Rewrite based
on change of info_macro and info_ordinary into distinct types.
(linemap_add): Strengthen locals "map" and "from" from line_map *
to line_map_ordinary *.
(linemap_enter_macro): Strengthen return type from
const line_map * to const line_map_macro *, and local "map" from
line_map * to line_map_macro *.
(linemap_add_macro_token): Strengthen param "map" from
const line_map * to const line_map_macro *.
(linemap_line_start): Strengthen local "map" from line_map * to
line_map_ordinary *.
(linemap_position_for_column): Likewise.
(linemap_position_for_line_and_column): Strengthen first param
from const line_map * to const line_map_ordinary *.
(linemap_position_for_loc_and_offset): Strengthen local "map" from
const line_map * to const line_map_ordinary *.
(linemap_ordinary_map_lookup): Likewise for return type and locals
"cached" and "result".
(linemap_macro_map_lookup): Strengthen return type and locals
"cached" and "result" from const line_map * to
const line_map_macro *.
(linemap_macro_map_loc_to_exp_point): Likewise for param "map".
(linemap_macro_map_loc_to_def_point): Likewise.
(linemap_macro_map_loc_unwind_toward_spelling): Likewise.
(linemap_get_expansion_line): Strengthen local "map" from
const line_map * to const line_map_ordinary *.
(linemap_get_expansion_filename): Likewise.
(linemap_map_get_macro_name): Strengthen param from
const line_map * to const line_map_macro *.
(linemap_location_in_system_header_p): Add call to
linemap_check_ordinary in region guarded by
!linemap_macro_expansion_map_p. Introduce local "macro_map" via
linemap_check_macro in other region, using it in place of "map"
for typesafety.
(first_map_in_common_1): Add calls to linemap_check_macro.
(trace_include): Strengthen param "map" from const line_map * to
const line_map_ordinary *.
(linemap_macro_loc_to_spelling_point): Strengthen final param from
const line_map ** to const line_map_ordinary **. Replace a
C-style cast with a const_cast, and add calls to
linemap_check_macro and linemap_check_ordinary.
(linemap_macro_loc_to_def_point): Likewise.
(linemap_macro_loc_to_exp_point): Likewise.
(linemap_resolve_location): Strengthen final param from
const line_map ** to const line_map_ordinary **.
(linemap_unwind_toward_expansion): Introduce local "macro_map" via
a checked cast and use it in place of *map.
(linemap_unwind_to_first_non_reserved_loc): Strengthen local
"map1" from const line_map * to const line_map_ordinary *.
(linemap_expand_location): Introduce local "ord_map" via a checked
cast and use it in place of map.
(linemap_dump): Make local "map" const. Strengthen local
"includer_map" from line_map * to const line_map_ordinary *.
Introduce locals "ord_map" and "macro_map" via checked casts and
use them in place of "map" for typesafety.
(linemap_dump_location): Strengthen local "map" from
const line_map * to const line_map_ordinary *.
(linemap_get_file_highest_location): Update for elimination of
union.
(linemap_get_statistics): Strengthen local "cur_map" from
line_map * to const line_map_macro *. Update uses of sizeof to
use the appropriate line_map subclasses.
* macro.c (_cpp_warn_if_unused_macro): Add call to
linemap_check_ordinary.
(builtin_macro): Strengthen local "map" from const line_map * to
const line_map_macro *.
(enter_macro_context): Likewise.
(replace_args): Likewise.
(tokens_buff_put_token_to): Likewise for param "map".
(tokens_buff_add_token): Likewise.
From-SVN: r223365
Diffstat (limited to 'libcpp/line-map.c')
-rw-r--r-- | libcpp/line-map.c | 237 |
1 files changed, 136 insertions, 101 deletions
diff --git a/libcpp/line-map.c b/libcpp/line-map.c index fd16c24..e262df4 100644 --- a/libcpp/line-map.c +++ b/libcpp/line-map.c @@ -26,25 +26,25 @@ along with this program; see the file COPYING3. If not see #include "internal.h" #include "hashtab.h" -static void trace_include (const struct line_maps *, const struct line_map *); -static const struct line_map * linemap_ordinary_map_lookup (struct line_maps *, - source_location); -static const struct line_map* linemap_macro_map_lookup (struct line_maps *, - source_location); +static void trace_include (const struct line_maps *, const line_map_ordinary *); +static const line_map_ordinary * linemap_ordinary_map_lookup (struct line_maps *, + source_location); +static const line_map_macro* linemap_macro_map_lookup (struct line_maps *, + source_location); static source_location linemap_macro_map_loc_to_def_point -(const struct line_map*, source_location); +(const line_map_macro *, source_location); static source_location linemap_macro_map_loc_unwind_toward_spelling -(const struct line_map*, source_location); +(const line_map_macro *, source_location); static source_location linemap_macro_map_loc_to_exp_point -(const struct line_map*, source_location); +(const line_map_macro *, source_location); static source_location linemap_macro_loc_to_spelling_point -(struct line_maps *, source_location, const struct line_map **); +(struct line_maps *, source_location, const line_map_ordinary **); static source_location linemap_macro_loc_to_def_point (struct line_maps *, source_location, - const struct line_map **); + const line_map_ordinary **); static source_location linemap_macro_loc_to_exp_point (struct line_maps *, source_location, - const struct line_map **); + const line_map_ordinary **); /* Counters defined in macro.c. */ extern unsigned num_expanded_macros_counter; @@ -191,7 +191,7 @@ linemap_init (struct line_maps *set, void linemap_check_files_exited (struct line_maps *set) { - const struct line_map *map; + const line_map_ordinary *map; /* Depending upon whether we are handling preprocessed input or not, this can be a user error or an ICE. */ for (map = LINEMAPS_LAST_ORDINARY_MAP (set); @@ -227,6 +227,10 @@ new_linemap (struct line_maps *set, line_map_round_alloc_size_func round_alloc_size = set->round_alloc_size; + size_t map_size = (macro_map_p + ? sizeof (line_map_macro) + : sizeof (line_map_ordinary)); + /* We are going to execute some dance to try to reduce the overhead of the memory allocator, in case we are using the ggc-page.c one. @@ -237,7 +241,7 @@ new_linemap (struct line_maps *set, alloc_size = (2 * LINEMAPS_ALLOCATED (set, macro_map_p) + 256) - * sizeof (struct line_map); + * map_size; /* Get the actual size of memory that is going to be allocated by the allocator. */ @@ -248,25 +252,37 @@ new_linemap (struct line_maps *set, Let's get back to the number of macro map that amounts to. */ LINEMAPS_ALLOCATED (set, macro_map_p) = - alloc_size / (sizeof (struct line_map)); + alloc_size / map_size; /* And now let's really do the re-allocation. */ - LINEMAPS_MAPS (set, macro_map_p) = - (struct line_map *) (*reallocator) - (LINEMAPS_MAPS (set, macro_map_p), - (LINEMAPS_ALLOCATED (set, macro_map_p) - * sizeof (struct line_map))); - - result = - &LINEMAPS_MAPS (set, macro_map_p)[LINEMAPS_USED (set, macro_map_p)]; + if (macro_map_p) + { + set->info_macro.maps + = (line_map_macro *) (*reallocator) (set->info_macro.maps, + (LINEMAPS_ALLOCATED (set, macro_map_p) + * map_size)); + result = &set->info_macro.maps[LINEMAPS_USED (set, macro_map_p)]; + } + else + { + set->info_ordinary.maps = + (line_map_ordinary *) (*reallocator) (set->info_ordinary.maps, + (LINEMAPS_ALLOCATED (set, macro_map_p) + * map_size)); + result = &set->info_ordinary.maps[LINEMAPS_USED (set, macro_map_p)]; + } memset (result, 0, ((LINEMAPS_ALLOCATED (set, macro_map_p) - LINEMAPS_USED (set, macro_map_p)) - * sizeof (struct line_map))); + * map_size)); } else - result = - &LINEMAPS_MAPS (set, macro_map_p)[LINEMAPS_USED (set, macro_map_p)]; + { + if (macro_map_p) + result = &set->info_macro.maps[LINEMAPS_USED (set, macro_map_p)]; + else + result = &set->info_ordinary.maps[LINEMAPS_USED (set, macro_map_p)]; + } LINEMAPS_USED (set, macro_map_p)++; @@ -291,7 +307,6 @@ const struct line_map * linemap_add (struct line_maps *set, enum lc_reason reason, unsigned int sysp, const char *to_file, linenum_type to_line) { - struct line_map *map; source_location start_location = set->highest_location + 1; linemap_assert (!(LINEMAPS_ORDINARY_USED (set) @@ -311,7 +326,8 @@ linemap_add (struct line_maps *set, enum lc_reason reason, return NULL; } - map = new_linemap (set, reason); + linemap_assert (reason != LC_ENTER_MACRO); + line_map_ordinary *map = linemap_check_ordinary (new_linemap (set, reason)); if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM) to_file = "<stdin>"; @@ -325,7 +341,7 @@ linemap_add (struct line_maps *set, enum lc_reason reason, location inside the "includer" right after the #include "included", this variable points the map in use right before the #include "included", inside the same "includer" file. */ - struct line_map *from; + line_map_ordinary *from; bool error; if (MAIN_FILE_P (map - 1)) @@ -365,7 +381,6 @@ linemap_add (struct line_maps *set, enum lc_reason reason, } } - linemap_assert (reason != LC_ENTER_MACRO); ORDINARY_MAP_IN_SYSTEM_HEADER_P (map) = sysp; MAP_START_LOCATION (map) = start_location; ORDINARY_MAP_FILE_NAME (map) = to_file; @@ -429,11 +444,11 @@ linemap_tracks_macro_expansion_locs_p (struct line_maps *set) this function cannot encode {line,column} pairs into locations of macro tokens anymore. */ -const struct line_map * +const line_map_macro * linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node, source_location expansion, unsigned int num_tokens) { - struct line_map *map; + line_map_macro *map; source_location start_location; /* Cast away extern "C" from the type of xrealloc. */ line_map_realloc reallocator = (set->reallocator @@ -447,7 +462,7 @@ linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node, /* We ran out of macro map space. */ return NULL; - map = new_linemap (set, LC_ENTER_MACRO); + map = linemap_check_macro (new_linemap (set, LC_ENTER_MACRO)); MAP_START_LOCATION (map) = start_location; MACRO_MAP_MACRO (map) = macro_node; @@ -489,7 +504,7 @@ linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node, replaces. */ source_location -linemap_add_macro_token (const struct line_map *map, +linemap_add_macro_token (const line_map_macro *map, unsigned int token_no, source_location orig_loc, source_location orig_parm_replacement_loc) @@ -516,7 +531,7 @@ source_location linemap_line_start (struct line_maps *set, linenum_type to_line, unsigned int max_column_hint) { - struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (set); + line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (set); source_location highest = set->highest_location; source_location r; linenum_type last_line = @@ -559,11 +574,12 @@ linemap_line_start (struct line_maps *set, linenum_type to_line, if (line_delta < 0 || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map) || SOURCE_COLUMN (map, highest) >= (1U << column_bits)) - map = (struct line_map *) linemap_add (set, LC_RENAME, - ORDINARY_MAP_IN_SYSTEM_HEADER_P - (map), - ORDINARY_MAP_FILE_NAME (map), - to_line); + map = linemap_check_ordinary + (const_cast <line_map *> + (linemap_add (set, LC_RENAME, + ORDINARY_MAP_IN_SYSTEM_HEADER_P (map), + ORDINARY_MAP_FILE_NAME (map), + to_line))); SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map, column_bits); r = (MAP_START_LOCATION (map) + ((to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (map)) @@ -607,7 +623,7 @@ linemap_position_for_column (struct line_maps *set, unsigned int to_column) } else { - struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (set); + line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (set); r = linemap_line_start (set, SOURCE_LINE (map, r), to_column + 50); } } @@ -621,16 +637,16 @@ linemap_position_for_column (struct line_maps *set, unsigned int to_column) column. */ source_location -linemap_position_for_line_and_column (const struct line_map *map, +linemap_position_for_line_and_column (const line_map_ordinary *ord_map, linenum_type line, unsigned column) { - linemap_assert (ORDINARY_MAP_STARTING_LINE_NUMBER (map) <= line); + linemap_assert (ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map) <= line); - return (MAP_START_LOCATION (map) - + ((line - ORDINARY_MAP_STARTING_LINE_NUMBER (map)) - << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map)) - + (column & ((1 << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map)) - 1))); + return (MAP_START_LOCATION (ord_map) + + ((line - ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map)) + << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (ord_map)) + + (column & ((1 << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (ord_map)) - 1))); } /* Encode and return a source_location starting from location LOC and @@ -642,7 +658,7 @@ linemap_position_for_loc_and_offset (struct line_maps *set, source_location loc, unsigned int offset) { - const struct line_map * map = NULL; + const line_map_ordinary * map = NULL; /* This function does not support virtual locations yet. */ if (linemap_assert_fails @@ -671,7 +687,8 @@ linemap_position_for_loc_and_offset (struct line_maps *set, return loc; offset += SOURCE_COLUMN (map, loc); - if (linemap_assert_fails (offset < (1u << map->d.ordinary.column_bits))) + if (linemap_assert_fails + (offset < (1u << map->column_bits))) return loc; source_location r = @@ -703,11 +720,11 @@ linemap_lookup (struct line_maps *set, source_location line) monotonic increasing, and so the list is sorted and we can use a binary search. */ -static const struct line_map * +static const line_map_ordinary * linemap_ordinary_map_lookup (struct line_maps *set, source_location line) { unsigned int md, mn, mx; - const struct line_map *cached, *result; + const line_map_ordinary *cached, *result; if (IS_ADHOC_LOC (line)) line = set->location_adhoc_data_map.data[line & MAX_SOURCE_LOCATION].locus; @@ -751,11 +768,11 @@ linemap_ordinary_map_lookup (struct line_maps *set, source_location line) monotonic decreasing, and so the list is sorted and we can use a binary search. */ -static const struct line_map* +static const line_map_macro * linemap_macro_map_lookup (struct line_maps *set, source_location line) { unsigned int md, mn, mx; - const struct line_map *cached, *result; + const struct line_map_macro *cached, *result; if (IS_ADHOC_LOC (line)) line = set->location_adhoc_data_map.data[line & MAX_SOURCE_LOCATION].locus; @@ -811,7 +828,7 @@ linemap_macro_expansion_map_p (const struct line_map *map) line-map.h to understand what a macro expansion point is. */ static source_location -linemap_macro_map_loc_to_exp_point (const struct line_map *map, +linemap_macro_map_loc_to_exp_point (const line_map_macro *map, source_location location ATTRIBUTE_UNUSED) { linemap_assert (linemap_macro_expansion_map_p (map) @@ -831,7 +848,7 @@ linemap_macro_map_loc_to_exp_point (const struct line_map *map, macro. */ static source_location -linemap_macro_map_loc_to_def_point (const struct line_map *map, +linemap_macro_map_loc_to_def_point (const line_map_macro *map, source_location location) { unsigned token_no; @@ -855,7 +872,7 @@ linemap_macro_map_loc_to_def_point (const struct line_map *map, In other words, this returns the xI location presented in the comments of line_map_macro above. */ source_location -linemap_macro_map_loc_unwind_toward_spelling (const struct line_map* map, +linemap_macro_map_loc_unwind_toward_spelling (const line_map_macro* map, source_location location) { unsigned token_no; @@ -882,7 +899,7 @@ int linemap_get_expansion_line (struct line_maps *set, source_location location) { - const struct line_map *map = NULL; + const line_map_ordinary *map = NULL; if (IS_ADHOC_LOC (location)) location = set->location_adhoc_data_map.data[location @@ -910,7 +927,7 @@ const char* linemap_get_expansion_filename (struct line_maps *set, source_location location) { - const struct line_map *map = NULL; + const struct line_map_ordinary *map = NULL; if (IS_ADHOC_LOC (location)) location = set->location_adhoc_data_map.data[location @@ -928,7 +945,7 @@ linemap_get_expansion_filename (struct line_maps *set, /* Return the name of the macro associated to MACRO_MAP. */ const char* -linemap_map_get_macro_name (const struct line_map* macro_map) +linemap_map_get_macro_name (const line_map_macro *macro_map) { linemap_assert (macro_map && linemap_macro_expansion_map_p (macro_map)); return (const char*) NODE_NAME (MACRO_MAP_MACRO (macro_map)); @@ -965,16 +982,18 @@ linemap_location_in_system_header_p (struct line_maps *set, { if (!linemap_macro_expansion_map_p (map)) /* It's a normal token. */ - return LINEMAP_SYSP (map); + return LINEMAP_SYSP (linemap_check_ordinary (map)); else { + const line_map_macro *macro_map = linemap_check_macro (map); + /* It's a token resulting from a macro expansion. */ source_location loc = - linemap_macro_map_loc_unwind_toward_spelling (map, location); + linemap_macro_map_loc_unwind_toward_spelling (macro_map, location); if (loc < RESERVED_LOCATION_COUNT) /* This token might come from a built-in macro. Let's look at where that macro got expanded. */ - location = linemap_macro_map_loc_to_exp_point (map, location); + location = linemap_macro_map_loc_to_exp_point (macro_map, location); else location = loc; } @@ -1025,12 +1044,14 @@ first_map_in_common_1 (struct line_maps *set, { if (MAP_START_LOCATION (map0) < MAP_START_LOCATION (map1)) { - l0 = linemap_macro_map_loc_to_exp_point (map0, l0); + l0 = linemap_macro_map_loc_to_exp_point (linemap_check_macro (map0), + l0); map0 = linemap_lookup (set, l0); } else { - l1 = linemap_macro_map_loc_to_exp_point (map1, l1); + l1 = linemap_macro_map_loc_to_exp_point (linemap_check_macro (map1), + l1); map1 = linemap_lookup (set, l1); } } @@ -1120,7 +1141,7 @@ linemap_compare_locations (struct line_maps *set, /* Print an include trace, for e.g. the -H option of the preprocessor. */ static void -trace_include (const struct line_maps *set, const struct line_map *map) +trace_include (const struct line_maps *set, const line_map_ordinary *map) { unsigned int i = set->depth; @@ -1138,7 +1159,7 @@ trace_include (const struct line_maps *set, const struct line_map *map) static source_location linemap_macro_loc_to_spelling_point (struct line_maps *set, source_location location, - const struct line_map **original_map) + const line_map_ordinary **original_map) { struct line_map *map; @@ -1150,16 +1171,18 @@ linemap_macro_loc_to_spelling_point (struct line_maps *set, while (true) { - map = (struct line_map*) linemap_lookup (set, location); + map = const_cast <line_map *> (linemap_lookup (set, location)); if (!linemap_macro_expansion_map_p (map)) break; - location = - linemap_macro_map_loc_unwind_toward_spelling (map, location); + location + = linemap_macro_map_loc_unwind_toward_spelling + (linemap_check_macro (map), + location); } if (original_map) - *original_map = map; + *original_map = linemap_check_ordinary (map); return location; } @@ -1176,7 +1199,7 @@ linemap_macro_loc_to_spelling_point (struct line_maps *set, static source_location linemap_macro_loc_to_def_point (struct line_maps *set, source_location location, - const struct line_map **original_map) + const line_map_ordinary **original_map) { struct line_map *map; @@ -1188,16 +1211,17 @@ linemap_macro_loc_to_def_point (struct line_maps *set, while (true) { - map = (struct line_map*) linemap_lookup (set, location); + map = const_cast <line_map *> (linemap_lookup (set, location)); if (!linemap_macro_expansion_map_p (map)) break; location = - linemap_macro_map_loc_to_def_point (map, location); + linemap_macro_map_loc_to_def_point (linemap_check_macro (map), + location); } if (original_map) - *original_map = map; + *original_map = linemap_check_ordinary (map); return location; } @@ -1218,7 +1242,7 @@ linemap_macro_loc_to_def_point (struct line_maps *set, static source_location linemap_macro_loc_to_exp_point (struct line_maps *set, source_location location, - const struct line_map **original_map) + const line_map_ordinary **original_map) { struct line_map *map; @@ -1230,14 +1254,15 @@ linemap_macro_loc_to_exp_point (struct line_maps *set, while (true) { - map = (struct line_map*) linemap_lookup (set, location); + map = const_cast <line_map *> (linemap_lookup (set, location)); if (!linemap_macro_expansion_map_p (map)) break; - location = linemap_macro_map_loc_to_exp_point (map, location); + location = linemap_macro_map_loc_to_exp_point (linemap_check_macro (map), + location); } if (original_map) - *original_map = map; + *original_map = linemap_check_ordinary (map); return location; } @@ -1293,7 +1318,7 @@ source_location linemap_resolve_location (struct line_maps *set, source_location loc, enum location_resolution_kind lrk, - const struct line_map **map) + const line_map_ordinary **map) { if (IS_ADHOC_LOC (loc)) loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; @@ -1343,18 +1368,19 @@ linemap_unwind_toward_expansion (struct line_maps *set, const struct line_map **map) { source_location resolved_location; + const line_map_macro *macro_map = linemap_check_macro (*map); const struct line_map *resolved_map; if (IS_ADHOC_LOC (loc)) loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; resolved_location = - linemap_macro_map_loc_unwind_toward_spelling (*map, loc); + linemap_macro_map_loc_unwind_toward_spelling (macro_map, loc); resolved_map = linemap_lookup (set, resolved_location); if (!linemap_macro_expansion_map_p (resolved_map)) { - resolved_location = linemap_macro_map_loc_to_exp_point (*map, loc); + resolved_location = linemap_macro_map_loc_to_exp_point (macro_map, loc); resolved_map = linemap_lookup (set, resolved_location); } @@ -1382,7 +1408,8 @@ linemap_unwind_to_first_non_reserved_loc (struct line_maps *set, const struct line_map **map) { source_location resolved_loc; - const struct line_map *map0 = NULL, *map1 = NULL; + const struct line_map *map0 = NULL; + const line_map_ordinary *map1 = NULL; if (IS_ADHOC_LOC (loc)) loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; @@ -1453,10 +1480,12 @@ linemap_expand_location (struct line_maps *set, if (linemap_location_from_macro_expansion_p (set, loc)) abort (); - xloc.file = LINEMAP_FILE (map); - xloc.line = SOURCE_LINE (map, loc); - xloc.column = SOURCE_COLUMN (map, loc); - xloc.sysp = LINEMAP_SYSP (map) != 0; + const line_map_ordinary *ord_map = linemap_check_ordinary (map); + + xloc.file = LINEMAP_FILE (ord_map); + xloc.line = SOURCE_LINE (ord_map, loc); + xloc.column = SOURCE_COLUMN (ord_map, loc); + xloc.sysp = LINEMAP_SYSP (ord_map) != 0; } return xloc; @@ -1474,7 +1503,7 @@ linemap_dump (FILE *stream, struct line_maps *set, unsigned ix, bool is_macro) = { "LC_ENTER", "LC_LEAVE", "LC_RENAME", "LC_RENAME_VERBATIM", "LC_ENTER_MACRO" }; const char *reason; - struct line_map *map; + const line_map *map; if (stream == NULL) stream = stderr; @@ -1488,26 +1517,32 @@ linemap_dump (FILE *stream, struct line_maps *set, unsigned ix, bool is_macro) fprintf (stream, "Map #%u [%p] - LOC: %u - REASON: %s - SYSP: %s\n", ix, (void *) map, map->start_location, reason, - (!is_macro && ORDINARY_MAP_IN_SYSTEM_HEADER_P (map)) ? "yes" : "no"); + ((!is_macro + && ORDINARY_MAP_IN_SYSTEM_HEADER_P (linemap_check_ordinary (map))) + ? "yes" : "no")); if (!is_macro) { + const line_map_ordinary *ord_map = linemap_check_ordinary (map); unsigned includer_ix; - struct line_map *includer_map; + const line_map_ordinary *includer_map; - includer_ix = ORDINARY_MAP_INCLUDER_FILE_INDEX (map); + includer_ix = ORDINARY_MAP_INCLUDER_FILE_INDEX (ord_map); includer_map = includer_ix < LINEMAPS_ORDINARY_USED (set) ? LINEMAPS_ORDINARY_MAP_AT (set, includer_ix) : NULL; - fprintf (stream, "File: %s:%d\n", ORDINARY_MAP_FILE_NAME (map), - ORDINARY_MAP_STARTING_LINE_NUMBER (map)); + fprintf (stream, "File: %s:%d\n", ORDINARY_MAP_FILE_NAME (ord_map), + ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map)); fprintf (stream, "Included from: [%d] %s\n", includer_ix, includer_map ? ORDINARY_MAP_FILE_NAME (includer_map) : "None"); } else - fprintf (stream, "Macro: %s (%u tokens)\n", - linemap_map_get_macro_name (map), - MACRO_MAP_NUM_MACRO_TOKENS (map)); + { + const line_map_macro *macro_map = linemap_check_macro (map); + fprintf (stream, "Macro: %s (%u tokens)\n", + linemap_map_get_macro_name (macro_map), + MACRO_MAP_NUM_MACRO_TOKENS (macro_map)); + } fprintf (stream, "\n"); } @@ -1521,7 +1556,7 @@ linemap_dump_location (struct line_maps *set, source_location loc, FILE *stream) { - const struct line_map *map; + const line_map_ordinary *map; source_location location; const char *path = "", *from = ""; int l = -1, c = -1, s = -1, e = -1; @@ -1578,7 +1613,7 @@ linemap_get_file_highest_location (struct line_maps *set, int i; for (i = set->info_ordinary.used - 1; i >= 0; --i) { - const char *fname = set->info_ordinary.maps[i].d.ordinary.to_file; + const char *fname = set->info_ordinary.maps[i].to_file; if (fname && !filename_cmp (fname, file_name)) break; } @@ -1610,16 +1645,16 @@ linemap_get_statistics (struct line_maps *set, macro_maps_allocated_size, macro_maps_used_size, macro_maps_locations_size = 0, duplicated_macro_maps_locations_size = 0; - struct line_map *cur_map; + const line_map_macro *cur_map; ordinary_maps_allocated_size = - LINEMAPS_ORDINARY_ALLOCATED (set) * sizeof (struct line_map); + LINEMAPS_ORDINARY_ALLOCATED (set) * sizeof (struct line_map_ordinary); ordinary_maps_used_size = - LINEMAPS_ORDINARY_USED (set) * sizeof (struct line_map); + LINEMAPS_ORDINARY_USED (set) * sizeof (struct line_map_ordinary); macro_maps_allocated_size = - LINEMAPS_MACRO_ALLOCATED (set) * sizeof (struct line_map); + LINEMAPS_MACRO_ALLOCATED (set) * sizeof (struct line_map_macro); for (cur_map = LINEMAPS_MACRO_MAPS (set); cur_map && cur_map <= LINEMAPS_LAST_MACRO_MAP (set); @@ -1642,7 +1677,7 @@ linemap_get_statistics (struct line_maps *set, } macro_maps_used_size = - LINEMAPS_MACRO_USED (set) * sizeof (struct line_map); + LINEMAPS_MACRO_USED (set) * sizeof (struct line_map_macro); s->num_ordinary_maps_allocated = LINEMAPS_ORDINARY_ALLOCATED (set); s->num_ordinary_maps_used = LINEMAPS_ORDINARY_USED (set); |