This is the mail archive of the gcc@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]

Re: sparc-sun-solaris2.8 headers: fixinc, cpplib


And this should fix the syshdr issue (please let me know!).  It's not
pretty, but it works.

The patch is longer than it needs to be, because I've renamed some
instances of "change_file" to "file_change" for consistency.

Neil.

	* c-lex.c: s/change_file/file_change.
	* cpplib.h: Similarly.
	* cppmain.c: Similarly.
	* fix-header.c: Similarly.
	* cppfiles.c (stack_include_file): Pass the buffer location and
	size to cpp_push_buffer.  Generate the file_change callback,
	so that sysp is already set.
	* cpphash.h: Add _cpp_do_file_change.
	* cpplib.c (do_line): Set buffer->sysp directly. Generate the
	file_change callback after setting sysp.
	(_cpp_do_file_change): Handle FC_ENTER and the FC_RENAME exception
	here.
	(cpp_push_buffer): Don't generate a callback.  Clear sysp.
	(cpp_pop_buffer): Clean up logic.

Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.123
diff -u -p -r1.123 c-lex.c
--- c-lex.c	2000/12/18 10:16:26	1.123
+++ c-lex.c	2000/12/18 12:37:55
@@ -90,7 +90,7 @@ static tree lex_charconst	PARAMS ((const
 static void update_header_times	PARAMS ((const char *));
 static int dump_one_header	PARAMS ((splay_tree_node, void *));
 static void cb_ident		PARAMS ((cpp_reader *, const cpp_string *));
-static void cb_change_file    PARAMS ((cpp_reader *, const cpp_file_change *));
+static void cb_file_change    PARAMS ((cpp_reader *, const cpp_file_change *));
 static void cb_def_pragma	PARAMS ((cpp_reader *));
 
 const char *
@@ -120,7 +120,7 @@ init_c_lex (filename)
 #endif
 
   parse_in->cb.ident = cb_ident;
-  parse_in->cb.change_file = cb_change_file;
+  parse_in->cb.file_change = cb_file_change;
   parse_in->cb.def_pragma = cb_def_pragma;
 
   if (filename == 0 || !strcmp (filename, "-"))
@@ -226,7 +226,7 @@ cb_ident (pfile, str)
 }
 
 static void
-cb_change_file (pfile, fc)
+cb_file_change (pfile, fc)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
      const cpp_file_change *fc;
 {
Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.95
diff -u -p -r1.95 cppfiles.c
--- cppfiles.c	2000/12/17 00:13:53	1.95
+++ cppfiles.c	2000/12/18 12:37:58
@@ -245,21 +245,19 @@ stack_include_file (pfile, inc)
      cpp_reader *pfile;
      struct include_file *inc;
 {
+  size_t len = 0;
   cpp_buffer *fp;
 
   /* Not in cache?  */
   if (! inc->buffer)
     read_include_file (pfile, inc);
 
-  /* Push a null buffer.  */
-  fp = cpp_push_buffer (pfile, NULL, 0, BUF_FILE, inc->name);
-  fp->inc = inc;
-  fp->buf = inc->buffer;
-  fp->rlimit = fp->buf;
   if (! DO_NOT_REREAD (inc))
-    fp->rlimit += inc->st.st_size;
-  fp->cur = fp->buf;
-  fp->line_base = fp->buf;
+    len = inc->st.st_size;
+
+  /* Push a buffer.  */
+  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;
@@ -273,6 +271,11 @@ stack_include_file (pfile, inc)
   pfile->mi_state = MI_OUTSIDE;
   pfile->mi_cmacro = 0;
   pfile->include_depth++;
+
+  /* Generate the call back.  */
+  fp->lineno = 0;
+  _cpp_do_file_change (pfile, FC_ENTER, 0, 0);
+  fp->lineno = 1;
 }
 
 /* Read the file referenced by INC into the file cache.
Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.89
diff -u -p -r1.89 cpphash.h
--- cpphash.h	2000/12/17 00:13:53	1.89
+++ cpphash.h	2000/12/18 12:38:00
@@ -229,6 +229,8 @@ extern void _cpp_do__Pragma	PARAMS ((cpp
 extern void _cpp_init_stacks	PARAMS ((cpp_reader *));
 extern void _cpp_cleanup_stacks	PARAMS ((cpp_reader *));
 extern void _cpp_init_internal_pragmas PARAMS ((cpp_reader *));
+extern void _cpp_do_file_change PARAMS ((cpp_reader *, enum cpp_fc_reason,
+					 const char *, unsigned int));
 
 /* Utility routines and macros.  */
 #define DSC(str) (const U_CHAR *)str, sizeof str - 1
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.233
diff -u -p -r1.233 cpplib.c
--- cpplib.c	2000/12/17 22:40:31	1.233
+++ cpplib.c	2000/12/18 12:38:07
@@ -108,8 +108,6 @@ static cpp_hashnode *parse_assertion PAR
 static struct answer ** find_answer PARAMS ((cpp_hashnode *,
 					     const struct answer *));
 static void handle_assertion	PARAMS ((cpp_reader *, const char *, int));
-static void do_file_change	PARAMS ((cpp_reader *, enum cpp_fc_reason,
-					 const char *, unsigned int));
 
 /* This is the table of directive handlers.  It is ordered by
    frequency of occurrence; the numbers at the end are directive
@@ -757,6 +755,8 @@ do_line (pfile)
 		{
 		  cpp_pop_buffer (pfile);
 		  buffer = pfile->buffer;
+		  /* Note that if anything is inconsistent here, the
+		     call back will have used the expected values.  */
 		  if (strcmp (buffer->nominal_fname, fname))
 		    cpp_warning (pfile, "expected to return to file \"%s\"",
 				 buffer->nominal_fname);
@@ -768,10 +768,8 @@ do_line (pfile)
 				 buffer->nominal_fname);
 		}
 	    }
-
-	  cpp_make_system_header (pfile, sysp, sysp == 2);
+	  buffer->sysp = sysp;
 	}
-
       buffer->nominal_fname = fname;
     }
   else if (token.type != CPP_EOF)
@@ -783,37 +781,47 @@ do_line (pfile)
 
   /* Our line number is incremented after the directive is processed.  */
   buffer->lineno = new_lineno - 1;
-
-  if (reason == FC_RENAME)
-    {
-      /* Special case for file "foo.i" with "# 1 foo.c" on first line.  */
-      if (! buffer->prev && pfile->directive_pos.line == 1)
-	filename = 0;
-      do_file_change (pfile, reason, filename, lineno);
-    }
+  _cpp_do_file_change (pfile, reason, filename, lineno);
 }
 
 /* Arrange the file_change callback.  */
-static void
-do_file_change (pfile, reason, from_file, from_lineno)
+void
+_cpp_do_file_change (pfile, reason, from_file, from_lineno)
      cpp_reader *pfile;
      enum cpp_fc_reason reason;
      const char *from_file;
      unsigned int from_lineno;
 {
-  if (pfile->cb.change_file)
+  if (pfile->cb.file_change)
     {
       cpp_file_change fc;
       cpp_buffer *buffer = pfile->buffer;
 
       fc.reason = reason;
-      fc.from.filename = from_file;
-      fc.from.lineno = from_lineno;
       fc.to.filename = buffer->nominal_fname;
       fc.to.lineno = buffer->lineno + 1;
       fc.sysp = buffer->sysp;
       fc.externc = CPP_OPTION (pfile, cplusplus) && buffer->sysp == 2;
-      pfile->cb.change_file (pfile, &fc);
+
+      /* Caller doesn't need to handle FC_ENTER.  */
+      if (reason == FC_ENTER)
+	{
+	  if (buffer->prev)
+	    {
+	      from_file = buffer->prev->nominal_fname;
+	      from_lineno = buffer->prev->lineno;
+	    }
+	  else
+	    from_file = 0;
+	}
+      /* Special case for file "foo.i" with "# 1 foo.c" on first line.  */
+      else if (reason == FC_RENAME && ! buffer->prev
+	       && pfile->directive_pos.line == 1)
+	from_file = 0;
+
+      fc.from.filename = from_file;
+      fc.from.lineno = from_lineno;
+      pfile->cb.file_change (pfile, &fc);
     }
 }
 
@@ -1707,10 +1715,10 @@ handle_assertion (pfile, str, type)
 
   run_directive (pfile, type, BUF_CL_OPTION, str, count);
 }
-
-/* Push a new buffer on the buffer stack.  Buffer can be NULL, but
-   then LEN should be 0.  Returns the new buffer; it doesn't fail.  */
 
+/* Push a new buffer on the buffer stack.  Returns the new buffer; it
+   doesn't fail.  It does not generate a file change call back; that
+   is the responsibility of the caller.  */
 cpp_buffer *
 cpp_push_buffer (pfile, buffer, len, type, filename)
      cpp_reader *pfile;
@@ -1741,6 +1749,7 @@ cpp_push_buffer (pfile, buffer, len, typ
 
       new->line_base = new->buf = new->cur = buffer;
       new->rlimit = buffer + len;
+      new->sysp = 0;
 
       /* No read ahead or extra char initially.  */
       new->read_ahead = EOF;
@@ -1758,38 +1767,26 @@ cpp_push_buffer (pfile, buffer, len, typ
   new->prev = pfile->buffer;
   new->pfile = pfile;
   new->include_stack_listed = 0;
+  new->lineno = 1;
 
   pfile->state.next_bol = 1;
   pfile->buffer_stack_depth++;
   pfile->buffer = new;
 
-  if (type == BUF_FILE || type == BUF_FAKE)
-    {
-      const char *filename = 0;
-      unsigned int lineno = 0;
-
-      if (new->prev)
-	{
-	  filename = new->prev->nominal_fname;
-	  lineno = new->prev->lineno;
-	}
-      new->lineno = 0;
-      do_file_change (pfile, FC_ENTER, filename, lineno);
-    }
-
-  new->lineno = 1;
   return new;
 }
 
+/* If called from do_line, pops a single buffer.  Otherwise pops all
+   buffers until a real file is reached.  Generates appropriate
+   call-backs.  */
 cpp_buffer *
 cpp_pop_buffer (pfile)
      cpp_reader *pfile;
 {
   cpp_buffer *buffer;
   struct if_stack *ifs;
-  int in_do_line = pfile->directive == &dtable[T_LINE];
 
-  do
+  for (;;)
     {
       buffer = pfile->buffer;
       /* Walk back up the conditional stack till we reach its level at
@@ -1799,28 +1796,34 @@ cpp_pop_buffer (pfile)
 			     "unterminated #%s", dtable[ifs->type].name);
 
       if (buffer->type == BUF_FAKE)
-	{
-	  if (!in_do_line)
-	    cpp_warning (pfile, "file \"%s\" entered but not left",
-			 buffer->nominal_fname);
-
-	  buffer->prev->cur = buffer->cur;
-	}
+	buffer->prev->cur = buffer->cur;
       else if (buffer->type == BUF_FILE)
 	_cpp_pop_file_buffer (pfile, buffer);
 
       pfile->buffer = buffer->prev;
       pfile->buffer_stack_depth--;
 
-      if ((buffer->type == BUF_FILE || buffer->type == BUF_FAKE)
-	  && pfile->buffer)
-	{
-	  do_file_change (pfile, FC_LEAVE, buffer->nominal_fname,
-			  buffer->lineno);
-	  pfile->buffer->include_stack_listed = 0;
-	}
+      /* Callbacks only generated for faked or real files.  */
+      if (buffer->type != BUF_FILE && buffer->type != BUF_FAKE)
+	break;
+	  
+      /* No callback for EOF of last file.  */
+      if (!pfile->buffer)
+	break;
+
+      /* do_line does its own call backs.  */
+      pfile->buffer->include_stack_listed = 0;
+      if (pfile->directive == &dtable[T_LINE])
+	break;
+
+      _cpp_do_file_change (pfile, FC_LEAVE, buffer->nominal_fname,
+			   buffer->lineno);
+      if (pfile->buffer->type == BUF_FILE)
+	break;
+
+      cpp_warning (pfile, "file \"%s\" entered but not left",
+		   buffer->nominal_fname);
     }
-  while (pfile->buffer && pfile->buffer->type == BUF_FAKE && !in_do_line);
 
   obstack_free (pfile->buffer_ob, buffer);
   return pfile->buffer;
Index: cpplib.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.h,v
retrieving revision 1.152
diff -u -p -r1.152 cpplib.h
--- cpplib.h	2000/12/17 22:40:31	1.152
+++ cpplib.h	2000/12/18 12:38:07
@@ -590,7 +590,7 @@ struct cpp_reader
 
   /* Call backs.  */
   struct {
-    void (*change_file) PARAMS ((cpp_reader *, const cpp_file_change *));
+    void (*file_change) PARAMS ((cpp_reader *, const cpp_file_change *));
     void (*include) PARAMS ((cpp_reader *, const unsigned char *,
 			     const cpp_token *));
     void (*define) PARAMS ((cpp_reader *, cpp_hashnode *));
Index: cppmain.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppmain.c,v
retrieving revision 1.47
diff -u -p -r1.47 cppmain.c
--- cppmain.c	2000/12/17 14:46:33	1.47
+++ cppmain.c	2000/12/18 12:38:11
@@ -57,7 +57,7 @@ static void cb_undef	PARAMS ((cpp_reader
 static void cb_include	PARAMS ((cpp_reader *, const unsigned char *,
 				 const cpp_token *));
 static void cb_ident	  PARAMS ((cpp_reader *, const cpp_string *));
-static void cb_change_file PARAMS ((cpp_reader *, const cpp_file_change *));
+static void cb_file_change PARAMS ((cpp_reader *, const cpp_file_change *));
 static void cb_def_pragma PARAMS ((cpp_reader *));
 static void do_pragma_implementation PARAMS ((cpp_reader *));
 
@@ -154,7 +154,7 @@ setup_callbacks ()
       pfile->cb.ident      = cb_ident;
       pfile->cb.def_pragma = cb_def_pragma;
       if (! CPP_OPTION (pfile, no_line_commands))
-	pfile->cb.change_file = cb_change_file;
+	pfile->cb.file_change = cb_file_change;
     }
 
   if (CPP_OPTION (pfile, dump_includes))
@@ -374,7 +374,7 @@ cb_include (pfile, dir, header)
 }
 
 static void
-cb_change_file (pfile, fc)
+cb_file_change (pfile, fc)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
      const cpp_file_change *fc;
 {
Index: fix-header.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fix-header.c,v
retrieving revision 1.58
diff -u -p -r1.58 fix-header.c
--- fix-header.c	2000/12/11 18:22:32	1.58
+++ fix-header.c	2000/12/18 12:38:12
@@ -199,7 +199,7 @@ static int inf_skip_spaces PARAMS ((int)
 static int inf_read_upto PARAMS ((sstring *, int));
 static int inf_scan_ident PARAMS ((sstring *, int));
 static int check_protection PARAMS ((int *, int *));
-static void cb_change_file PARAMS ((cpp_reader *, const cpp_file_change *));
+static void cb_file_change PARAMS ((cpp_reader *, const cpp_file_change *));
 
 static void
 add_symbols (flags, names)
@@ -598,7 +598,7 @@ check_macro_names (pfile, names)
 }
 
 static void
-cb_change_file (pfile, fc)
+cb_file_change (pfile, fc)
      cpp_reader *pfile ATTRIBUTE_UNUSED;
      const cpp_file_change *fc;
 {
@@ -620,7 +620,7 @@ read_scan_file (in_fname, argc, argv)
   obstack_init (&scan_file_obstack); 
 
   scan_in = cpp_create_reader (CLK_GNUC89);
-  scan_in->cb.change_file = cb_change_file;
+  scan_in->cb.file_change = cb_file_change;
 
   /* We are going to be scanning a header file out of its proper context,
      so ignore warnings and errors.  */

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