cpplib: Small cleanup
Neil Booth
neil@daikokuya.demon.co.uk
Tue Aug 21 23:40:00 GMT 2001
Bootstrapping x86 Linux.
Neil.
* cppfiles.c (_cpp_pop_file_buffer): Handle -include file pushing
and file change callback generation here.
* cpphash.h (_cpp_pop_file_buffer): Update prototype.
* cppinit.c (cpp_handle_option): Use free_chain.
* cpplex.c (_cpp_lex_token): Don't do -include file pushing here.
* cpplib.c (_cpp_pop_buffer): Don't do file change callback
generation here.
Index: cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.128
diff -u -p -r1.128 cppfiles.c
--- cppfiles.c 2001/08/21 23:05:09 1.128
+++ cppfiles.c 2001/08/22 06:21:50
@@ -720,14 +720,12 @@ _cpp_read_file (pfile, fname)
}
/* Do appropriate cleanup when a file buffer is popped off the input
- stack. */
+ stack. Push the next -include file, if any remain. */
void
-_cpp_pop_file_buffer (pfile, buf)
+_cpp_pop_file_buffer (pfile, inc)
cpp_reader *pfile;
- cpp_buffer *buf;
+ struct include_file *inc;
{
- struct include_file *inc = buf->inc;
-
/* Record the inclusion-preventing macro, which could be NULL
meaning no controlling macro. */
if (pfile->mi_valid && inc->cmacro == NULL)
@@ -739,6 +737,16 @@ _cpp_pop_file_buffer (pfile, buf)
inc->refcnt--;
if (inc->refcnt == 0 && DO_NOT_REREAD (inc))
purge_cache (inc);
+
+ /* Don't generate a callback for popping the main file. */
+ if (pfile->buffer)
+ {
+ _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0);
+
+ /* Finally, push the next -included file, if any. */
+ if (!pfile->buffer->prev)
+ _cpp_push_next_buffer (pfile);
+ }
}
/* Returns the first place in the include chain to start searching for
Index: cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpphash.h,v
retrieving revision 1.121
diff -u -p -r1.121 cpphash.h
--- cpphash.h 2001/08/21 23:05:09 1.121
+++ cpphash.h 2001/08/22 06:21:56
@@ -391,7 +391,8 @@ extern int _cpp_compare_file_date
extern void _cpp_report_missing_guards PARAMS ((cpp_reader *));
extern void _cpp_init_includes PARAMS ((cpp_reader *));
extern void _cpp_cleanup_includes PARAMS ((cpp_reader *));
-extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *, cpp_buffer *));
+extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *,
+ struct include_file *));
/* In cppexp.c */
extern int _cpp_parse_expr PARAMS ((cpp_reader *));
Index: cppinit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cppinit.c,v
retrieving revision 1.175
diff -u -p -r1.175 cppinit.c
--- cppinit.c 2001/08/21 21:17:47 1.175
+++ cppinit.c 2001/08/22 06:22:03
@@ -1546,15 +1546,7 @@ cpp_handle_option (pfile, argc, argv)
if (arg[1] == '\0')
{
- struct pending_option *o1, *o2;
-
- o1 = pend->directive_head;
- while (o1)
- {
- o2 = o1->next;
- free (o1);
- o1 = o2;
- }
+ free_chain (pend->directive_head);
pend->directive_head = NULL;
pend->directive_tail = NULL;
}
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplex.c,v
retrieving revision 1.156
diff -u -p -r1.156 cpplex.c
--- cpplex.c 2001/08/21 06:20:17 1.156
+++ cpplex.c 2001/08/22 06:22:08
@@ -914,9 +914,6 @@ _cpp_lex_token (pfile, result)
unsigned char stop = buffer->return_at_eof;
_cpp_pop_buffer (pfile);
- /* Push the next -included file, if any. */
- if (!pfile->buffer->prev)
- _cpp_push_next_buffer (pfile);
if (!stop)
goto next_token;
}
Index: cpplib.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cpplib.c,v
retrieving revision 1.270
diff -u -p -r1.270 cpplib.c
--- cpplib.c 2001/08/21 23:05:09 1.270
+++ cpplib.c 2001/08/22 06:22:12
@@ -1785,26 +1785,20 @@ _cpp_pop_buffer (pfile)
cpp_error_with_line (pfile, ifs->pos.line, ifs->pos.col,
"unterminated #%s", dtable[ifs->type].name);
- /* Update the reader's buffer before _cpp_do_file_change. */
- pfile->buffer = buffer->prev;
-
- if (buffer->type == BUF_FILE)
- {
- /* Callbacks are not generated for popping the main file. */
- if (buffer->prev)
- _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0);
-
- _cpp_pop_file_buffer (pfile, buffer);
- }
-
- obstack_free (&pfile->buffer_ob, buffer);
-
/* The output line can fall out of sync if we missed the final
newline from the previous buffer, for example because of an
unterminated comment. Similarly, skipping needs to be cleared in
case of a missing #endif. */
pfile->lexer_pos.output_line = pfile->line;
pfile->state.skipping = 0;
+
+ /* Update the reader's buffer before _cpp_do_file_change. */
+ pfile->buffer = buffer->prev;
+
+ if (buffer->type == BUF_FILE)
+ _cpp_pop_file_buffer (pfile, buffer->inc);
+
+ obstack_free (&pfile->buffer_ob, buffer);
}
void
More information about the Gcc-patches
mailing list