This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Have line-map.c track include depth


cpplib had 3 trackers of include depth.  One was for dependencies, and
had I not missed it it really should have died as part of the
dependency patch I sent earlier.

The others are in some way duplicates, and are properly done in the
line map code.  This gives a few more simplifications.

Bootstrapping x86 Linux.

Neil.

	* 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.

Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.127
diff -u -p -r1.127 cppfiles.c
--- cppfiles.c	2001/08/21 21:17:47	1.127
+++ cppfiles.c	2001/08/21 21:22:53
@@ -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, ang
      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, typ
 			   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)
@@ -733,11 +727,6 @@ _cpp_pop_file_buffer (pfile, buf)
      cpp_buffer *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.  */
Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.120
diff -u -p -r1.120 cpphash.h
--- cpphash.h	2001/08/21 19:23:24	1.120
+++ cpphash.h	2001/08/21 21:22:54
@@ -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;
 
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.269
diff -u -p -r1.269 cpplib.c
--- cpplib.c	2001/08/21 06:20:18	1.269
+++ cpplib.c	2001/08/21 21:22:58
@@ -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, typ
   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)
     {
Index: cppmacro.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmacro.c,v
retrieving revision 1.62
diff -u -p -r1.62 cppmacro.c
--- cppmacro.c	2001/08/17 22:23:48	1.62
+++ cppmacro.c	2001/08/21 21:23:01
@@ -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:
Index: line-map.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/line-map.c,v
retrieving revision 1.5
diff -u -p -r1.5 line-map.c
--- line-map.c	2001/08/21 21:17:48	1.5
+++ line-map.c	2001/08/21 21:23:13
@@ -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_li
 	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_li
   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);
 }
Index: line-map.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/line-map.h,v
retrieving revision 1.8
diff -u -p -r1.8 line-map.h
--- line-map.h	2001/08/21 21:17:48	1.8
+++ line-map.h	2001/08/21 21:23:13
@@ -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;
 };


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]