This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[cs] Various init_c_lex patches
- From: Per Bothner <per at bothner dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Thu, 14 Aug 2003 12:59:04 -0700
- Subject: [cs] Various init_c_lex patches
I checked these into the compile-server branch. I don't consider
them ready for the trunk, though they should be safe enough.
The first set of changes is the usual issue of re-initializing data.
The second set splits out some code into a new function
register_cpp_callbacks because the compile-server needs to to do
this at init_xxx_once time rather than init_xxx_eachsrc time.
I think the reason I changed it made the allocation of file_info_tree
lazy was because things were happening in a different order than the
code expected, and lazily allocation seemed the easiest solution. It
might be cleaner to move the allocation to register_cpp_callbacks,
and rename that to init_c_lex_once.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2003-08-14 Per Bothner <pbothner@apple.com>
* c-lex.c (init_c_lex): Clear map - needed if server starts new file.
(fe_file_change): Handle new_map == NULL.
* c-lex.c (register_cpp_callbacks): New function.
Move stuff out of init_c_lex.
* c-opts.c (c_common_post_options): Call it.
* c-common.h (register_cpp_callbacks): New declaration.
* c-lex.c (init_c_lex): Don't allocate file_info_tree here.
(get_fileinfo): Instead allocate it lazily here.
(dump_time_statistics): Check that file_info_tree is non-NULL.
Index: c-lex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lex.c,v
retrieving revision 1.209.2.1
diff -u -r1.209.2.1 c-lex.c
--- c-lex.c 12 Aug 2003 23:06:49 -0000 1.209.2.1
+++ c-lex.c 14 Aug 2003 19:38:26 -0000
@@ -81,13 +81,8 @@
void
init_c_lex (void)
{
- struct cpp_callbacks *cb;
struct c_fileinfo *toplevel;
- /* Set up filename timing. Must happen before cpp_read_main_file. */
- file_info_tree = splay_tree_new ((splay_tree_compare_fn)strcmp,
- 0,
- (splay_tree_delete_value_fn)free);
toplevel = get_fileinfo ("<top level>");
if (flag_detailed_statistics)
{
@@ -95,7 +90,13 @@
body_time = get_run_time ();
toplevel->time = body_time;
}
+ map = NULL;
+}
+void
+register_cpp_callbacks ()
+{
+ struct cpp_callbacks *cb;
cb = cpp_get_callbacks (parse_in);
cb->line_change = cb_line_change;
@@ -121,6 +122,11 @@
splay_tree_node n;
struct c_fileinfo *fi;
+ /* Set up filename timing. Must happen before cpp_read_main_file. */
+ if (file_info_tree == NULL)
+ file_info_tree = splay_tree_new ((splay_tree_compare_fn)strcmp,
+ 0,
+ (splay_tree_delete_value_fn)free);
n = splay_tree_lookup (file_info_tree, (splay_tree_key) name);
if (n)
return (struct c_fileinfo *) n->value;
@@ -171,7 +177,8 @@
(double)header_time / (double)(this_time - body_time));
fprintf (stderr, "\n******\n");
- splay_tree_foreach (file_info_tree, dump_one_header, 0);
+ if (file_info_tree != NULL)
+ splay_tree_foreach (file_info_tree, dump_one_header, 0);
}
static void
@@ -212,7 +219,14 @@
void
fe_file_change (const struct line_map *new_map)
{
- unsigned int to_line = SOURCE_LINE (new_map, new_map->to_line);
+ unsigned int to_line;
+ if (new_map == NULL)
+ {
+ map = NULL;
+ return;
+ }
+
+ to_line = SOURCE_LINE (new_map, new_map->to_line);
if (new_map->reason == LC_ENTER)
{
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.194.2.1
diff -u -r1.194.2.1 c-common.h
--- c-common.h 12 Aug 2003 23:06:48 -0000 1.194.2.1
+++ c-common.h 14 Aug 2003 19:38:27 -0000
@@ -1258,6 +1258,7 @@
extern int c_common_unsafe_for_reeval (tree);
extern void init_c_lex (void);
+extern void register_cpp_callbacks (void);
extern void c_cpp_builtins (cpp_reader *);
Index: c-opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-opts.c,v
retrieving revision 1.79.2.1
diff -u -r1.79.2.1 c-opts.c
--- c-opts.c 12 Aug 2003 23:06:50 -0000 1.79.2.1
+++ c-opts.c 14 Aug 2003 19:38:28 -0000
@@ -1119,6 +1119,7 @@
}
else
{
+ register_cpp_callbacks ();
init_c_lex ();
/* Yuk. WTF is this? I do know ObjC relies on it somewhere. */
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ChangeLog,v
retrieving revision 2.618.2.4
diff -u -r2.618.2.4 ChangeLog
--- ChangeLog 14 Aug 2003 19:13:23 -0000 2.618.2.4
+++ ChangeLog 14 Aug 2003 19:38:31 -0000
@@ -1,3 +1,17 @@
+2003-08-14 Per Bothner <pbothner@apple.com>
+
+ * c-lex.c (init_c_lex): Clear map - needed if server starts new file.
+ (fe_file_change): Handle new_map == NULL.
+
+ * c-lex.c (register_cpp_callbacks): New function.
+ Move stuff out of init_c_lex.
+ * c-opts.c (c_common_post_options): Call it.
+ * c-common.h (register_cpp_callbacks): New declaration.
+
+ * c-lex.c (init_c_lex): Don't allocate file_info_tree here.
+ (get_fileinfo): Instead allocate it lazily here.
+ (dump_time_statistics): Check that file_info_tree is non-NULL.
+
2003-08-14 Per Bothner <bothner@pbothner.com>
* cppfiles.c (stack_file): Correctly pass return_at_eof parameter