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
This commit is contained in:
David Malcolm 2015-05-19 13:18:01 +00:00 committed by David Malcolm
parent 49c6543450
commit 0e50b62468
22 changed files with 618 additions and 340 deletions

View File

@ -1,3 +1,29 @@
2015-05-19 David Malcolm <dmalcolm@redhat.com>
* 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 *.
2015-05-19 Nick Clifton <nickc@redhat.com> 2015-05-19 Nick Clifton <nickc@redhat.com>
PR target/66156 PR target/66156

View File

@ -1,3 +1,8 @@
2015-05-19 David Malcolm <dmalcolm@redhat.com>
* gcc-interface/trans.c (Sloc_to_locus1): Strenghthen local "map"
from line_map * to line_map_ordinary *.
2015-05-12 Jason Merrill <jason@redhat.com> 2015-05-12 Jason Merrill <jason@redhat.com>
* sigtramp-vxworks.c: Add space between string literal and macro * sigtramp-vxworks.c: Add space between string literal and macro

View File

@ -9316,7 +9316,7 @@ Sloc_to_locus1 (Source_Ptr Sloc, location_t *locus, bool clear_column)
Source_File_Index file = Get_Source_File_Index (Sloc); Source_File_Index file = Get_Source_File_Index (Sloc);
Logical_Line_Number line = Get_Logical_Line_Number (Sloc); Logical_Line_Number line = Get_Logical_Line_Number (Sloc);
Column_Number column = (clear_column ? 0 : Get_Column_Number (Sloc)); Column_Number column = (clear_column ? 0 : Get_Column_Number (Sloc));
struct line_map *map = LINEMAPS_ORDINARY_MAP_AT (line_table, file - 1); line_map_ordinary *map = LINEMAPS_ORDINARY_MAP_AT (line_table, file - 1);
/* We can have zero if pragma Source_Reference is in effect. */ /* We can have zero if pragma Source_Reference is in effect. */
if (line < 1) if (line < 1)

View File

@ -1,3 +1,21 @@
2015-05-19 David Malcolm <dmalcolm@redhat.com>
* 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".
2015-05-19 Mikhail Maltsev <maltsevm@gmail.com> 2015-05-19 Mikhail Maltsev <maltsevm@gmail.com>
* c-common.c (shorten_compare): Use std::swap instead of explicit swaps. * c-common.c (shorten_compare): Use std::swap instead of explicit swaps.

View File

@ -1093,13 +1093,13 @@ extern const unsigned char executable_checksum[16];
extern void builtin_define_std (const char *macro); extern void builtin_define_std (const char *macro);
extern void builtin_define_with_value (const char *, const char *, int); extern void builtin_define_with_value (const char *, const char *, int);
extern void c_stddef_cpp_builtins (void); extern void c_stddef_cpp_builtins (void);
extern void fe_file_change (const struct line_map *); extern void fe_file_change (const line_map_ordinary *);
extern void c_parse_error (const char *, enum cpp_ttype, tree, unsigned char); extern void c_parse_error (const char *, enum cpp_ttype, tree, unsigned char);
/* In c-ppoutput.c */ /* In c-ppoutput.c */
extern void init_pp_output (FILE *); extern void init_pp_output (FILE *);
extern void preprocess_file (cpp_reader *); extern void preprocess_file (cpp_reader *);
extern void pp_file_change (const struct line_map *); extern void pp_file_change (const line_map_ordinary *);
extern void pp_dir_change (cpp_reader *, const char *); extern void pp_dir_change (cpp_reader *, const char *);
extern bool check_missing_format_attribute (tree, tree); extern bool check_missing_format_attribute (tree, tree);

View File

@ -201,7 +201,7 @@ cb_line_change (cpp_reader * ARG_UNUSED (pfile), const cpp_token *token,
} }
void void
fe_file_change (const struct line_map *new_map) fe_file_change (const line_map_ordinary *new_map)
{ {
if (new_map == NULL) if (new_map == NULL)
return; return;
@ -281,7 +281,7 @@ static void
cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node) cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node)
{ {
const struct line_map *map = linemap_lookup (line_table, loc); const struct line_map *map = linemap_lookup (line_table, loc);
(*debug_hooks->define) (SOURCE_LINE (map, loc), (*debug_hooks->define) (SOURCE_LINE (linemap_check_ordinary (map), loc),
(const char *) cpp_macro_definition (pfile, node)); (const char *) cpp_macro_definition (pfile, node));
} }
@ -291,7 +291,7 @@ cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc,
cpp_hashnode *node) cpp_hashnode *node)
{ {
const struct line_map *map = linemap_lookup (line_table, loc); const struct line_map *map = linemap_lookup (line_table, loc);
(*debug_hooks->undef) (SOURCE_LINE (map, loc), (*debug_hooks->undef) (SOURCE_LINE (linemap_check_ordinary (map), loc),
(const char *) NODE_NAME (node)); (const char *) NODE_NAME (node));
} }

View File

@ -135,7 +135,7 @@ static void handle_deferred_opts (void);
static void sanitize_cpp_opts (void); static void sanitize_cpp_opts (void);
static void add_prefixed_path (const char *, size_t); static void add_prefixed_path (const char *, size_t);
static void push_command_line_include (void); static void push_command_line_include (void);
static void cb_file_change (cpp_reader *, const struct line_map *); static void cb_file_change (cpp_reader *, const line_map_ordinary *);
static void cb_dir_change (cpp_reader *, const char *); static void cb_dir_change (cpp_reader *, const char *);
static void c_finish_options (void); static void c_finish_options (void);
@ -1306,8 +1306,10 @@ c_finish_options (void)
size_t i; size_t i;
cb_file_change (parse_in, cb_file_change (parse_in,
linemap_add (line_table, LC_RENAME, 0, linemap_check_ordinary (linemap_add (line_table,
_("<built-in>"), 0)); LC_RENAME, 0,
_("<built-in>"),
0)));
/* Make sure all of the builtins about to be declared have /* Make sure all of the builtins about to be declared have
BUILTINS_LOCATION has their source_location. */ BUILTINS_LOCATION has their source_location. */
source_location builtins_loc = BUILTINS_LOCATION; source_location builtins_loc = BUILTINS_LOCATION;
@ -1330,8 +1332,8 @@ c_finish_options (void)
cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99); cpp_opts->warn_dollars = (cpp_opts->cpp_pedantic && !cpp_opts->c99);
cb_file_change (parse_in, cb_file_change (parse_in,
linemap_add (line_table, LC_RENAME, 0, linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
_("<command-line>"), 0)); _("<command-line>"), 0)));
for (i = 0; i < deferred_count; i++) for (i = 0; i < deferred_count; i++)
{ {
@ -1434,7 +1436,7 @@ push_command_line_include (void)
/* File change callback. Has to handle -include files. */ /* File change callback. Has to handle -include files. */
static void static void
cb_file_change (cpp_reader * ARG_UNUSED (pfile), cb_file_change (cpp_reader * ARG_UNUSED (pfile),
const struct line_map *new_map) const line_map_ordinary *new_map)
{ {
if (flag_preprocess_only) if (flag_preprocess_only)
pp_file_change (new_map); pp_file_change (new_map);

View File

@ -502,7 +502,7 @@ cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
static void static void
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node) cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
{ {
const struct line_map *map; const line_map_ordinary *map;
maybe_print_line (line); maybe_print_line (line);
fputs ("#define ", print.outf); fputs ("#define ", print.outf);
@ -642,7 +642,7 @@ pp_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
described in MAP. */ described in MAP. */
void void
pp_file_change (const struct line_map *map) pp_file_change (const line_map_ordinary *map)
{ {
const char *flags = ""; const char *flags = "";
@ -664,7 +664,7 @@ pp_file_change (const struct line_map *map)
/* Bring current file to correct line when entering a new file. */ /* Bring current file to correct line when entering a new file. */
if (map->reason == LC_ENTER) if (map->reason == LC_ENTER)
{ {
const struct line_map *from = INCLUDED_FROM (line_table, map); const line_map_ordinary *from = INCLUDED_FROM (line_table, map);
maybe_print_line (LAST_SOURCE_LINE_LOCATION (from)); maybe_print_line (LAST_SOURCE_LINE_LOCATION (from));
} }
if (map->reason == LC_ENTER) if (map->reason == LC_ENTER)

View File

@ -607,7 +607,7 @@ diagnostic_action_after_output (diagnostic_context *context,
void void
diagnostic_report_current_module (diagnostic_context *context, location_t where) diagnostic_report_current_module (diagnostic_context *context, location_t where)
{ {
const struct line_map *map = NULL; const line_map_ordinary *map = NULL;
if (pp_needs_newline (context->printer)) if (pp_needs_newline (context->printer))
{ {

View File

@ -1,3 +1,10 @@
2015-05-19 David Malcolm <dmalcolm@redhat.com>
* 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".
2015-05-19 Mikhail Maltsev <maltsevm@gmail.com> 2015-05-19 Mikhail Maltsev <maltsevm@gmail.com>
* interface.c (compare_actual_formal): Use std::swap instead of * interface.c (compare_actual_formal): Use std::swap instead of

View File

@ -147,7 +147,7 @@ static void scan_translation_unit_trad (cpp_reader *);
/* Callback routines for the parser. Most of these are active only /* Callback routines for the parser. Most of these are active only
in specific modes. */ in specific modes. */
static void cb_file_change (cpp_reader *, const struct line_map *); static void cb_file_change (cpp_reader *, const line_map_ordinary *);
static void cb_line_change (cpp_reader *, const cpp_token *, int); static void cb_line_change (cpp_reader *, const cpp_token *, int);
static void cb_define (cpp_reader *, source_location, cpp_hashnode *); static void cb_define (cpp_reader *, source_location, cpp_hashnode *);
static void cb_undef (cpp_reader *, source_location, cpp_hashnode *); static void cb_undef (cpp_reader *, source_location, cpp_hashnode *);
@ -807,7 +807,8 @@ scan_translation_unit_trad (cpp_reader *pfile)
static void static void
maybe_print_line (source_location src_loc) maybe_print_line (source_location src_loc)
{ {
const struct line_map *map = linemap_lookup (line_table, src_loc); const line_map_ordinary *map
= linemap_check_ordinary (linemap_lookup (line_table, src_loc));
int src_line = SOURCE_LINE (map, src_loc); int src_line = SOURCE_LINE (map, src_loc);
/* End the previous line of text. */ /* End the previous line of text. */
@ -874,7 +875,7 @@ print_line (source_location src_loc, const char *special_flags)
} }
static void static void
cb_file_change (cpp_reader * ARG_UNUSED (pfile), const struct line_map *map) cb_file_change (cpp_reader * ARG_UNUSED (pfile), const line_map_ordinary *map)
{ {
const char *flags = ""; const char *flags = "";
@ -896,7 +897,7 @@ cb_file_change (cpp_reader * ARG_UNUSED (pfile), const struct line_map *map)
/* Bring current file to correct line when entering a new file. */ /* Bring current file to correct line when entering a new file. */
if (map->reason == LC_ENTER) if (map->reason == LC_ENTER)
{ {
const struct line_map *from = INCLUDED_FROM (line_table, map); const line_map_ordinary *from = INCLUDED_FROM (line_table, map);
maybe_print_line (LAST_SOURCE_LINE_LOCATION (from)); maybe_print_line (LAST_SOURCE_LINE_LOCATION (from));
} }
if (map->reason == LC_ENTER) if (map->reason == LC_ENTER)
@ -930,7 +931,8 @@ cb_line_change (cpp_reader *pfile, const cpp_token *token,
ought to care. Some things do care; the fault lies with them. */ ought to care. Some things do care; the fault lies with them. */
if (!CPP_OPTION (pfile, traditional)) if (!CPP_OPTION (pfile, traditional))
{ {
const struct line_map *map = linemap_lookup (line_table, src_loc); const line_map_ordinary *map
= linemap_check_ordinary (linemap_lookup (line_table, src_loc));
int spaces = SOURCE_COLUMN (map, src_loc) - 2; int spaces = SOURCE_COLUMN (map, src_loc) - 2;
print.printed = 1; print.printed = 1;

View File

@ -58,7 +58,7 @@ __attribute__((format (printf, 6, 0)))
error_cb (cpp_reader *, int errtype, int, source_location location, error_cb (cpp_reader *, int errtype, int, source_location location,
unsigned int, const char *msg, va_list *ap) unsigned int, const char *msg, va_list *ap)
{ {
const line_map *map; const line_map_ordinary *map;
linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map); linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map);
expanded_location loc = linemap_expand_location (line_table, map, location); expanded_location loc = linemap_expand_location (line_table, map, location);
fprintf (stderr, "%s:%d:%d %s: ", loc.file, loc.line, loc.column, fprintf (stderr, "%s:%d:%d %s: ", loc.file, loc.line, loc.column,
@ -134,7 +134,7 @@ static void
output_line_directive (FILE *f, source_location location, output_line_directive (FILE *f, source_location location,
bool dumpfile = false) bool dumpfile = false)
{ {
const line_map *map; const line_map_ordinary *map;
linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map); linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map);
expanded_location loc = linemap_expand_location (line_table, map, location); expanded_location loc = linemap_expand_location (line_table, map, location);
if (dumpfile) if (dumpfile)

View File

@ -134,7 +134,7 @@ expand_location_1 (source_location loc,
bool expansion_point_p) bool expansion_point_p)
{ {
expanded_location xloc; expanded_location xloc;
const struct line_map *map; const line_map_ordinary *map;
enum location_resolution_kind lrk = LRK_MACRO_EXPANSION_POINT; enum location_resolution_kind lrk = LRK_MACRO_EXPANSION_POINT;
tree block = NULL; tree block = NULL;
@ -158,7 +158,7 @@ expand_location_1 (source_location loc,
location (toward the expansion point) that is not reserved; location (toward the expansion point) that is not reserved;
that is, the first location that is in real source code. */ that is, the first location that is in real source code. */
loc = linemap_unwind_to_first_non_reserved_loc (line_table, loc = linemap_unwind_to_first_non_reserved_loc (line_table,
loc, &map); loc, NULL);
lrk = LRK_SPELLING_LOCATION; lrk = LRK_SPELLING_LOCATION;
} }
loc = linemap_resolve_location (line_table, loc, loc = linemap_resolve_location (line_table, loc,
@ -724,7 +724,7 @@ location_get_source_line (expanded_location xloc,
bool bool
is_location_from_builtin_token (source_location loc) is_location_from_builtin_token (source_location loc)
{ {
const line_map *map = NULL; const line_map_ordinary *map = NULL;
loc = linemap_resolve_location (line_table, loc, loc = linemap_resolve_location (line_table, loc,
LRK_SPELLING_LOCATION, &map); LRK_SPELLING_LOCATION, &map);
return loc == BUILTINS_LOCATION; return loc == BUILTINS_LOCATION;
@ -949,7 +949,8 @@ dump_location_info (FILE *stream)
source_location end_location = get_end_location (line_table, idx); source_location end_location = get_end_location (line_table, idx);
/* half-closed: doesn't include this one. */ /* half-closed: doesn't include this one. */
struct line_map *map = LINEMAPS_ORDINARY_MAP_AT (line_table, idx); const line_map_ordinary *map
= LINEMAPS_ORDINARY_MAP_AT (line_table, idx);
fprintf (stream, "ORDINARY MAP: %i\n", idx); fprintf (stream, "ORDINARY MAP: %i\n", idx);
dump_location_range (stream, dump_location_range (stream,
MAP_START_LOCATION (map), end_location); MAP_START_LOCATION (map), end_location);
@ -1026,7 +1027,7 @@ dump_location_info (FILE *stream)
unsigned int idx = (ascending_source_locations unsigned int idx = (ascending_source_locations
? (LINEMAPS_MACRO_USED (line_table) - (i + 1)) ? (LINEMAPS_MACRO_USED (line_table) - (i + 1))
: i); : i);
struct line_map *map = LINEMAPS_MACRO_MAP_AT (line_table, idx); const line_map_macro *map = LINEMAPS_MACRO_MAP_AT (line_table, idx);
fprintf (stream, "MACRO %i: %s (%u tokens)\n", fprintf (stream, "MACRO %i: %s (%u tokens)\n",
idx, idx,
linemap_map_get_macro_name (map), linemap_map_get_macro_name (map),

View File

@ -67,7 +67,7 @@ default_tree_diagnostic_starter (diagnostic_context *context,
below. */ below. */
typedef struct typedef struct
{ {
const struct line_map *map; const line_map_macro *map;
source_location where; source_location where;
} loc_map_pair; } loc_map_pair;
@ -133,7 +133,7 @@ maybe_unwind_expanded_macro_loc (diagnostic_context *context,
do do
{ {
loc.where = where; loc.where = where;
loc.map = map; loc.map = linemap_check_macro (map);
loc_vec.safe_push (loc); loc_vec.safe_push (loc);
@ -148,6 +148,7 @@ maybe_unwind_expanded_macro_loc (diagnostic_context *context,
/* Now map is set to the map of the location in the source that /* Now map is set to the map of the location in the source that
first triggered the macro expansion. This must be an ordinary map. */ first triggered the macro expansion. This must be an ordinary map. */
const line_map_ordinary *ord_map = linemap_check_ordinary (map);
/* Walk LOC_VEC and print the macro expansion trace, unless the /* Walk LOC_VEC and print the macro expansion trace, unless the
first macro which expansion triggered this trace was expanded first macro which expansion triggered this trace was expanded
@ -155,7 +156,7 @@ maybe_unwind_expanded_macro_loc (diagnostic_context *context,
int saved_location_line = int saved_location_line =
expand_location_to_spelling_point (diagnostic_location (diagnostic)).line; expand_location_to_spelling_point (diagnostic_location (diagnostic)).line;
if (!LINEMAP_SYSP (map)) if (!LINEMAP_SYSP (ord_map))
FOR_EACH_VEC_ELT (loc_vec, ix, iter) FOR_EACH_VEC_ELT (loc_vec, ix, iter)
{ {
/* Sometimes, in the unwound macro expansion trace, we want to /* Sometimes, in the unwound macro expansion trace, we want to
@ -195,7 +196,7 @@ maybe_unwind_expanded_macro_loc (diagnostic_context *context,
/* Don't print trace for locations that are reserved or from /* Don't print trace for locations that are reserved or from
within a system header. */ within a system header. */
const struct line_map *m = NULL; const line_map_ordinary *m = NULL;
source_location l = source_location l =
linemap_resolve_location (line_table, resolved_def_loc, linemap_resolve_location (line_table, resolved_def_loc,
LRK_SPELLING_LOCATION, &m); LRK_SPELLING_LOCATION, &m);

View File

@ -1,3 +1,161 @@
2015-05-19 David Malcolm <dmalcolm@redhat.com>
* 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.
2015-05-13 David Malcolm <dmalcolm@redhat.com> 2015-05-13 David Malcolm <dmalcolm@redhat.com>
* include/line-map.h (source_location): Add a reference to * include/line-map.h (source_location): Add a reference to

View File

@ -912,7 +912,7 @@ static void
do_line (cpp_reader *pfile) do_line (cpp_reader *pfile)
{ {
struct line_maps *line_table = pfile->line_table; struct line_maps *line_table = pfile->line_table;
const struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (line_table); const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
/* skip_rest_of_line() may cause line table to be realloc()ed so note down /* skip_rest_of_line() may cause line table to be realloc()ed so note down
sysp right now. */ sysp right now. */
@ -975,7 +975,7 @@ static void
do_linemarker (cpp_reader *pfile) do_linemarker (cpp_reader *pfile)
{ {
struct line_maps *line_table = pfile->line_table; struct line_maps *line_table = pfile->line_table;
const struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (line_table); const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
const cpp_token *token; const cpp_token *token;
const char *new_file = ORDINARY_MAP_FILE_NAME (map); const char *new_file = ORDINARY_MAP_FILE_NAME (map);
linenum_type new_lineno; linenum_type new_lineno;
@ -1065,15 +1065,20 @@ _cpp_do_file_change (cpp_reader *pfile, enum lc_reason reason,
const char *to_file, linenum_type file_line, const char *to_file, linenum_type file_line,
unsigned int sysp) unsigned int sysp)
{ {
linemap_assert (reason != LC_ENTER_MACRO);
const struct line_map *map = linemap_add (pfile->line_table, reason, sysp, const struct line_map *map = linemap_add (pfile->line_table, reason, sysp,
to_file, file_line); to_file, file_line);
const line_map_ordinary *ord_map = NULL;
if (map != NULL) if (map != NULL)
linemap_line_start (pfile->line_table, {
ORDINARY_MAP_STARTING_LINE_NUMBER (map), ord_map = linemap_check_ordinary (map);
127); linemap_line_start (pfile->line_table,
ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map),
127);
}
if (pfile->cb.file_change) if (pfile->cb.file_change)
pfile->cb.file_change (pfile, map); pfile->cb.file_change (pfile, ord_map);
} }
/* Report a warning or error detected by the program we are /* Report a warning or error detected by the program we are

View File

@ -1326,7 +1326,7 @@ cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc)
{ {
int flags = 0; int flags = 0;
const struct line_maps *line_table = pfile->line_table; const struct line_maps *line_table = pfile->line_table;
const struct line_map *map = LINEMAPS_LAST_ORDINARY_MAP (line_table); const line_map_ordinary *map = LINEMAPS_LAST_ORDINARY_MAP (line_table);
/* 1 = system header, 2 = system header to be treated as C. */ /* 1 = system header, 2 = system header to be treated as C. */
if (syshdr) if (syshdr)
flags = 1 + (externc != 0); flags = 1 + (externc != 0);

View File

@ -549,7 +549,7 @@ struct cpp_callbacks
The line_map is for the new file. It is NULL if there is no new file. The line_map is for the new file. It is NULL if there is no new file.
(In C this happens when done with <built-in>+<command line> and also (In C this happens when done with <built-in>+<command line> and also
when done with a main file.) This can be used for resource cleanup. */ when done with a main file.) This can be used for resource cleanup. */
void (*file_change) (cpp_reader *, const struct line_map *); void (*file_change) (cpp_reader *, const line_map_ordinary *);
void (*dir_change) (cpp_reader *, const char *); void (*dir_change) (cpp_reader *, const char *);
void (*include) (cpp_reader *, source_location, const unsigned char *, void (*include) (cpp_reader *, source_location, const unsigned char *,

View File

@ -125,6 +125,39 @@ typedef void *(*line_map_realloc) (void *, size_t);
for a given requested allocation. */ for a given requested allocation. */
typedef size_t (*line_map_round_alloc_size_func) (size_t); typedef size_t (*line_map_round_alloc_size_func) (size_t);
/* A line_map encodes a sequence of locations.
There are two kinds of maps. Ordinary maps and macro expansion
maps, a.k.a macro maps.
A macro map encodes source locations of tokens that are part of a
macro replacement-list, at a macro expansion point. E.g, in:
#define PLUS(A,B) A + B
No macro map is going to be created there, because we are not at a
macro expansion point. We are at a macro /definition/ point. So the
locations of the tokens of the macro replacement-list (i.e, A + B)
will be locations in an ordinary map, not a macro map.
On the other hand, if we later do:
int a = PLUS (1,2);
The invocation of PLUS here is a macro expansion. So we are at a
macro expansion point. The preprocessor expands PLUS (1,2) and
replaces it with the tokens of its replacement-list: 1 + 2. A macro
map is going to be created to hold (or rather to map, haha ...) the
locations of the tokens 1, + and 2. The macro map also records the
location of the expansion point of PLUS. That location is mapped in
the map that is active right before the location of the invocation
of PLUS. */
struct GTY((tag ("0"), desc ("%h.reason == LC_ENTER_MACRO ? 2 : 1"))) line_map {
source_location start_location;
/* The reason for creation of this line map. */
ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
};
/* An ordinary line map encodes physical source locations. Those /* An ordinary line map encodes physical source locations. Those
physical source locations are called "spelling locations". physical source locations are called "spelling locations".
@ -136,7 +169,7 @@ typedef size_t (*line_map_round_alloc_size_func) (size_t);
means "entire file/line" or "unknown line/column" or "not applicable".) means "entire file/line" or "unknown line/column" or "not applicable".)
The highest possible source location is MAX_SOURCE_LOCATION. */ The highest possible source location is MAX_SOURCE_LOCATION. */
struct GTY(()) line_map_ordinary { struct GTY((tag ("1"))) line_map_ordinary : public line_map {
const char *to_file; const char *to_file;
linenum_type to_line; linenum_type to_line;
@ -164,13 +197,9 @@ struct cpp_hashnode;
/* A macro line map encodes location of tokens coming from a macro /* A macro line map encodes location of tokens coming from a macro
expansion. expansion.
Please note that this struct line_map_macro is a field of struct
line_map below, go read the comments of struct line_map below and
then come back here.
The offset from START_LOCATION is used to index into The offset from START_LOCATION is used to index into
MACRO_LOCATIONS; this holds the original location of the token. */ MACRO_LOCATIONS; this holds the original location of the token. */
struct GTY(()) line_map_macro { struct GTY((tag ("2"))) line_map_macro : public line_map {
/* The cpp macro which expansion gave birth to this macro map. */ /* The cpp macro which expansion gave birth to this macro map. */
struct cpp_hashnode * GTY ((nested_ptr (union tree_node, struct cpp_hashnode * GTY ((nested_ptr (union tree_node,
"%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL", "%h ? CPP_HASHNODE (GCC_IDENT_TO_HT_IDENT (%h)) : NULL",
@ -243,44 +272,6 @@ struct GTY(()) line_map_macro {
source_location expansion; source_location expansion;
}; };
/* A line_map encodes a sequence of locations.
There are two kinds of maps. Ordinary maps and macro expansion
maps, a.k.a macro maps.
A macro map encodes source locations of tokens that are part of a
macro replacement-list, at a macro expansion point. E.g, in:
#define PLUS(A,B) A + B
No macro map is going to be created there, because we are not at a
macro expansion point. We are at a macro /definition/ point. So the
locations of the tokens of the macro replacement-list (i.e, A + B)
will be locations in an ordinary map, not a macro map.
On the other hand, if we later do:
int a = PLUS (1,2);
The invocation of PLUS here is a macro expansion. So we are at a
macro expansion point. The preprocessor expands PLUS (1,2) and
replaces it with the tokens of its replacement-list: 1 + 2. A macro
map is going to be created to hold (or rather to map, haha ...) the
locations of the tokens 1, + and 2. The macro map also records the
location of the expansion point of PLUS. That location is mapped in
the map that is active right before the location of the invocation
of PLUS. */
struct GTY(()) line_map {
source_location start_location;
/* The reason for creation of this line map. */
ENUM_BITFIELD (lc_reason) reason : CHAR_BIT;
union map_u {
struct line_map_ordinary GTY((tag ("0"))) ordinary;
struct line_map_macro GTY((tag ("1"))) macro;
} GTY((desc ("%1.reason == LC_ENTER_MACRO"))) d;
};
#if defined ENABLE_CHECKING && (GCC_VERSION >= 2007) #if defined ENABLE_CHECKING && (GCC_VERSION >= 2007)
/* Assertion macro to be used in line-map code. */ /* Assertion macro to be used in line-map code. */
@ -312,22 +303,44 @@ bool
linemap_macro_expansion_map_p (const struct line_map *); linemap_macro_expansion_map_p (const struct line_map *);
/* Assert that MAP encodes locations of tokens that are not part of /* Assert that MAP encodes locations of tokens that are not part of
the replacement-list of a macro expansion. */ the replacement-list of a macro expansion, downcasting from
inline struct line_map * line_map * to line_map_ordinary *. */
inline line_map_ordinary *
linemap_check_ordinary (struct line_map *map) linemap_check_ordinary (struct line_map *map)
{ {
linemap_assert (!linemap_macro_expansion_map_p (map)); linemap_assert (!linemap_macro_expansion_map_p (map));
return map; return (line_map_ordinary *)map;
} }
/* Assert that MAP encodes locations of tokens that are not part of /* Assert that MAP encodes locations of tokens that are not part of
the replacement-list of a macro expansion. */ the replacement-list of a macro expansion, downcasting from
const line_map * to const line_map_ordinary *. */
inline const struct line_map * inline const line_map_ordinary *
linemap_check_ordinary (const struct line_map *map) linemap_check_ordinary (const struct line_map *map)
{ {
linemap_assert (!linemap_macro_expansion_map_p (map)); linemap_assert (!linemap_macro_expansion_map_p (map));
return map; return (const line_map_ordinary *)map;
}
/* Assert that MAP is a macro expansion and downcast to the appropriate
subclass. */
inline line_map_macro *linemap_check_macro (line_map *map)
{
linemap_assert (linemap_macro_expansion_map_p (map));
return (line_map_macro *)map;
}
/* Assert that MAP is a macro expansion and downcast to the appropriate
subclass. */
inline const line_map_macro *
linemap_check_macro (const line_map *map)
{
linemap_assert (linemap_macro_expansion_map_p (map));
return (const line_map_macro *)map;
} }
/* Read the start location of MAP, as an rvalue. */ /* Read the start location of MAP, as an rvalue. */
@ -350,18 +363,18 @@ MAP_START_LOCATION (line_map *map)
/* Get the starting line number of ordinary map MAP. */ /* Get the starting line number of ordinary map MAP. */
inline linenum_type inline linenum_type
ORDINARY_MAP_STARTING_LINE_NUMBER (const line_map *map) ORDINARY_MAP_STARTING_LINE_NUMBER (const line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.to_line; return ord_map->to_line;
} }
/* Access the starting line number of ordinary map MAP by /* Access the starting line number of ordinary map MAP by
reference (e.g. as an lvalue). */ reference (e.g. as an lvalue). */
inline linenum_type& inline linenum_type&
ORDINARY_MAP_STARTING_LINE_NUMBER (line_map *map) ORDINARY_MAP_STARTING_LINE_NUMBER (line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.to_line; return ord_map->to_line;
} }
/* Get the index of the ordinary map at whose end /* Get the index of the ordinary map at whose end
@ -370,17 +383,17 @@ ORDINARY_MAP_STARTING_LINE_NUMBER (line_map *map)
File(s) at the bottom of the include stack have this set. */ File(s) at the bottom of the include stack have this set. */
inline int inline int
ORDINARY_MAP_INCLUDER_FILE_INDEX (const line_map *map) ORDINARY_MAP_INCLUDER_FILE_INDEX (const line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.included_from; return ord_map->included_from;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
inline int& inline int&
ORDINARY_MAP_INCLUDER_FILE_INDEX (line_map *map) ORDINARY_MAP_INCLUDER_FILE_INDEX (line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.included_from; return ord_map->included_from;
} }
/* Return a positive value if map encodes locations from a system /* Return a positive value if map encodes locations from a system
@ -389,129 +402,147 @@ ORDINARY_MAP_INCLUDER_FILE_INDEX (line_map *map)
that therefore needs to be extern "C" protected in C++. */ that therefore needs to be extern "C" protected in C++. */
inline unsigned char inline unsigned char
ORDINARY_MAP_IN_SYSTEM_HEADER_P (const line_map *map) ORDINARY_MAP_IN_SYSTEM_HEADER_P (const line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.sysp; return ord_map->sysp;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
inline unsigned char & inline unsigned char &
ORDINARY_MAP_IN_SYSTEM_HEADER_P (line_map *map) ORDINARY_MAP_IN_SYSTEM_HEADER_P (line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.sysp; return ord_map->sysp;
} }
/* Get the number of the low-order source_location bits used for a /* Get the number of the low-order source_location bits used for a
column number within ordinary map MAP. */ column number within ordinary map MAP. */
inline unsigned char inline unsigned char
ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (const line_map *map) ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (const line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.column_bits; return ord_map->column_bits;
} }
/* Set the number of the low-order source_location bits used for a /* Set the number of the low-order source_location bits used for a
column number within ordinary map MAP. */ column number within ordinary map MAP. */
inline void inline void
SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (line_map *map, int col_bits) SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (line_map_ordinary *ord_map,
int col_bits)
{ {
linemap_check_ordinary (map)->d.ordinary.column_bits = col_bits; ord_map->column_bits = col_bits;
} }
/* Get the filename of ordinary map MAP. */ /* Get the filename of ordinary map MAP. */
inline const char * inline const char *
ORDINARY_MAP_FILE_NAME (const line_map *map) ORDINARY_MAP_FILE_NAME (const line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.to_file; return ord_map->to_file;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
inline const char * & inline const char * &
ORDINARY_MAP_FILE_NAME (line_map *map) ORDINARY_MAP_FILE_NAME (line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.to_file; return ord_map->to_file;
} }
/* Get the cpp macro whose expansion gave birth to macro map MAP. */ /* Get the cpp macro whose expansion gave birth to macro map MAP. */
inline cpp_hashnode * inline cpp_hashnode *
MACRO_MAP_MACRO (const line_map *map) MACRO_MAP_MACRO (const line_map_macro *macro_map)
{ {
return map->d.macro.macro; return macro_map->macro;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
inline cpp_hashnode * & inline cpp_hashnode * &
MACRO_MAP_MACRO (line_map *map) MACRO_MAP_MACRO (line_map_macro *macro_map)
{ {
return map->d.macro.macro; return macro_map->macro;
} }
/* Get the number of tokens inside the replacement-list of the macro /* Get the number of tokens inside the replacement-list of the macro
that led to macro map MAP. */ that led to macro map MAP. */
inline unsigned int inline unsigned int
MACRO_MAP_NUM_MACRO_TOKENS (const line_map *map) MACRO_MAP_NUM_MACRO_TOKENS (const line_map_macro *macro_map)
{ {
return map->d.macro.n_tokens; return macro_map->n_tokens;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
inline unsigned int & inline unsigned int &
MACRO_MAP_NUM_MACRO_TOKENS (line_map *map) MACRO_MAP_NUM_MACRO_TOKENS (line_map_macro *macro_map)
{ {
return map->d.macro.n_tokens; return macro_map->n_tokens;
} }
/* Get the array of pairs of locations within macro map MAP. /* Get the array of pairs of locations within macro map MAP.
See the declaration of line_map_macro for more information. */ See the declaration of line_map_macro for more information. */
inline source_location * inline source_location *
MACRO_MAP_LOCATIONS (const line_map *map) MACRO_MAP_LOCATIONS (const line_map_macro *macro_map)
{ {
return map->d.macro.macro_locations; return macro_map->macro_locations;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
inline source_location * & inline source_location * &
MACRO_MAP_LOCATIONS (line_map *map) MACRO_MAP_LOCATIONS (line_map_macro *macro_map)
{ {
return map->d.macro.macro_locations; return macro_map->macro_locations;
} }
/* Get the location of the expansion point of the macro map MAP. */ /* Get the location of the expansion point of the macro map MAP. */
inline source_location inline source_location
MACRO_MAP_EXPANSION_POINT_LOCATION (const line_map *map) MACRO_MAP_EXPANSION_POINT_LOCATION (const line_map_macro *macro_map)
{ {
return map->d.macro.expansion; return macro_map->expansion;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
inline source_location & inline source_location &
MACRO_MAP_EXPANSION_POINT_LOCATION (line_map *map) MACRO_MAP_EXPANSION_POINT_LOCATION (line_map_macro *macro_map)
{ {
return map->d.macro.expansion; return macro_map->expansion;
} }
/* The abstraction of a set of location maps. There can be several /* The abstraction of a set of location maps. There can be several
types of location maps. This abstraction contains the attributes types of location maps. This abstraction contains the attributes
that are independent from the type of the map. */ that are independent from the type of the map.
struct GTY(()) maps_info {
/* This array contains the different line maps. Essentially this is just a vector of T_linemap_subclass,
A line map is created for the following events: which can only ever grow in size. */
- when a new preprocessing unit start.
- when a preprocessing unit ends. struct GTY(()) maps_info_ordinary {
- when a macro expansion occurs. */ /* This array contains the "ordinary" line maps, for all
struct line_map * GTY ((length ("%h.used"))) maps; events other than macro expansion
(e.g. when a new preprocessing unit starts or ends). */
line_map_ordinary * GTY ((length ("%h.used"))) maps;
/* The total number of allocated maps. */
unsigned int allocated;
/* The number of elements used in maps. This number is smaller
or equal to ALLOCATED. */
unsigned int used;
unsigned int cache;
};
struct GTY(()) maps_info_macro {
/* This array contains the macro line maps.
A macro line map is created whenever a macro expansion occurs. */
line_map_macro * GTY ((length ("%h.used"))) maps;
/* The total number of allocated maps. */ /* The total number of allocated maps. */
unsigned int allocated; unsigned int allocated;
@ -551,9 +582,9 @@ struct GTY(()) location_adhoc_data_map {
/* A set of chronological line_map structures. */ /* A set of chronological line_map structures. */
struct GTY(()) line_maps { struct GTY(()) line_maps {
struct maps_info info_ordinary; maps_info_ordinary info_ordinary;
struct maps_info info_macro; maps_info_macro info_macro;
/* Depth of the include stack, including the current file. */ /* Depth of the include stack, including the current file. */
unsigned int depth; unsigned int depth;
@ -589,50 +620,15 @@ struct GTY(()) line_maps {
bool seen_line_directive; bool seen_line_directive;
}; };
/* Returns the pointer to the memory region where information about
maps are stored in the line table SET. MACRO_MAP_P is a flag
telling if we want macro or ordinary maps. */
inline struct maps_info *
LINEMAPS_MAP_INFO (line_maps *set, bool macro_map_p)
{
return (macro_map_p
? &(set->info_macro)
: &(set->info_ordinary));
}
/* As above, but preserving constness. */
inline const struct maps_info *
LINEMAPS_MAP_INFO (const line_maps *set, bool macro_map_p)
{
return (macro_map_p
? &(set->info_macro)
: &(set->info_ordinary));
}
/* Returns the pointer to the memory region where maps are stored in
the line table SET. MAP_KIND shall be TRUE if we are interested in
macro maps false otherwise. */
inline line_map *
LINEMAPS_MAPS (const line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->maps;
}
/* As above, but by reference (e.g. as an lvalue). */
inline line_map * &
LINEMAPS_MAPS (line_maps *set, bool map_kind)
{
return LINEMAPS_MAP_INFO (set, map_kind)->maps;
}
/* Returns the number of allocated maps so far. MAP_KIND shall be TRUE /* Returns the number of allocated maps so far. MAP_KIND shall be TRUE
if we are interested in macro maps, FALSE otherwise. */ if we are interested in macro maps, FALSE otherwise. */
inline unsigned int inline unsigned int
LINEMAPS_ALLOCATED (const line_maps *set, bool map_kind) LINEMAPS_ALLOCATED (const line_maps *set, bool map_kind)
{ {
return LINEMAPS_MAP_INFO (set, map_kind)->allocated; if (map_kind)
return set->info_macro.allocated;
else
return set->info_ordinary.allocated;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
@ -640,7 +636,10 @@ LINEMAPS_ALLOCATED (const line_maps *set, bool map_kind)
inline unsigned int & inline unsigned int &
LINEMAPS_ALLOCATED (line_maps *set, bool map_kind) LINEMAPS_ALLOCATED (line_maps *set, bool map_kind)
{ {
return LINEMAPS_MAP_INFO (set, map_kind)->allocated; if (map_kind)
return set->info_macro.allocated;
else
return set->info_ordinary.allocated;
} }
/* Returns the number of used maps so far. MAP_KIND shall be TRUE if /* Returns the number of used maps so far. MAP_KIND shall be TRUE if
@ -648,7 +647,10 @@ LINEMAPS_ALLOCATED (line_maps *set, bool map_kind)
inline unsigned int inline unsigned int
LINEMAPS_USED (const line_maps *set, bool map_kind) LINEMAPS_USED (const line_maps *set, bool map_kind)
{ {
return LINEMAPS_MAP_INFO (set, map_kind)->used; if (map_kind)
return set->info_macro.used;
else
return set->info_ordinary.used;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
@ -656,7 +658,10 @@ LINEMAPS_USED (const line_maps *set, bool map_kind)
inline unsigned int & inline unsigned int &
LINEMAPS_USED (line_maps *set, bool map_kind) LINEMAPS_USED (line_maps *set, bool map_kind)
{ {
return LINEMAPS_MAP_INFO (set, map_kind)->used; if (map_kind)
return set->info_macro.used;
else
return set->info_ordinary.used;
} }
/* Returns the index of the last map that was looked up with /* Returns the index of the last map that was looked up with
@ -665,7 +670,10 @@ LINEMAPS_USED (line_maps *set, bool map_kind)
inline unsigned int inline unsigned int
LINEMAPS_CACHE (const line_maps *set, bool map_kind) LINEMAPS_CACHE (const line_maps *set, bool map_kind)
{ {
return LINEMAPS_MAP_INFO (set, map_kind)->cache; if (map_kind)
return set->info_macro.cache;
else
return set->info_ordinary.cache;
} }
/* As above, but by reference (e.g. as an lvalue). */ /* As above, but by reference (e.g. as an lvalue). */
@ -673,14 +681,20 @@ LINEMAPS_CACHE (const line_maps *set, bool map_kind)
inline unsigned int & inline unsigned int &
LINEMAPS_CACHE (line_maps *set, bool map_kind) LINEMAPS_CACHE (line_maps *set, bool map_kind)
{ {
return LINEMAPS_MAP_INFO (set, map_kind)->cache; if (map_kind)
return set->info_macro.cache;
else
return set->info_ordinary.cache;
} }
/* Return the map at a given index. */ /* Return the map at a given index. */
inline line_map * inline line_map *
LINEMAPS_MAP_AT (const line_maps *set, bool map_kind, int index) LINEMAPS_MAP_AT (const line_maps *set, bool map_kind, int index)
{ {
return &(LINEMAPS_MAPS (set, map_kind)[index]); if (map_kind)
return &set->info_macro.maps[index];
else
return &set->info_ordinary.maps[index];
} }
/* Returns the last map used in the line table SET. MAP_KIND /* Returns the last map used in the line table SET. MAP_KIND
@ -705,17 +719,19 @@ LINEMAPS_LAST_ALLOCATED_MAP (const line_maps *set, bool map_kind)
/* Returns a pointer to the memory region where ordinary maps are /* Returns a pointer to the memory region where ordinary maps are
allocated in the line table SET. */ allocated in the line table SET. */
inline line_map * inline line_map_ordinary *
LINEMAPS_ORDINARY_MAPS (const line_maps *set) LINEMAPS_ORDINARY_MAPS (const line_maps *set)
{ {
return LINEMAPS_MAPS (set, false); return set->info_ordinary.maps;
} }
/* Returns the INDEXth ordinary map. */ /* Returns the INDEXth ordinary map. */
inline line_map * inline line_map_ordinary *
LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index) LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index)
{ {
return LINEMAPS_MAP_AT (set, false, index); linemap_assert (index >= 0);
linemap_assert ((unsigned int)index < set->info_ordinary.used);
return &set->info_ordinary.maps[index];
} }
/* Return the number of ordinary maps allocated in the line table /* Return the number of ordinary maps allocated in the line table
@ -751,33 +767,35 @@ LINEMAPS_ORDINARY_CACHE (line_maps *set)
/* Returns a pointer to the last ordinary map used in the line table /* Returns a pointer to the last ordinary map used in the line table
SET. */ SET. */
inline line_map * inline line_map_ordinary *
LINEMAPS_LAST_ORDINARY_MAP (const line_maps *set) LINEMAPS_LAST_ORDINARY_MAP (const line_maps *set)
{ {
return LINEMAPS_LAST_MAP (set, false); return (line_map_ordinary *)LINEMAPS_LAST_MAP (set, false);
} }
/* Returns a pointer to the last ordinary map allocated the line table /* Returns a pointer to the last ordinary map allocated the line table
SET. */ SET. */
inline line_map * inline line_map_ordinary *
LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP (const line_maps *set) LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP (const line_maps *set)
{ {
return LINEMAPS_LAST_ALLOCATED_MAP (set, false); return (line_map_ordinary *)LINEMAPS_LAST_ALLOCATED_MAP (set, false);
} }
/* Returns a pointer to the beginning of the region where macro maps /* Returns a pointer to the beginning of the region where macro maps
are allcoated. */ are allcoated. */
inline line_map * inline line_map_macro *
LINEMAPS_MACRO_MAPS (const line_maps *set) LINEMAPS_MACRO_MAPS (const line_maps *set)
{ {
return LINEMAPS_MAPS (set, true); return set->info_macro.maps;
} }
/* Returns the INDEXth macro map. */ /* Returns the INDEXth macro map. */
inline line_map * inline line_map_macro *
LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index) LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index)
{ {
return LINEMAPS_MAP_AT (set, true, index); linemap_assert (index >= 0);
linemap_assert ((unsigned int)index < set->info_macro.used);
return &set->info_macro.maps[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
@ -812,10 +830,10 @@ LINEMAPS_MACRO_CACHE (line_maps *set)
} }
/* Returns the last macro map used in the line table SET. */ /* Returns the last macro map used in the line table SET. */
inline line_map * inline line_map_macro *
LINEMAPS_LAST_MACRO_MAP (const line_maps *set) LINEMAPS_LAST_MACRO_MAP (const line_maps *set)
{ {
return LINEMAPS_LAST_MAP (set, true); return (line_map_macro *)LINEMAPS_LAST_MAP (set, true);
} }
/* Returns the lowest location [of a token resulting from macro /* Returns the lowest location [of a token resulting from macro
@ -829,10 +847,10 @@ LINEMAPS_MACRO_LOWEST_LOCATION (const line_maps *set)
} }
/* Returns the last macro map allocated in the line table SET. */ /* Returns the last macro map allocated in the line table SET. */
inline line_map * inline line_map_macro *
LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set) LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set)
{ {
return LINEMAPS_LAST_ALLOCATED_MAP (set, true); return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true);
} }
extern void location_adhoc_data_fini (struct line_maps *); extern void location_adhoc_data_fini (struct line_maps *);
@ -913,7 +931,7 @@ extern const struct line_map *linemap_lookup
bool linemap_tracks_macro_expansion_locs_p (struct line_maps *); bool linemap_tracks_macro_expansion_locs_p (struct line_maps *);
/* Return the name of the macro associated to MACRO_MAP. */ /* Return the name of the macro associated to MACRO_MAP. */
const char* linemap_map_get_macro_name (const struct line_map*); const char* linemap_map_get_macro_name (const line_map_macro *);
/* Return a positive value if LOCATION is the locus of a token that is /* Return a positive value if LOCATION is the locus of a token that is
located in a system header, O otherwise. It returns 1 if LOCATION located in a system header, O otherwise. It returns 1 if LOCATION
@ -940,37 +958,36 @@ const int RESERVED_LOCATION_COUNT = 2;
/* Converts a map and a source_location to source line. */ /* Converts a map and a source_location to source line. */
inline linenum_type inline linenum_type
SOURCE_LINE (const struct line_map *map, source_location loc) SOURCE_LINE (const line_map_ordinary *ord_map, source_location loc)
{ {
return ((loc - linemap_check_ordinary (map)->start_location) return ((loc - ord_map->start_location)
>> map->d.ordinary.column_bits) + map->d.ordinary.to_line; >> ord_map->column_bits) + ord_map->to_line;
} }
/* Convert a map and source_location to source column number. */ /* Convert a map and source_location to source column number. */
inline linenum_type inline linenum_type
SOURCE_COLUMN (const struct line_map *map, source_location loc) SOURCE_COLUMN (const line_map_ordinary *ord_map, source_location loc)
{ {
return ((loc - linemap_check_ordinary (map)->start_location) return ((loc - ord_map->start_location)
& ((1 << map->d.ordinary.column_bits) - 1)); & ((1 << ord_map->column_bits) - 1));
} }
/* Return the location of the last source line within an ordinary /* Return the location of the last source line within an ordinary
map. */ map. */
inline source_location inline source_location
LAST_SOURCE_LINE_LOCATION (const struct line_map *map) LAST_SOURCE_LINE_LOCATION (const line_map_ordinary *map)
{ {
return (((linemap_check_ordinary (map)[1].start_location - 1 return (((map[1].start_location - 1
- map->start_location) - map->start_location)
& ~((1 << map->d.ordinary.column_bits) - 1)) & ~((1 << map->column_bits) - 1))
+ map->start_location); + map->start_location);
} }
/* Returns the last source line number within an ordinary map. This /* Returns the last source line number within an ordinary map. This
is the (last) line of the #include, or other directive, that caused is the (last) line of the #include, or other directive, that caused
a map change. */ a map change. */
inline linenum_type inline linenum_type
LAST_SOURCE_LINE (const struct line_map *map) LAST_SOURCE_LINE (const line_map_ordinary *map)
{ {
return SOURCE_LINE (map, LAST_SOURCE_LINE_LOCATION (map)); return SOURCE_LINE (map, LAST_SOURCE_LINE_LOCATION (map));
} }
@ -978,7 +995,7 @@ LAST_SOURCE_LINE (const struct line_map *map)
/* Return the last column number within an ordinary map. */ /* Return the last column number within an ordinary map. */
inline linenum_type inline linenum_type
LAST_SOURCE_COLUMN (const struct line_map *map) LAST_SOURCE_COLUMN (const line_map_ordinary *map)
{ {
return SOURCE_COLUMN (map, LAST_SOURCE_LINE_LOCATION (map)); return SOURCE_COLUMN (map, LAST_SOURCE_LINE_LOCATION (map));
} }
@ -986,21 +1003,20 @@ LAST_SOURCE_COLUMN (const struct line_map *map)
/* Returns the map a given map was included from, or NULL if the map /* Returns the map a given map was included from, or NULL if the map
belongs to the main file, i.e, a file that wasn't included by belongs to the main file, i.e, a file that wasn't included by
another one. */ another one. */
inline line_map_ordinary *
inline struct line_map * INCLUDED_FROM (struct line_maps *set, const line_map_ordinary *ord_map)
INCLUDED_FROM (struct line_maps *set, const struct line_map *map)
{ {
return ((linemap_check_ordinary (map)->d.ordinary.included_from == -1) return ((ord_map->included_from == -1)
? NULL ? NULL
: (&LINEMAPS_ORDINARY_MAPS (set)[(map)->d.ordinary.included_from])); : LINEMAPS_ORDINARY_MAP_AT (set, ord_map->included_from));
} }
/* True if the map is at the bottom of the include stack. */ /* True if the map is at the bottom of the include stack. */
inline bool inline bool
MAIN_FILE_P (const struct line_map *map) MAIN_FILE_P (const line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.included_from < 0; return ord_map->included_from < 0;
} }
/* Encode and return a source_location from a column number. The /* Encode and return a source_location from a column number. The
@ -1013,7 +1029,7 @@ linemap_position_for_column (struct line_maps *, unsigned int);
/* Encode and return a source location from a given line and /* Encode and return a source location from a given line and
column. */ column. */
source_location source_location
linemap_position_for_line_and_column (const struct line_map *, linemap_position_for_line_and_column (const line_map_ordinary *,
linenum_type, unsigned int); linenum_type, unsigned int);
/* Encode and return a source_location starting from location LOC and /* Encode and return a source_location starting from location LOC and
@ -1026,16 +1042,16 @@ linemap_position_for_loc_and_offset (struct line_maps *set,
/* Return the file this map is for. */ /* Return the file this map is for. */
inline const char * inline const char *
LINEMAP_FILE (const struct line_map *map) LINEMAP_FILE (const line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.to_file; return ord_map->to_file;
} }
/* Return the line number this map started encoding location from. */ /* Return the line number this map started encoding location from. */
inline linenum_type inline linenum_type
LINEMAP_LINE (const struct line_map *map) LINEMAP_LINE (const line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.to_line; return ord_map->to_line;
} }
/* Return a positive value if map encodes locations from a system /* Return a positive value if map encodes locations from a system
@ -1043,9 +1059,9 @@ LINEMAP_LINE (const struct line_map *map)
system header and 2 if it encodes locations in a C system header system header and 2 if it encodes locations in a C system header
that therefore needs to be extern "C" protected in C++. */ that therefore needs to be extern "C" protected in C++. */
inline unsigned char inline unsigned char
LINEMAP_SYSP (const struct line_map *map) LINEMAP_SYSP (const line_map_ordinary *ord_map)
{ {
return linemap_check_ordinary (map)->d.ordinary.sysp; return ord_map->sysp;
} }
/* Return a positive value if PRE denotes the location of a token that /* Return a positive value if PRE denotes the location of a token that
@ -1144,7 +1160,7 @@ enum location_resolution_kind
source_location linemap_resolve_location (struct line_maps *, source_location linemap_resolve_location (struct line_maps *,
source_location loc, source_location loc,
enum location_resolution_kind lrk, enum location_resolution_kind lrk,
const struct line_map **loc_map); const line_map_ordinary **loc_map);
/* Suppose that LOC is the virtual location of a token coming from the /* Suppose that LOC is the virtual location of a token coming from the
expansion of a macro M. This function then steps up to get the expansion of a macro M. This function then steps up to get the

View File

@ -68,7 +68,7 @@ struct cset_converter
#define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \ #define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \
const struct line_maps *line_table = PFILE->line_table; \ const struct line_maps *line_table = PFILE->line_table; \
const struct line_map *map = \ const struct line_map_ordinary *map = \
LINEMAPS_LAST_ORDINARY_MAP (line_table); \ LINEMAPS_LAST_ORDINARY_MAP (line_table); \
linenum_type line = SOURCE_LINE (map, line_table->highest_line); \ linenum_type line = SOURCE_LINE (map, line_table->highest_line); \
linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \ linemap_line_start (PFILE->line_table, line + 1, COLS_HINT); \
@ -833,10 +833,10 @@ ufputs (const unsigned char *s, FILE *f)
of the macro, rather than the the location of the first character of the macro, rather than the the location of the first character
of the macro. NUM_TOKENS is the number of tokens that are part of of the macro. NUM_TOKENS is the number of tokens that are part of
the replacement-list of MACRO. */ the replacement-list of MACRO. */
const struct line_map *linemap_enter_macro (struct line_maps *, const line_map_macro *linemap_enter_macro (struct line_maps *,
struct cpp_hashnode*, struct cpp_hashnode*,
source_location, source_location,
unsigned int); unsigned int);
/* Create and return a virtual location for a token that is part of a /* Create and return a virtual location for a token that is part of a
macro expansion-list at a macro expansion point. See the comment macro expansion-list at a macro expansion point. See the comment
@ -860,7 +860,7 @@ const struct line_map *linemap_enter_macro (struct line_maps *,
MACRO_DEFINITION_LOC is the location in the macro definition, MACRO_DEFINITION_LOC is the location in the macro definition,
either of the token itself or of a macro parameter that it either of the token itself or of a macro parameter that it
replaces. */ replaces. */
source_location linemap_add_macro_token (const struct line_map *, source_location linemap_add_macro_token (const line_map_macro *,
unsigned int, unsigned int,
source_location, source_location,
source_location); source_location);

View File

@ -26,25 +26,25 @@ along with this program; see the file COPYING3. If not see
#include "internal.h" #include "internal.h"
#include "hashtab.h" #include "hashtab.h"
static void trace_include (const struct line_maps *, const struct line_map *); static void trace_include (const struct line_maps *, const line_map_ordinary *);
static const struct line_map * linemap_ordinary_map_lookup (struct line_maps *, static const line_map_ordinary * linemap_ordinary_map_lookup (struct line_maps *,
source_location); source_location);
static const struct line_map* linemap_macro_map_lookup (struct line_maps *, static const line_map_macro* linemap_macro_map_lookup (struct line_maps *,
source_location); source_location);
static source_location linemap_macro_map_loc_to_def_point 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 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 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 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 *, static source_location linemap_macro_loc_to_def_point (struct line_maps *,
source_location, source_location,
const struct line_map **); const line_map_ordinary **);
static source_location linemap_macro_loc_to_exp_point (struct line_maps *, static source_location linemap_macro_loc_to_exp_point (struct line_maps *,
source_location, source_location,
const struct line_map **); const line_map_ordinary **);
/* Counters defined in macro.c. */ /* Counters defined in macro.c. */
extern unsigned num_expanded_macros_counter; extern unsigned num_expanded_macros_counter;
@ -191,7 +191,7 @@ linemap_init (struct line_maps *set,
void void
linemap_check_files_exited (struct line_maps *set) 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 /* Depending upon whether we are handling preprocessed input or
not, this can be a user error or an ICE. */ not, this can be a user error or an ICE. */
for (map = LINEMAPS_LAST_ORDINARY_MAP (set); 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 = line_map_round_alloc_size_func round_alloc_size =
set->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 /* We are going to execute some dance to try to reduce the
overhead of the memory allocator, in case we are using the overhead of the memory allocator, in case we are using the
ggc-page.c one. ggc-page.c one.
@ -237,7 +241,7 @@ new_linemap (struct line_maps *set,
alloc_size = alloc_size =
(2 * LINEMAPS_ALLOCATED (set, macro_map_p) + 256) (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 /* Get the actual size of memory that is going to be allocated
by the allocator. */ 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 Let's get back to the number of macro map that amounts
to. */ to. */
LINEMAPS_ALLOCATED (set, macro_map_p) = 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. */ /* And now let's really do the re-allocation. */
LINEMAPS_MAPS (set, macro_map_p) = if (macro_map_p)
(struct line_map *) (*reallocator) {
(LINEMAPS_MAPS (set, macro_map_p), set->info_macro.maps
(LINEMAPS_ALLOCATED (set, macro_map_p) = (line_map_macro *) (*reallocator) (set->info_macro.maps,
* sizeof (struct line_map))); (LINEMAPS_ALLOCATED (set, macro_map_p)
* map_size));
result = result = &set->info_macro.maps[LINEMAPS_USED (set, macro_map_p)];
&LINEMAPS_MAPS (set, macro_map_p)[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, memset (result, 0,
((LINEMAPS_ALLOCATED (set, macro_map_p) ((LINEMAPS_ALLOCATED (set, macro_map_p)
- LINEMAPS_USED (set, macro_map_p)) - LINEMAPS_USED (set, macro_map_p))
* sizeof (struct line_map))); * map_size));
} }
else 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)++; LINEMAPS_USED (set, macro_map_p)++;
@ -291,7 +307,6 @@ const struct line_map *
linemap_add (struct line_maps *set, enum lc_reason reason, linemap_add (struct line_maps *set, enum lc_reason reason,
unsigned int sysp, const char *to_file, linenum_type to_line) unsigned int sysp, const char *to_file, linenum_type to_line)
{ {
struct line_map *map;
source_location start_location = set->highest_location + 1; source_location start_location = set->highest_location + 1;
linemap_assert (!(LINEMAPS_ORDINARY_USED (set) linemap_assert (!(LINEMAPS_ORDINARY_USED (set)
@ -311,7 +326,8 @@ linemap_add (struct line_maps *set, enum lc_reason reason,
return NULL; 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) if (to_file && *to_file == '\0' && reason != LC_RENAME_VERBATIM)
to_file = "<stdin>"; 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 location inside the "includer" right after the #include
"included", this variable points the map in use right before the "included", this variable points the map in use right before the
#include "included", inside the same "includer" file. */ #include "included", inside the same "includer" file. */
struct line_map *from; line_map_ordinary *from;
bool error; bool error;
if (MAIN_FILE_P (map - 1)) 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; ORDINARY_MAP_IN_SYSTEM_HEADER_P (map) = sysp;
MAP_START_LOCATION (map) = start_location; MAP_START_LOCATION (map) = start_location;
ORDINARY_MAP_FILE_NAME (map) = to_file; 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 this function cannot encode {line,column} pairs into locations of
macro tokens anymore. */ macro tokens anymore. */
const struct line_map * const line_map_macro *
linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node, linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node,
source_location expansion, unsigned int num_tokens) source_location expansion, unsigned int num_tokens)
{ {
struct line_map *map; line_map_macro *map;
source_location start_location; source_location start_location;
/* Cast away extern "C" from the type of xrealloc. */ /* Cast away extern "C" from the type of xrealloc. */
line_map_realloc reallocator = (set->reallocator 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. */ /* We ran out of macro map space. */
return NULL; 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; MAP_START_LOCATION (map) = start_location;
MACRO_MAP_MACRO (map) = macro_node; MACRO_MAP_MACRO (map) = macro_node;
@ -489,7 +504,7 @@ linemap_enter_macro (struct line_maps *set, struct cpp_hashnode *macro_node,
replaces. */ replaces. */
source_location source_location
linemap_add_macro_token (const struct line_map *map, linemap_add_macro_token (const line_map_macro *map,
unsigned int token_no, unsigned int token_no,
source_location orig_loc, source_location orig_loc,
source_location orig_parm_replacement_loc) source_location orig_parm_replacement_loc)
@ -516,7 +531,7 @@ source_location
linemap_line_start (struct line_maps *set, linenum_type to_line, linemap_line_start (struct line_maps *set, linenum_type to_line,
unsigned int max_column_hint) 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 highest = set->highest_location;
source_location r; source_location r;
linenum_type last_line = linenum_type last_line =
@ -559,11 +574,12 @@ linemap_line_start (struct line_maps *set, linenum_type to_line,
if (line_delta < 0 if (line_delta < 0
|| last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map) || last_line != ORDINARY_MAP_STARTING_LINE_NUMBER (map)
|| SOURCE_COLUMN (map, highest) >= (1U << column_bits)) || SOURCE_COLUMN (map, highest) >= (1U << column_bits))
map = (struct line_map *) linemap_add (set, LC_RENAME, map = linemap_check_ordinary
ORDINARY_MAP_IN_SYSTEM_HEADER_P (const_cast <line_map *>
(map), (linemap_add (set, LC_RENAME,
ORDINARY_MAP_FILE_NAME (map), ORDINARY_MAP_IN_SYSTEM_HEADER_P (map),
to_line); ORDINARY_MAP_FILE_NAME (map),
to_line)));
SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map, column_bits); SET_ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map, column_bits);
r = (MAP_START_LOCATION (map) r = (MAP_START_LOCATION (map)
+ ((to_line - ORDINARY_MAP_STARTING_LINE_NUMBER (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 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); 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. */ column. */
source_location 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, linenum_type line,
unsigned column) 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) return (MAP_START_LOCATION (ord_map)
+ ((line - ORDINARY_MAP_STARTING_LINE_NUMBER (map)) + ((line - ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map))
<< ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map)) << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (ord_map))
+ (column & ((1 << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (map)) - 1))); + (column & ((1 << ORDINARY_MAP_NUMBER_OF_COLUMN_BITS (ord_map)) - 1)));
} }
/* Encode and return a source_location starting from location LOC and /* 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, source_location loc,
unsigned int offset) unsigned int offset)
{ {
const struct line_map * map = NULL; const line_map_ordinary * map = NULL;
/* This function does not support virtual locations yet. */ /* This function does not support virtual locations yet. */
if (linemap_assert_fails if (linemap_assert_fails
@ -671,7 +687,8 @@ linemap_position_for_loc_and_offset (struct line_maps *set,
return loc; return loc;
offset += SOURCE_COLUMN (map, 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; return loc;
source_location r = 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 monotonic increasing, and so the list is sorted and we can use a
binary search. */ binary search. */
static const struct line_map * static const line_map_ordinary *
linemap_ordinary_map_lookup (struct line_maps *set, source_location line) linemap_ordinary_map_lookup (struct line_maps *set, source_location line)
{ {
unsigned int md, mn, mx; unsigned int md, mn, mx;
const struct line_map *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_SOURCE_LOCATION].locus; 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 monotonic decreasing, and so the list is sorted and we can use a
binary search. */ binary search. */
static const struct line_map* static const line_map_macro *
linemap_macro_map_lookup (struct line_maps *set, source_location line) linemap_macro_map_lookup (struct line_maps *set, source_location line)
{ {
unsigned int md, mn, mx; unsigned int md, mn, mx;
const struct line_map *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_SOURCE_LOCATION].locus; 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. */ line-map.h to understand what a macro expansion point is. */
static source_location 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) source_location location ATTRIBUTE_UNUSED)
{ {
linemap_assert (linemap_macro_expansion_map_p (map) 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. */ macro. */
static source_location 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) source_location location)
{ {
unsigned token_no; 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 In other words, this returns the xI location presented in the
comments of line_map_macro above. */ comments of line_map_macro above. */
source_location 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) source_location location)
{ {
unsigned token_no; unsigned token_no;
@ -882,7 +899,7 @@ int
linemap_get_expansion_line (struct line_maps *set, linemap_get_expansion_line (struct line_maps *set,
source_location location) source_location location)
{ {
const struct line_map *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 = set->location_adhoc_data_map.data[location
@ -910,7 +927,7 @@ const char*
linemap_get_expansion_filename (struct line_maps *set, linemap_get_expansion_filename (struct line_maps *set,
source_location location) source_location location)
{ {
const struct line_map *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 = 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. */ /* Return the name of the macro associated to MACRO_MAP. */
const char* 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)); linemap_assert (macro_map && linemap_macro_expansion_map_p (macro_map));
return (const char*) NODE_NAME (MACRO_MAP_MACRO (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)) if (!linemap_macro_expansion_map_p (map))
/* It's a normal token. */ /* It's a normal token. */
return LINEMAP_SYSP (map); return LINEMAP_SYSP (linemap_check_ordinary (map));
else else
{ {
const line_map_macro *macro_map = linemap_check_macro (map);
/* It's a token resulting from a macro expansion. */ /* It's a token resulting from a macro expansion. */
source_location loc = 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) if (loc < RESERVED_LOCATION_COUNT)
/* This token might come from a built-in macro. Let's /* This token might come from a built-in macro. Let's
look at where that macro got expanded. */ 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 else
location = loc; location = loc;
} }
@ -1025,12 +1044,14 @@ first_map_in_common_1 (struct line_maps *set,
{ {
if (MAP_START_LOCATION (map0) < MAP_START_LOCATION (map1)) 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); map0 = linemap_lookup (set, l0);
} }
else 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); 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. */ /* Print an include trace, for e.g. the -H option of the preprocessor. */
static void 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; unsigned int i = set->depth;
@ -1138,7 +1159,7 @@ trace_include (const struct line_maps *set, const struct line_map *map)
static source_location static source_location
linemap_macro_loc_to_spelling_point (struct line_maps *set, linemap_macro_loc_to_spelling_point (struct line_maps *set,
source_location location, source_location location,
const struct line_map **original_map) const line_map_ordinary **original_map)
{ {
struct line_map *map; struct line_map *map;
@ -1150,16 +1171,18 @@ linemap_macro_loc_to_spelling_point (struct line_maps *set,
while (true) 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)) if (!linemap_macro_expansion_map_p (map))
break; break;
location = location
linemap_macro_map_loc_unwind_toward_spelling (map, location); = linemap_macro_map_loc_unwind_toward_spelling
(linemap_check_macro (map),
location);
} }
if (original_map) if (original_map)
*original_map = map; *original_map = linemap_check_ordinary (map);
return location; return location;
} }
@ -1176,7 +1199,7 @@ linemap_macro_loc_to_spelling_point (struct line_maps *set,
static source_location static source_location
linemap_macro_loc_to_def_point (struct line_maps *set, linemap_macro_loc_to_def_point (struct line_maps *set,
source_location location, source_location location,
const struct line_map **original_map) const line_map_ordinary **original_map)
{ {
struct line_map *map; struct line_map *map;
@ -1188,16 +1211,17 @@ linemap_macro_loc_to_def_point (struct line_maps *set,
while (true) 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)) if (!linemap_macro_expansion_map_p (map))
break; break;
location = 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) if (original_map)
*original_map = map; *original_map = linemap_check_ordinary (map);
return location; return location;
} }
@ -1218,7 +1242,7 @@ linemap_macro_loc_to_def_point (struct line_maps *set,
static source_location static source_location
linemap_macro_loc_to_exp_point (struct line_maps *set, linemap_macro_loc_to_exp_point (struct line_maps *set,
source_location location, source_location location,
const struct line_map **original_map) const line_map_ordinary **original_map)
{ {
struct line_map *map; struct line_map *map;
@ -1230,14 +1254,15 @@ linemap_macro_loc_to_exp_point (struct line_maps *set,
while (true) 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)) if (!linemap_macro_expansion_map_p (map))
break; 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) if (original_map)
*original_map = map; *original_map = linemap_check_ordinary (map);
return location; return location;
} }
@ -1293,7 +1318,7 @@ source_location
linemap_resolve_location (struct line_maps *set, linemap_resolve_location (struct line_maps *set,
source_location loc, source_location loc,
enum location_resolution_kind lrk, enum location_resolution_kind lrk,
const struct line_map **map) const line_map_ordinary **map)
{ {
if (IS_ADHOC_LOC (loc)) if (IS_ADHOC_LOC (loc))
loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; 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) const struct line_map **map)
{ {
source_location resolved_location; source_location resolved_location;
const line_map_macro *macro_map = linemap_check_macro (*map);
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_SOURCE_LOCATION].locus; loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
resolved_location = 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); resolved_map = linemap_lookup (set, resolved_location);
if (!linemap_macro_expansion_map_p (resolved_map)) 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); 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) const struct line_map **map)
{ {
source_location resolved_loc; 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)) if (IS_ADHOC_LOC (loc))
loc = set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus; 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)) if (linemap_location_from_macro_expansion_p (set, loc))
abort (); abort ();
xloc.file = LINEMAP_FILE (map); const line_map_ordinary *ord_map = linemap_check_ordinary (map);
xloc.line = SOURCE_LINE (map, loc);
xloc.column = SOURCE_COLUMN (map, loc); xloc.file = LINEMAP_FILE (ord_map);
xloc.sysp = LINEMAP_SYSP (map) != 0; xloc.line = SOURCE_LINE (ord_map, loc);
xloc.column = SOURCE_COLUMN (ord_map, loc);
xloc.sysp = LINEMAP_SYSP (ord_map) != 0;
} }
return xloc; 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", "LC_LEAVE", "LC_RENAME", "LC_RENAME_VERBATIM",
"LC_ENTER_MACRO" }; "LC_ENTER_MACRO" };
const char *reason; const char *reason;
struct line_map *map; const line_map *map;
if (stream == NULL) if (stream == NULL)
stream = stderr; 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", fprintf (stream, "Map #%u [%p] - LOC: %u - REASON: %s - SYSP: %s\n",
ix, (void *) map, map->start_location, reason, 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) if (!is_macro)
{ {
const line_map_ordinary *ord_map = linemap_check_ordinary (map);
unsigned includer_ix; 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) includer_map = includer_ix < LINEMAPS_ORDINARY_USED (set)
? LINEMAPS_ORDINARY_MAP_AT (set, includer_ix) ? LINEMAPS_ORDINARY_MAP_AT (set, includer_ix)
: NULL; : NULL;
fprintf (stream, "File: %s:%d\n", ORDINARY_MAP_FILE_NAME (map), fprintf (stream, "File: %s:%d\n", ORDINARY_MAP_FILE_NAME (ord_map),
ORDINARY_MAP_STARTING_LINE_NUMBER (map)); ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map));
fprintf (stream, "Included from: [%d] %s\n", includer_ix, fprintf (stream, "Included from: [%d] %s\n", includer_ix,
includer_map ? ORDINARY_MAP_FILE_NAME (includer_map) : "None"); includer_map ? ORDINARY_MAP_FILE_NAME (includer_map) : "None");
} }
else else
fprintf (stream, "Macro: %s (%u tokens)\n", {
linemap_map_get_macro_name (map), const line_map_macro *macro_map = linemap_check_macro (map);
MACRO_MAP_NUM_MACRO_TOKENS (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"); fprintf (stream, "\n");
} }
@ -1521,7 +1556,7 @@ linemap_dump_location (struct line_maps *set,
source_location loc, source_location loc,
FILE *stream) FILE *stream)
{ {
const struct line_map *map; const line_map_ordinary *map;
source_location location; source_location location;
const char *path = "", *from = ""; const char *path = "", *from = "";
int l = -1, c = -1, s = -1, e = -1; int l = -1, c = -1, s = -1, e = -1;
@ -1578,7 +1613,7 @@ linemap_get_file_highest_location (struct line_maps *set,
int i; int i;
for (i = set->info_ordinary.used - 1; i >= 0; --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)) if (fname && !filename_cmp (fname, file_name))
break; break;
} }
@ -1610,16 +1645,16 @@ linemap_get_statistics (struct line_maps *set,
macro_maps_allocated_size, macro_maps_used_size, macro_maps_allocated_size, macro_maps_used_size,
macro_maps_locations_size = 0, duplicated_macro_maps_locations_size = 0; 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 = 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 = 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 = 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); for (cur_map = LINEMAPS_MACRO_MAPS (set);
cur_map && cur_map <= LINEMAPS_LAST_MACRO_MAP (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 = 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_allocated = LINEMAPS_ORDINARY_ALLOCATED (set);
s->num_ordinary_maps_used = LINEMAPS_ORDINARY_USED (set); s->num_ordinary_maps_used = LINEMAPS_ORDINARY_USED (set);

View File

@ -141,7 +141,7 @@ static inline const cpp_token **tokens_buff_put_token_to (const cpp_token **,
const cpp_token *, const cpp_token *,
source_location, source_location,
source_location, source_location,
const struct line_map *, const line_map_macro *,
unsigned int); unsigned int);
static const cpp_token **tokens_buff_add_token (_cpp_buff *, static const cpp_token **tokens_buff_add_token (_cpp_buff *,
@ -149,7 +149,7 @@ static const cpp_token **tokens_buff_add_token (_cpp_buff *,
const cpp_token *, const cpp_token *,
source_location, source_location,
source_location, source_location,
const struct line_map *, const line_map_macro *,
unsigned int); unsigned int);
static inline void tokens_buff_remove_last_token (_cpp_buff *); static inline void tokens_buff_remove_last_token (_cpp_buff *);
static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *, static void replace_args (cpp_reader *, cpp_hashnode *, cpp_macro *,
@ -195,7 +195,9 @@ _cpp_warn_if_unused_macro (cpp_reader *pfile, cpp_hashnode *node,
cpp_macro *macro = node->value.macro; cpp_macro *macro = node->value.macro;
if (!macro->used if (!macro->used
&& MAIN_FILE_P (linemap_lookup (pfile->line_table, macro->line))) && MAIN_FILE_P (linemap_check_ordinary
(linemap_lookup (pfile->line_table,
macro->line))))
cpp_warning_with_line (pfile, CPP_W_UNUSED_MACROS, macro->line, 0, cpp_warning_with_line (pfile, CPP_W_UNUSED_MACROS, macro->line, 0,
"macro \"%s\" is not used", NODE_NAME (node)); "macro \"%s\" is not used", NODE_NAME (node));
} }
@ -453,7 +455,7 @@ builtin_macro (cpp_reader *pfile, cpp_hashnode *node, source_location loc)
macro. */ macro. */
source_location *virt_locs = NULL; source_location *virt_locs = NULL;
_cpp_buff *token_buf = tokens_buff_new (pfile, 1, &virt_locs); _cpp_buff *token_buf = tokens_buff_new (pfile, 1, &virt_locs);
const line_map * map = const line_map_macro * map =
linemap_enter_macro (pfile->line_table, node, linemap_enter_macro (pfile->line_table, node,
token->src_loc, 1); token->src_loc, 1);
tokens_buff_add_token (token_buf, virt_locs, token, tokens_buff_add_token (token_buf, virt_locs, token,
@ -1167,7 +1169,7 @@ enter_macro_context (cpp_reader *pfile, cpp_hashnode *node,
{ {
unsigned int i; unsigned int i;
const cpp_token *src = macro->exp.tokens; const cpp_token *src = macro->exp.tokens;
const struct line_map *map; const line_map_macro *map;
source_location *virt_locs = NULL; source_location *virt_locs = NULL;
_cpp_buff *macro_tokens _cpp_buff *macro_tokens
= tokens_buff_new (pfile, tokens_count, &virt_locs); = tokens_buff_new (pfile, tokens_count, &virt_locs);
@ -1535,7 +1537,7 @@ replace_args (cpp_reader *pfile, cpp_hashnode *node, cpp_macro *macro,
_cpp_buff *buff = NULL; _cpp_buff *buff = NULL;
source_location *virt_locs = NULL; source_location *virt_locs = NULL;
unsigned int exp_count; unsigned int exp_count;
const struct line_map *map = NULL; const line_map_macro *map = NULL;
int track_macro_exp; int track_macro_exp;
/* First, fully macro-expand arguments, calculating the number of /* First, fully macro-expand arguments, calculating the number of
@ -2066,7 +2068,7 @@ tokens_buff_put_token_to (const cpp_token **dest,
const cpp_token *token, const cpp_token *token,
source_location virt_loc, source_location virt_loc,
source_location parm_def_loc, source_location parm_def_loc,
const struct line_map *map, const line_map_macro *map,
unsigned int macro_token_index) unsigned int macro_token_index)
{ {
source_location macro_loc = virt_loc; source_location macro_loc = virt_loc;
@ -2111,7 +2113,7 @@ tokens_buff_add_token (_cpp_buff *buffer,
const cpp_token *token, const cpp_token *token,
source_location virt_loc, source_location virt_loc,
source_location parm_def_loc, source_location parm_def_loc,
const struct line_map *map, const line_map_macro *map,
unsigned int macro_token_index) unsigned int macro_token_index)
{ {
const cpp_token **result; const cpp_token **result;