This is the mail archive of the
egcs-patches@egcs.cygnus.com
mailing list for the EGCS project.
Re: cpplib startup patch
- To: Jason Merrill <jason@cygnus.com>
- Subject: Re: cpplib startup patch
- From: Dave Brolley <brolley@cygnus.com>
- Date: Mon, 12 Jul 1999 14:36:46 -0400
- CC: zack@blastula.phys.columbia.edu, egcs-patches@egcs.cygnus.com
- Organization: Cygnus Solutions Canada Ltd
- References: <199907090114.SAA19395@yorick.cygnus.com>
I've looked into this a bit more and now I'm confused. It appears as though the C
and C++ front ends use already check_newline to recognize an initial #line
directive (actually any initial directive) and it is done in lang_init whether
cpplib is used or not. Is the problem that this is too late to check this? If so,
then it's not a cpplib specific problem. If not, then I need help understanding
the need for this patch.
Also, it turns out that the code in check_newline will recognize an initial #line
directive which begins with whitespace.
Thanks,
Dave
Jason Merrill wrote:
> 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.