This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFA] Integrated cpp -include -g fix
- To: Neil Booth <neilb at earthling dot net>
- Subject: Re: [RFA] Integrated cpp -include -g fix
- From: Richard Henderson <rth at redhat dot com>
- Date: Mon, 20 Nov 2000 18:45:20 -0800
- Cc: gcc-patches at gcc dot gnu dot org
- References: <20001119122453.A31587@daikokuya.demon.co.uk>
On Sun, Nov 19, 2000 at 12:24:53PM +0000, Neil Booth wrote:
> * toplev.c (delayed_init_parse_hook): New callback.
> (compile_file): Use it.
> * toplev.h (delayed_init_parse_hook): External declaration.
I _really_ don't like the callback. Nor to I like mucking with
the grammar as Zack was suggesting.
Instead I suggest something along these lines.
r~
* c-lex.c (orig_filename): New variable.
(init_c_lex): Set it. Move call to cpp_start_read ...
(yyparse): ... here. New function.
* c-parse.in (yyparse_1): Rename the parser entry point.
* c-tree.h: Declare it.
Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-lex.c,v
retrieving revision 1.114
diff -u -p -r1.114 c-lex.c
--- c-lex.c 2000/11/17 17:31:07 1.114
+++ c-lex.c 2000/11/21 02:42:13
@@ -60,6 +60,9 @@ extern cpp_reader parse_in;
FILE *finput;
#endif
+/* The original file name, before changing "-" to "stdin". */
+static const char *orig_filename;
+
/* Private idea of the line number. See discussion in c_lex(). */
static int lex_lineno;
@@ -170,6 +173,8 @@ init_c_lex (filename)
{
struct c_fileinfo *toplevel;
+ orig_filename = filename;
+
/* Set up filename timing. Must happen before cpp_start_read. */
file_info_tree = splay_tree_new ((splay_tree_compare_fn)strcmp,
0,
@@ -214,9 +219,6 @@ init_c_lex (filename)
/* Make sure parse_in.digraphs matches flag_digraphs. */
CPP_OPTION (&parse_in, digraphs) = flag_digraphs;
- if (! cpp_start_read (&parse_in, filename))
- exit (FATAL_EXIT_CODE); /* cpplib has emitted an error. */
-
if (filename == 0 || !strcmp (filename, "-"))
filename = "stdin";
#endif
@@ -230,6 +232,18 @@ init_c_lex (filename)
lineno = lex_lineno = 0;
return filename;
+}
+
+/* A thin wrapper around the real parser that initializes the
+ integrated preprocessor after debug output has been initialized. */
+
+int
+yyparse()
+{
+ if (! cpp_start_read (&parse_in, orig_filename))
+ return 1; /* cpplib has emitted an error. */
+
+ return yyparse_1();
}
struct c_fileinfo *
Index: c-parse.in
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-parse.in,v
retrieving revision 1.69
diff -u -p -r1.69 c-parse.in
--- c-parse.in 2000/11/18 23:18:35 1.69
+++ c-parse.in 2000/11/21 02:42:13
@@ -72,8 +72,11 @@ end ifc
/* Like YYERROR but do call yyerror. */
#define YYERROR1 { yyerror ("syntax error"); YYERROR; }
-/* Cause the `yydebug' variable to be defined. */
+/* Cause the "yydebug" variable to be defined. */
#define YYDEBUG 1
+
+/* Rename the "yyparse" function so that we can override it elsewhere. */
+#define yyparse yyparse_1
%}
%start program
Index: c-tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/c-tree.h,v
retrieving revision 1.51
diff -u -p -r1.51 c-tree.h
--- c-tree.h 2000/11/18 23:18:35 1.51
+++ c-tree.h 2000/11/21 02:42:13
@@ -154,6 +154,7 @@ extern tree lookup_objc_ivar PARAMS ((
/* in c-parse.in */
extern void c_parse_init PARAMS ((void));
+extern int yyparse_1 PARAMS ((void));
/* in c-aux-info.c */
extern void gen_aux_info_record PARAMS ((tree, int, int, int));