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]

cpplib: what is a system header? [HEAD]


This unifies and simplifies the tests for systemheaderness in
cpplib.  Currently, there are 2 tests, one for dependencies
(-MM) and one for everything else.  The current ones work like
this:

o For dependencies, everything #included with <>, and nested
  includes below that, are deemed system headers, regardless
  of where the headers actually are found.

o For everything else, something is deemed a system header
  based upon the directory in which it is found, and absolute
  paths never give system headers.  It is unlikely, but this
  scheme can lead to system headers including headers not
  deemed to be system headers.

The new rule for everything is

o Something is deemed a system header if it was included by
  a system header (via "" or <>), or if it was found in a
  system header directory (with absolute pathnames never
  giving a system header directory).

This is a slight change in semantics, but for properly
configured systems with code that correctly uses the
<> and "" forms of #include, no changes should be noticed.  Zack
and I want to try this for a while, and see if anyone complains.

If this isn't what you had in mind, Zack, then please shout.

I can't bootstrap at present because of breakage in cse.c, but
when I can I'll commit this.

Neil.

	* cppfiles.c (stack_include_file): Generate dependencies
	here, based on new rule for systemheaderness, and manage
	include_count here too.
	(PRINT_THIS_DEP): Delete.
	(_cpp_execute_include): Do not generate dependencies here,
	apart from the case of a missing header.  Do not manage
	include_count.  Scrap system_include_depth.
	(_cpp_read_file): Leave dependency generation to
	stack_include_file.
	(_cpp_pop_file_buffer): Don't manage system_include_depth.
	* cpphash.h (struct cpp_reader): Remove system_include_depth.

Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.102
diff -u -p -r1.102 cppfiles.c
--- cppfiles.c	2001/02/16 07:41:08	1.102
+++ cppfiles.c	2001/02/17 17:19:33
@@ -268,7 +268,15 @@ stack_include_file (pfile, inc)
 {
   size_t len = 0;
   cpp_buffer *fp;
+  int sysp;
 
+  /* For -M, add the file to the dependencies on its first inclusion.  */
+  sysp = ((pfile->buffer && pfile->buffer->sysp)
+	  || (inc->foundhere && inc->foundhere->sysp));
+  if (CPP_OPTION (pfile, print_deps) > sysp && !inc->include_count)
+    deps_add_dep (pfile->deps, inc->name);
+  inc->include_count++;
+
   /* Not in cache?  */
   if (! inc->buffer)
     read_include_file (pfile, inc);
@@ -280,8 +288,7 @@ stack_include_file (pfile, inc)
   fp = cpp_push_buffer (pfile, inc->buffer, len, BUF_FILE, inc->name);
   fp->inc = inc;
   fp->inc->refcnt++;
-  if (inc->foundhere)
-    fp->sysp = inc->foundhere->sysp;
+  fp->sysp = sysp;
 
   /* The ->actual_dir field is only used when ignore_srcdir is not in effect;
      see do_include */
@@ -566,7 +573,6 @@ report_missing_guard (n, b)
   return 0;
 }
 
-#define PRINT_THIS_DEP(p, b) (CPP_PRINT_DEPS(p) > (b||p->system_include_depth))
 void
 _cpp_execute_include (pfile, header, no_reinclude, include_next)
      cpp_reader *pfile;
@@ -579,6 +585,7 @@ _cpp_execute_include (pfile, header, no_
   unsigned int angle_brackets = header->type == CPP_HEADER_NAME;
   struct include_file *inc;
   char *fname;
+  int print_dep;
 
   /* Help protect #include or similar from recursion.  */
   if (pfile->buffer_stack_depth >= CPP_STACK_MAX)
@@ -636,20 +643,10 @@ _cpp_execute_include (pfile, header, no_
     }
 
   inc = find_include_file (pfile, fname, search_start);
-
   if (inc)
     {
-      /* For -M, add the file to the dependencies on its first inclusion. */
-      if (!inc->include_count && PRINT_THIS_DEP (pfile, angle_brackets))
-	deps_add_dep (pfile->deps, inc->name);
-      inc->include_count++;
-
-      /* Actually process the file.  */
       stack_include_file (pfile, inc);
 
-      if (angle_brackets)
-	pfile->system_include_depth++;
-
       if (! DO_NOT_REREAD (inc))
 	{
 	  if (no_reinclude)
@@ -668,8 +665,8 @@ _cpp_execute_include (pfile, header, no_
       return;
     }
       
-  if (CPP_OPTION (pfile, print_deps_missing_files)
-      && PRINT_THIS_DEP (pfile, angle_brackets))
+  print_dep = CPP_PRINT_DEPS(pfile) > pfile->buffer->sysp;
+  if (CPP_OPTION (pfile, print_deps_missing_files) && print_dep)
     {
       if (!angle_brackets || IS_ABSOLUTE_PATHNAME (fname))
 	deps_add_dep (pfile->deps, fname);
@@ -704,8 +701,7 @@ _cpp_execute_include (pfile, header, no_
      can't produce correct output, because there may be
      dependencies we need inside the missing file, and we don't
      know what directory this missing file exists in. */
-  else if (CPP_PRINT_DEPS (pfile)
-	   && ! PRINT_THIS_DEP (pfile, angle_brackets))
+  else if (CPP_PRINT_DEPS (pfile) && ! print_dep)
     cpp_warning (pfile, "No include path in which to find %s", fname);
   else
     cpp_error_from_errno (pfile, fname);
@@ -767,9 +763,6 @@ _cpp_read_file (pfile, fname)
       return 0;
     }
 
-  if (CPP_OPTION (pfile, print_deps))
-    deps_add_dep (pfile->deps, f->name);
-
   stack_include_file (pfile, f);
   return 1;
 }
@@ -783,8 +776,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--;
 
Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.97
diff -u -p -r1.97 cpphash.h
--- cpphash.h	2001/02/07 23:13:46	1.97
+++ cpphash.h	2001/02/17 17:19:36
@@ -282,9 +282,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;
 


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