cpplib startup patch

Jason Merrill jason@cygnus.com
Thu Jul 8 18:14:00 GMT 1999


This patch fixes a problem with cpplib reading preprocessed input; it makes
up its mind too soon as to what the main filename is.  If the input has a
#line directive at the beginning, we should respect it.

Thu Jul  8 18:06:30 1999  Jason Merrill  <jason@yorick.cygnus.com>

	* cpplib.c (cpp_unget): New fn.
	(output_initial_line_command): New fn.
	* cppinit.c (cpp_start_read): Use it.

Index: cppinit.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cppinit.c,v
retrieving revision 1.14
diff -c -p -r1.14 cppinit.c
*** cppinit.c	1999/05/10 15:24:34	1.14
--- cppinit.c	1999/07/09 01:09:06
*************** cpp_start_read (pfile, fname)
*** 988,994 ****
    ih_fake->limit = 0;
    if (!finclude (pfile, f, ih_fake))
      return 0;
!   output_line_command (pfile, same_file);
    pfile->only_seen_white = 2;
  
    /* The -imacros files can be scanned now, but the -include files
--- 988,994 ----
    ih_fake->limit = 0;
    if (!finclude (pfile, f, ih_fake))
      return 0;
!   output_initial_line_command (pfile, same_file);
    pfile->only_seen_white = 2;
  
    /* The -imacros files can be scanned now, but the -include files
Index: cpplib.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cpplib.c,v
retrieving revision 1.82
diff -c -p -r1.82 cpplib.c
*** cpplib.c	1999/06/07 10:35:26	1.82
--- cpplib.c	1999/07/09 01:09:06
*************** cpp_file_buffer (pfile)
*** 827,832 ****
--- 827,862 ----
    return NULL;
  }
  
+ /* At the beginning of compilation, we want to feed the frontend a # line
+    directive so it knows what file we're compiling.  But if the input begins
+    with a line directive, use that one instead.  */
+ 
+ void
+ output_initial_line_command (pfile)
+      cpp_reader *pfile;
+ {
+   if (PEEKC() == '#')
+     {
+       int c;
+       unsigned char *save_cur = CPP_BUFFER (pfile)->cur;
+ 
+       FORWARD (1);
+       cpp_skip_hspace (pfile);
+       c = PEEKC ();
+       if (c >= '0' && c <= '9')
+ 	{
+ 	  /* Handle # followed by a line number.  */
+ 	  if (CPP_PEDANTIC (pfile))
+ 	    cpp_pedwarn (pfile, "`#' followed by integer");
+ 	  do_line (pfile, NULL);
+ 	  return;
+ 	}
+       else
+ 	CPP_BUFFER (pfile)->cur = save_cur;
+     }
+ 
+   output_line_command (pfile, same_file);
+ }
  /*
   * write out a #line command, for instance, after an #include file.
   * FILE_CHANGE says whether we are entering a file, leaving, or neither.


More information about the Gcc-patches mailing list