Commit 0e50b624 by David Malcolm Committed by David Malcolm

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
parent 49c65434
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>
PR target/66156
......
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>
* sigtramp-vxworks.c: Add space between string literal and macro
......
......@@ -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);
Logical_Line_Number line = Get_Logical_Line_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. */
if (line < 1)
......
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>
* c-common.c (shorten_compare): Use std::swap instead of explicit swaps.
......
......@@ -1093,13 +1093,13 @@ extern const unsigned char executable_checksum[16];
extern void builtin_define_std (const char *macro);
extern void builtin_define_with_value (const char *, const char *, int);
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);
/* In c-ppoutput.c */
extern void init_pp_output (FILE *);
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 bool check_missing_format_attribute (tree, tree);
......
......@@ -201,7 +201,7 @@ cb_line_change (cpp_reader * ARG_UNUSED (pfile), const cpp_token *token,
}
void
fe_file_change (const struct line_map *new_map)
fe_file_change (const line_map_ordinary *new_map)
{
if (new_map == NULL)
return;
......@@ -281,7 +281,7 @@ static void
cb_define (cpp_reader *pfile, source_location loc, cpp_hashnode *node)
{
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));
}
......@@ -291,7 +291,7 @@ cb_undef (cpp_reader * ARG_UNUSED (pfile), source_location loc,
cpp_hashnode *node)
{
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));
}
......
......@@ -135,7 +135,7 @@ static void handle_deferred_opts (void);
static void sanitize_cpp_opts (void);
static void add_prefixed_path (const char *, size_t);
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 c_finish_options (void);
......@@ -1306,8 +1306,10 @@ c_finish_options (void)
size_t i;
cb_file_change (parse_in,
linemap_add (line_table, LC_RENAME, 0,
_("<built-in>"), 0));
linemap_check_ordinary (linemap_add (line_table,
LC_RENAME, 0,
_("<built-in>"),
0)));
/* Make sure all of the builtins about to be declared have
BUILTINS_LOCATION has their source_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);
cb_file_change (parse_in,
linemap_add (line_table, LC_RENAME, 0,
_("<command-line>"), 0));
linemap_check_ordinary (linemap_add (line_table, LC_RENAME, 0,
_("<command-line>"), 0)));
for (i = 0; i < deferred_count; i++)
{
......@@ -1434,7 +1436,7 @@ push_command_line_include (void)
/* File change callback. Has to handle -include files. */
static void
cb_file_change (cpp_reader * ARG_UNUSED (pfile),
const struct line_map *new_map)
const line_map_ordinary *new_map)
{
if (flag_preprocess_only)
pp_file_change (new_map);
......
......@@ -502,7 +502,7 @@ cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
static void
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);
fputs ("#define ", print.outf);
......@@ -642,7 +642,7 @@ pp_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
described in MAP. */
void
pp_file_change (const struct line_map *map)
pp_file_change (const line_map_ordinary *map)
{
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. */
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));
}
if (map->reason == LC_ENTER)
......
......@@ -607,7 +607,7 @@ diagnostic_action_after_output (diagnostic_context *context,
void
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))
{
......
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>
* interface.c (compare_actual_formal): Use std::swap instead of
......
......@@ -147,7 +147,7 @@ static void scan_translation_unit_trad (cpp_reader *);
/* Callback routines for the parser. Most of these are active only
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_define (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
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);
/* End the previous line of text. */
......@@ -874,7 +875,7 @@ print_line (source_location src_loc, const char *special_flags)
}
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 = "";
......@@ -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. */
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));
}
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. */
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;
print.printed = 1;
......
......@@ -58,7 +58,7 @@ __attribute__((format (printf, 6, 0)))
error_cb (cpp_reader *, int errtype, int, source_location location,
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);
expanded_location loc = linemap_expand_location (line_table, map, location);
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,
bool dumpfile = false)
{
const line_map *map;
const line_map_ordinary *map;
linemap_resolve_location (line_table, location, LRK_SPELLING_LOCATION, &map);
expanded_location loc = linemap_expand_location (line_table, map, location);
if (dumpfile)
......
......@@ -134,7 +134,7 @@ expand_location_1 (source_location loc,
bool expansion_point_p)
{
expanded_location xloc;
const struct line_map *map;
const line_map_ordinary *map;
enum location_resolution_kind lrk = LRK_MACRO_EXPANSION_POINT;
tree block = NULL;
......@@ -158,7 +158,7 @@ expand_location_1 (source_location loc,
location (toward the expansion point) that is not reserved;
that is, the first location that is in real source code. */
loc = linemap_unwind_to_first_non_reserved_loc (line_table,
loc, &map);
loc, NULL);
lrk = LRK_SPELLING_LOCATION;
}
loc = linemap_resolve_location (line_table, loc,
......@@ -724,7 +724,7 @@ location_get_source_line (expanded_location xloc,
bool
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,
LRK_SPELLING_LOCATION, &map);
return loc == BUILTINS_LOCATION;
......@@ -949,7 +949,8 @@ dump_location_info (FILE *stream)
source_location end_location = get_end_location (line_table, idx);
/* 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);
dump_location_range (stream,
MAP_START_LOCATION (map), end_location);
......@@ -1026,7 +1027,7 @@ dump_location_info (FILE *stream)
unsigned int idx = (ascending_source_locations
? (LINEMAPS_MACRO_USED (line_table) - (i + 1))
: 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",
idx,
linemap_map_get_macro_name (map),
......
......@@ -67,7 +67,7 @@ default_tree_diagnostic_starter (diagnostic_context *context,
below. */
typedef struct
{
const struct line_map *map;
const line_map_macro *map;
source_location where;
} loc_map_pair;
......@@ -133,7 +133,7 @@ maybe_unwind_expanded_macro_loc (diagnostic_context *context,
do
{
loc.where = where;
loc.map = map;
loc.map = linemap_check_macro (map);
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
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
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 =
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)
{
/* 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
within a system header. */
const struct line_map *m = NULL;
const line_map_ordinary *m = NULL;
source_location l =
linemap_resolve_location (line_table, resolved_def_loc,
LRK_SPELLING_LOCATION, &m);
......
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>
* include/line-map.h (source_location): Add a reference to
......
......@@ -912,7 +912,7 @@ static void
do_line (cpp_reader *pfile)
{
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
sysp right now. */
......@@ -975,7 +975,7 @@ static void
do_linemarker (cpp_reader *pfile)
{
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 char *new_file = ORDINARY_MAP_FILE_NAME (map);
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,
unsigned int sysp)
{
linemap_assert (reason != LC_ENTER_MACRO);
const struct line_map *map = linemap_add (pfile->line_table, reason, sysp,
to_file, file_line);
const line_map_ordinary *ord_map = NULL;
if (map != NULL)
linemap_line_start (pfile->line_table,
ORDINARY_MAP_STARTING_LINE_NUMBER (map),
127);
{
ord_map = linemap_check_ordinary (map);
linemap_line_start (pfile->line_table,
ORDINARY_MAP_STARTING_LINE_NUMBER (ord_map),
127);
}
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
......
......@@ -1326,7 +1326,7 @@ cpp_make_system_header (cpp_reader *pfile, int syshdr, int externc)
{
int flags = 0;
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. */
if (syshdr)
flags = 1 + (externc != 0);
......
......@@ -549,7 +549,7 @@ struct cpp_callbacks
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
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 (*include) (cpp_reader *, source_location, const unsigned char *,
......
......@@ -68,7 +68,7 @@ struct cset_converter
#define CPP_INCREMENT_LINE(PFILE, COLS_HINT) do { \
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); \
linenum_type line = SOURCE_LINE (map, line_table->highest_line); \
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. NUM_TOKENS is the number of tokens that are part of
the replacement-list of MACRO. */
const struct line_map *linemap_enter_macro (struct line_maps *,
struct cpp_hashnode*,
source_location,
unsigned int);
const line_map_macro *linemap_enter_macro (struct line_maps *,
struct cpp_hashnode*,
source_location,
unsigned int);
/* 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
......@@ -860,7 +860,7 @@ const struct line_map *linemap_enter_macro (struct line_maps *,
MACRO_DEFINITION_LOC is the location in the macro definition,
either of the token itself or of a macro parameter that it
replaces. */
source_location linemap_add_macro_token (const struct line_map *,
source_location linemap_add_macro_token (const line_map_macro *,
unsigned int,
source_location,
source_location);
......
......@@ -141,7 +141,7 @@ static inline const cpp_token **tokens_buff_put_token_to (const cpp_token **,
const cpp_token *,
source_location,
source_location,
const struct line_map *,
const line_map_macro *,
unsigned int);
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 *,
source_location,
source_location,
const struct line_map *,
const line_map_macro *,
unsigned int);
static inline void tokens_buff_remove_last_token (_cpp_buff *);
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;
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,
"macro \"%s\" is not used", NODE_NAME (node));
}
......@@ -453,7 +455,7 @@ builtin_macro (cpp_reader *pfile, cpp_hashnode *node, source_location loc)
macro. */
source_location *virt_locs = NULL;
_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,
token->src_loc, 1);
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;
const cpp_token *src = macro->exp.tokens;
const struct line_map *map;
const line_map_macro *map;
source_location *virt_locs = NULL;
_cpp_buff *macro_tokens
= 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;
source_location *virt_locs = NULL;
unsigned int exp_count;
const struct line_map *map = NULL;
const line_map_macro *map = NULL;
int track_macro_exp;
/* 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,
source_location virt_loc,
source_location parm_def_loc,
const struct line_map *map,
const line_map_macro *map,
unsigned int macro_token_index)
{
source_location macro_loc = virt_loc;
......@@ -2111,7 +2113,7 @@ tokens_buff_add_token (_cpp_buff *buffer,
const cpp_token *token,
source_location virt_loc,
source_location parm_def_loc,
const struct line_map *map,
const line_map_macro *map,
unsigned int macro_token_index)
{
const cpp_token **result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment