cppfiles.c (stack_include_file): line-map.c now handles include depth.

* cppfiles.c (stack_include_file): line-map.c now handles include
	depth.
	(handle_missing_handler): Similarly.
	(_cpp_execute_include): Similarly.
	(_cpp_pop_file_buffer): Similarly.
	* cpphash.h (struct cpp_reader): Remove system_include_depth,
	buffer_stack_depth and include_depth.
	* cpplib.c (do_include_common): line-map.c now handles include depth.
	(cpp_push_buffer): Similarly.
	(_cpp_pop_buffer): Similarly.
	* cppmacro.c (builtin_macro): Update.
	* line-map.c (init_line_maps): Set depth.
	(add_line_map): Increment "used" earlier.  Update and use the
	include depth.
	(trace_include): Use the include depth.
	* line-map.h (struct line_maps): New member depth.

From-SVN: r45085
This commit is contained in:
Neil Booth 2001-08-21 23:05:12 +00:00 committed by Neil Booth
parent 5993019d20
commit d8693c6fa4
7 changed files with 43 additions and 38 deletions

View File

@ -1,3 +1,22 @@
2001-08-22 Neil Booth <neil@daikokuya.demon.co.uk>
* cppfiles.c (stack_include_file): line-map.c now handles include
depth.
(handle_missing_handler): Similarly.
(_cpp_execute_include): Similarly.
(_cpp_pop_file_buffer): Similarly.
* cpphash.h (struct cpp_reader): Remove system_include_depth,
buffer_stack_depth and include_depth.
* cpplib.c (do_include_common): line-map.c now handles include depth.
(cpp_push_buffer): Similarly.
(_cpp_pop_buffer): Similarly.
* cppmacro.c (builtin_macro): Update.
* line-map.c (init_line_maps): Set depth.
(add_line_map): Increment "used" earlier. Update and use the
include depth.
(trace_include): Use the include depth.
* line-map.h (struct line_maps): New member depth.
2001-08-21 Neil Booth <neil@daikokuya.demon.co.uk>
* cppfiles.c (stack_include_file): Don't handle -H here.

View File

@ -324,7 +324,6 @@ stack_include_file (pfile, inc)
/* Initialise controlling macro state. */
pfile->mi_valid = true;
pfile->mi_cmacro = 0;
pfile->include_depth++;
/* Generate the call back. */
filename = inc->name;
@ -614,9 +613,7 @@ handle_missing_header (pfile, fname, angle_brackets)
const char *fname;
int angle_brackets;
{
/* We will try making the RHS pfile->buffer->sysp after 3.0. */
int print_dep = CPP_PRINT_DEPS(pfile) > (angle_brackets
|| pfile->system_include_depth);
int print_dep = CPP_PRINT_DEPS(pfile) > (angle_brackets || pfile->map->sysp);
if (CPP_OPTION (pfile, print_deps_missing_files) && print_dep)
{
@ -671,9 +668,6 @@ _cpp_execute_include (pfile, header, type)
header->type == CPP_HEADER_NAME);
else if (inc != NO_INCLUDE_PATH)
{
if (header->type == CPP_HEADER_NAME)
pfile->system_include_depth++;
stacked = stack_include_file (pfile, inc);
if (type == IT_IMPORT)
@ -734,11 +728,6 @@ _cpp_pop_file_buffer (pfile, buf)
{
struct include_file *inc = buf->inc;
if (pfile->system_include_depth)
pfile->system_include_depth--;
if (pfile->include_depth)
pfile->include_depth--;
/* Record the inclusion-preventing macro, which could be NULL
meaning no controlling macro. */
if (pfile->mi_valid && inc->cmacro == NULL)

View File

@ -279,15 +279,6 @@ struct cpp_reader
unsigned char *macro_buffer;
unsigned int macro_buffer_len;
/* Current depth in #include directives that use <...>. */
unsigned int system_include_depth;
/* Current depth of buffer stack. */
unsigned int buffer_stack_depth;
/* Current depth in #include directives. */
unsigned int include_depth;
/* Tree of other included files. See cppfiles.c. */
struct splay_tree_s *all_include_files;

View File

@ -614,7 +614,7 @@ do_include_common (pfile, type)
if (!parse_include (pfile, &header))
{
/* Prevent #include recursion. */
if (pfile->buffer_stack_depth >= CPP_STACK_MAX)
if (pfile->line_maps.depth >= CPP_STACK_MAX)
cpp_fatal (pfile, "#include nested too deeply");
else
{
@ -1764,7 +1764,6 @@ cpp_push_buffer (pfile, buffer, len, type, return_at_eof)
new->pfile = pfile;
new->return_at_eof = return_at_eof;
pfile->buffer_stack_depth++;
pfile->buffer = new;
return new;
@ -1788,7 +1787,6 @@ _cpp_pop_buffer (pfile)
/* Update the reader's buffer before _cpp_do_file_change. */
pfile->buffer = buffer->prev;
pfile->buffer_stack_depth--;
if (buffer->type == BUF_FILE)
{

View File

@ -164,10 +164,10 @@ builtin_macro (pfile, token)
break;
case BT_INCLUDE_LEVEL:
/* pfile->include_depth counts the primary source as level 1,
but historically __INCLUDE_DEPTH__ has called the primary
source level 0. */
make_number_token (pfile, token, pfile->include_depth - 1);
/* The line map depth counts the primary source as level 1, but
historically __INCLUDE_DEPTH__ has called the primary source
level 0. */
make_number_token (pfile, token, pfile->line_maps.depth - 1);
break;
case BT_SPECLINE:

View File

@ -39,6 +39,7 @@ init_line_maps (set)
set->used = 0;
set->last_listed = -1;
set->trace_includes = false;
set->depth = 0;
}
/* Free a line map set. */
@ -90,11 +91,11 @@ add_line_map (set, reason, sysp, from_line, to_file, to_line)
xrealloc (set->maps, set->allocated * sizeof (struct line_map));
}
map = &set->maps[set->used];
map = &set->maps[set->used++];
/* If we don't keep our line maps consistent, we can easily
segfault. Don't rely on the client to do it for us. */
if (set->used == 0)
if (set->depth == 0)
reason = LC_ENTER;
else if (reason == LC_LEAVE)
{
@ -135,15 +136,19 @@ add_line_map (set, reason, sysp, from_line, to_file, to_line)
map->to_line = to_line;
if (reason == LC_ENTER)
map->included_from = set->used - 1;
{
set->depth++;
map->included_from = set->used - 2;
if (set->trace_includes)
trace_include (set, map);
}
else if (reason == LC_RENAME)
map->included_from = map[-1].included_from;
else if (reason == LC_LEAVE)
map->included_from = INCLUDED_FROM (set, map - 1)->included_from;
set->used++;
if (reason == LC_ENTER && set->trace_includes)
trace_include (set, map);
{
set->depth--;
map->included_from = INCLUDED_FROM (set, map - 1)->included_from;
}
return map;
}
@ -222,9 +227,9 @@ trace_include (set, map)
const struct line_maps *set;
const struct line_map *map;
{
const struct line_map *m;
unsigned int i = set->depth;
for (m = map; !MAIN_FILE_P (m); m = INCLUDED_FROM (set, m))
while (--i)
putc ('.', stderr);
fprintf (stderr, " %s\n", map->to_file);
}

View File

@ -60,6 +60,9 @@ struct line_maps
has been listed yet. */
int last_listed;
/* Depth of the include stack, including the current file. */
unsigned int depth;
/* If true, prints an include trace a la -H. */
bool trace_includes;
};