This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: splitting up cpplib, revised
- To: Dave Brolley <brolley at cygnus dot com>
- Subject: Re: splitting up cpplib, revised
- From: Zack Weinberg <zack at rabi dot columbia dot edu>
- Date: Mon, 26 Oct 1998 22:50:08 -0500
- cc: bothner at cygnus dot com, egcs-patches at cygnus dot com
On Mon, 26 Oct 1998 11:08:40 -0500, Dave Brolley wrote:
>I have no problems with the intent and structure of this patch. I can't commen
>t on the VMS stuff and would like to see
>this reviewd by a VMS guru before approval.
Ok. That would probably be Klaus Kempf, right?
In the meantime, here's another patch. This one is pure bugfix: it
makes -include work properly when cpplib is linked into cc1. The
problem was that cpp_start_read was processing the -included file
through to the token_buffer, but c-lex.c didn't expect anything to be
in the token_buffer until after cpp_get_token had been called for the
first time.
The change in init_parse fixed that, but then another bug appeared in
the nesting of #line directives. The only way to cure that was to
pretend that -included files were pulled in by a chain of #include
directives. In other words, if you compile x.c with -include a.h
-include b.h, it's as if the first line of x.c is #include "b.h" and
the first line of b.h is #include "a.h". The `In file included
from...' listing on an error in a.h looks a bit weird, but that's
harmless.
This patch should be independent of the splitup patch except that the
hunk for cpplib.c is offset a bit.
zw
1998-10-26 22:42 -0500 Zack Weinberg <zack@rabi.phys.columbia.edu>
* c-lang.c: Declare extern char *yy_cur if USE_CPPLIB.
(lang_init): Call check_newline always.
* c-lex.c (init_parse) [USE_CPPLIB=1]: After calling
cpp_start_read, set yy_cur and yy_lim to read from
parse_in.token_buffer, so that we'll see the first #line
directive.
* cpplib.c (cpp_start_read): finclude the main input file
before processing -include/-imacros. Process -imacros and
-include separately, and handle -include by stacking a
buffer for the file in question as if it'd been #included.
* toplev.c (documented_lang_options) Recognize -H when
USE_CPPLIB is on.
============================================================
Index: c-lang.c
--- c-lang.c 1998/06/19 21:58:00 1.14
+++ c-lang.c 1998/10/27 03:30:38
@@ -28,6 +28,10 @@
#include "toplev.h"
#include "output.h"
+#if USE_CPPLIB
+extern char *yy_cur;
+#endif
+
/* Each of the functions defined here
is an alternative to a function in objc-actions.c. */
@@ -47,12 +51,15 @@
void
lang_init ()
{
-#if !USE_CPPLIB
/* the beginning of the file is a new line; check for # */
/* With luck, we discover the real source file's name from that
and put it in input_filename. */
+#if !USE_CPPLIB
ungetc (check_newline (), finput);
-#endif
+#else
+ check_newline ();
+ yy_cur--;
+#endif
}
void
============================================================
Index: c-lex.c
--- c-lex.c 1998/10/21 09:53:23 1.36
+++ c-lex.c 1998/10/27 03:30:39
@@ -194,12 +194,14 @@
init_lex ();
#if USE_CPPLIB
- yy_cur = "\n";
- yy_lim = yy_cur+1;
-
parse_in.show_column = 1;
if (! cpp_start_read (&parse_in, filename))
abort ();
+
+ /* cpp_start_read always puts at least one line directive into the
+ token buffer. We must arrange to read it out here. */
+ yy_cur = parse_in.token_buffer;
+ yy_lim = CPP_PWRITTEN (&parse_in);
#endif
return filename;
============================================================
Index: cpplib.c
--- cpplib.c 1998/10/17 20:26:10 1.39
+++ cpplib.c 1998/10/27 03:30:40
@@ -6142,18 +5421,27 @@
trigraph_pcp (fp);
#endif
- /* Avoid a #line 0 if -include files are present. */
- CPP_BUFFER (pfile)->lineno = 1;
+ /* Must call finclude() on the main input before processing
+ -include switches; otherwise the -included text winds up
+ after the main input. */
+ if (!finclude (pfile, f, fname, 0, NULL_PTR))
+ return 0;
output_line_command (pfile, 0, same_file);
-
- /* Scan the -include and -imacros files before the main input. */
+ pfile->only_seen_white = 2;
+ /* The -imacros files can be scanned now, but the -include files
+ have to be pushed onto the include stack and processed later,
+ in the main loop calling cpp_get_token. That means the -include
+ files have to be processed in reverse order of the pending list,
+ which means the pending list has to be reversed again, which
+ means the -imacros files have to be done separately and first. */
+
pfile->no_record_file++;
- for (pend = opts->pending; pend; pend = pend->next)
+ for (pend = opts->pending; pend; pend = pend->next)
{
if (pend->cmd != NULL)
{
- if (strcmp (pend->cmd, "-include") == 0)
+ if (strcmp (pend->cmd, "-imacros") == 0)
{
int fd = open (pend->arg, O_RDONLY, 0666);
if (fd < 0)
@@ -6163,13 +5451,19 @@
}
if (!cpp_push_buffer (pfile, NULL, 0))
return 0;
+ opts->no_output++;
if (finclude (pfile, fd, pend->arg, 0, NULL_PTR))
- {
- output_line_command (pfile, 0, enter_file);
- cpp_scan_buffer (pfile);
- }
+ cpp_scan_buffer (pfile);
+ opts->no_output--;
}
- else if (strcmp (pend->cmd, "-imacros") == 0)
+ }
+ }
+ opts->pending = nreverse_pending (opts->pending);
+ for (pend = opts->pending; pend; pend = pend->next)
+ {
+ if (pend->cmd != NULL)
+ {
+ if (strcmp (pend->cmd, "-include") == 0)
{
int fd = open (pend->arg, O_RDONLY, 0666);
if (fd < 0)
@@ -6177,12 +5471,10 @@
cpp_perror_with_name (pfile, pend->arg);
return 0;
}
- opts->no_output++;
if (!cpp_push_buffer (pfile, NULL, 0))
return 0;
if (finclude (pfile, fd, pend->arg, 0, NULL_PTR))
- cpp_scan_buffer (pfile);
- opts->no_output--;
+ output_line_command (pfile, 0, enter_file);
}
}
}
@@ -6197,19 +5489,6 @@
}
opts->pending = NULL;
-#if 0
- /* Scan the input, processing macros and directives. */
-
- rescan (&outbuf, 0);
-
- if (missing_newline)
- fp->lineno--;
-
- if (CPP_PEDANTIC (pfile) && missing_newline)
- pedwarn ("file does not end in newline");
-
-#endif
- finclude (pfile, f, fname, 0, NULL_PTR);
return 1;
}
============================================================
Index: toplev.c
--- toplev.c 1998/10/21 09:53:37 1.115
+++ toplev.c 1998/10/27 03:30:40
@@ -1045,6 +1045,7 @@
{ "-D", "" },
{ "-I", "" },
{ "-U", "" },
+ { "-H", "" },
{ "-idirafter", "" },
{ "-imacros", "" },
{ "-include", "" },