aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2002-04-22 17:48:02 +0000
committerNeil Booth <neil@gcc.gnu.org>2002-04-22 17:48:02 +0000
commitaf0d16cdec59d270a017f82ac209c44dfa748ea3 (patch)
tree0fc130b06a7d9e6cdc2502aaa5f671bb726c8773
parent74b273d68f6a479fa9a563ff87ef3e9561408c2c (diff)
downloadgcc-af0d16cdec59d270a017f82ac209c44dfa748ea3.zip
gcc-af0d16cdec59d270a017f82ac209c44dfa748ea3.tar.gz
gcc-af0d16cdec59d270a017f82ac209c44dfa748ea3.tar.bz2
cppfiles.c (_cpp_pop_file_buffer): Return void.
* cppfiles.c (_cpp_pop_file_buffer): Return void. Move file change and include code to _cpp_pop_buffer. * cpphash.h (struct pending_option): Predeclare. (struct cpp_reader): New member next_include_file. (_cpp_pop_file_buffer): Update. (_cpp_push_next_buffer): Update, rename. * cppinit.c (cpp_destroy): Free include chain and pending here. (cpp_finish_options): Simplify. (_cpp_push_next_buffer): Rename and clean up. * cpplib.c (cpp_pop_buffer): Move code from _cpp_pop_file_buffer. Clarify. * cppmacro.c (cpp_scan_nooutput): Set return_at_eof here. From-SVN: r52621
-rw-r--r--gcc/ChangeLog15
-rw-r--r--gcc/cppfiles.c18
-rw-r--r--gcc/cpphash.h10
-rw-r--r--gcc/cppinit.c76
-rw-r--r--gcc/cpplib.c31
-rw-r--r--gcc/cppmacro.c8
6 files changed, 82 insertions, 76 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 0338958..8d9bb2c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,18 @@
+2002-04-22 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * cppfiles.c (_cpp_pop_file_buffer): Return void. Move
+ file change and include code to _cpp_pop_buffer.
+ * cpphash.h (struct pending_option): Predeclare.
+ (struct cpp_reader): New member next_include_file.
+ (_cpp_pop_file_buffer): Update.
+ (_cpp_push_next_buffer): Update, rename.
+ * cppinit.c (cpp_destroy): Free include chain and pending here.
+ (cpp_finish_options): Simplify.
+ (_cpp_push_next_buffer): Rename and clean up.
+ * cpplib.c (cpp_pop_buffer): Move code from _cpp_pop_file_buffer.
+ Clarify.
+ * cppmacro.c (cpp_scan_nooutput): Set return_at_eof here.
+
2002-04-22 Aldy Hernandez <aldyh@redhat.com>
* config/rs6000/altivec.h (vec_xor): Add variant for both args
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index 38780ad..7600523 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -761,14 +761,12 @@ _cpp_read_file (pfile, fname)
}
/* Do appropriate cleanup when a file INC's buffer is popped off the
- input stack. Push the next -include file, if any remain. */
-bool
+ input stack. */
+void
_cpp_pop_file_buffer (pfile, inc)
cpp_reader *pfile;
struct include_file *inc;
{
- bool pushed = false;
-
/* Record the inclusion-preventing macro, which could be NULL
meaning no controlling macro. */
if (pfile->mi_valid && inc->cmacro == NULL)
@@ -780,18 +778,6 @@ _cpp_pop_file_buffer (pfile, inc)
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)
- pushed = _cpp_push_next_buffer (pfile);
- }
-
- return pushed;
}
/* Returns the first place in the include chain to start searching for
diff --git a/gcc/cpphash.h b/gcc/cpphash.h
index e101bb3..773c3cc 100644
--- a/gcc/cpphash.h
+++ b/gcc/cpphash.h
@@ -26,6 +26,7 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "hashtable.h"
struct directive; /* Deliberately incomplete. */
+struct pending_option;
/* Test if a sign is valid within a preprocessing number. */
#define VALID_SIGN(c, prevc) \
@@ -250,6 +251,11 @@ struct cpp_reader
/* If in_directive, the directive if known. */
const struct directive *directive;
+ /* The next -include-d file; NULL if they all are done. If it
+ points to NULL, the last one is in progress, and
+ _cpp_maybe_push_include_file has yet to restore the line map. */
+ struct pending_option **next_include_file;
+
/* Multiple inlcude optimisation. */
const cpp_hashnode *mi_cmacro;
const cpp_hashnode *mi_ind_cmacro;
@@ -381,7 +387,7 @@ extern int _cpp_compare_file_date PARAMS ((cpp_reader *,
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 bool _cpp_pop_file_buffer PARAMS ((cpp_reader *,
+extern void _cpp_pop_file_buffer PARAMS ((cpp_reader *,
struct include_file *));
/* In cppexp.c */
@@ -396,7 +402,7 @@ extern int _cpp_equiv_tokens PARAMS ((const cpp_token *,
extern void _cpp_init_tokenrun PARAMS ((tokenrun *, unsigned int));
/* In cppinit.c. */
-extern bool _cpp_push_next_buffer PARAMS ((cpp_reader *));
+extern void _cpp_maybe_push_include_file PARAMS ((cpp_reader *));
/* In cpplib.c */
extern int _cpp_test_assertion PARAMS ((cpp_reader *, int *));
diff --git a/gcc/cppinit.c b/gcc/cppinit.c
index 8caf2ed..c444f83 100644
--- a/gcc/cppinit.c
+++ b/gcc/cppinit.c
@@ -554,6 +554,9 @@ cpp_destroy (pfile)
cpp_context *context, *contextn;
tokenrun *run, *runn;
+ free_chain (CPP_OPTION (pfile, pending)->include_head);
+ free (CPP_OPTION (pfile, pending));
+
while (CPP_BUFFER (pfile) != NULL)
_cpp_pop_buffer (pfile);
@@ -1014,65 +1017,44 @@ cpp_finish_options (pfile)
for (p = CPP_OPTION (pfile, pending)->directive_head; p; p = p->next)
(*p->handler) (pfile, p->arg);
- /* Scan -imacros files after command line defines, but before
- files given with -include. */
- while ((p = CPP_OPTION (pfile, pending)->imacros_head) != NULL)
- {
- if (push_include (pfile, p))
- {
- pfile->buffer->return_at_eof = true;
- cpp_scan_nooutput (pfile);
- }
- CPP_OPTION (pfile, pending)->imacros_head = p->next;
- free (p);
- }
+ /* Scan -imacros files after -D, -U, but before -include.
+ pfile->next_include_file is NULL, so _cpp_pop_buffer does not
+ push -include files. */
+ for (p = CPP_OPTION (pfile, pending)->imacros_head; p; p = p->next)
+ if (push_include (pfile, p))
+ cpp_scan_nooutput (pfile);
+
+ pfile->next_include_file = &CPP_OPTION (pfile, pending)->include_head;
+ _cpp_maybe_push_include_file (pfile);
}
+ free_chain (CPP_OPTION (pfile, pending)->imacros_head);
free_chain (CPP_OPTION (pfile, pending)->directive_head);
- _cpp_push_next_buffer (pfile);
}
-/* Called to push the next buffer on the stack given by -include. If
- there are none, free the pending structure and restore the line map
- for the main file. */
-bool
-_cpp_push_next_buffer (pfile)
+/* Push the next buffer on the stack given by -include, if any. */
+void
+_cpp_maybe_push_include_file (pfile)
cpp_reader *pfile;
{
- bool pushed = false;
-
- /* This is't pretty; we'd rather not be relying on this as a boolean
- for reverting the line map. Further, we only free the chains in
- this conditional, so an early call to cpp_finish / cpp_destroy
- will leak that memory. */
- if (CPP_OPTION (pfile, pending)
- && CPP_OPTION (pfile, pending)->imacros_head == NULL)
+ if (pfile->next_include_file)
{
- while (!pushed)
- {
- struct pending_option *p = CPP_OPTION (pfile, pending)->include_head;
-
- if (p == NULL)
- break;
- if (! CPP_OPTION (pfile, preprocessed))
- pushed = push_include (pfile, p);
- CPP_OPTION (pfile, pending)->include_head = p->next;
- free (p);
- }
+ struct pending_option *head = *pfile->next_include_file;
+
+ while (head && !push_include (pfile, head))
+ head = head->next;
- if (!pushed)
+ if (head)
+ pfile->next_include_file = &head->next;
+ else
{
- free (CPP_OPTION (pfile, pending));
- CPP_OPTION (pfile, pending) = NULL;
-
- /* Restore the line map for the main file. */
- if (! CPP_OPTION (pfile, preprocessed))
- _cpp_do_file_change (pfile, LC_RENAME,
- pfile->line_maps.maps[0].to_file, 1, 0);
+ /* All done; restore the line map from <command line>. */
+ _cpp_do_file_change (pfile, LC_RENAME,
+ pfile->line_maps.maps[0].to_file, 1, 0);
+ /* Don't come back here again. */
+ pfile->next_include_file = NULL;
}
}
-
- return pushed;
}
/* Use mkdeps.c to output dependency information. */
diff --git a/gcc/cpplib.c b/gcc/cpplib.c
index dddf86a..712b9df 100644
--- a/gcc/cpplib.c
+++ b/gcc/cpplib.c
@@ -1900,16 +1900,15 @@ cpp_push_buffer (pfile, buffer, len, from_stage3, return_at_eof)
return new;
}
-/* If called from do_line, pops a single buffer. Otherwise pops all
- buffers until a real file is reached. Generates appropriate
- call-backs. */
+/* Pops a single buffer, with a file change call-back if appropriate.
+ Then pushes the next -include file, if any remain. */
void
_cpp_pop_buffer (pfile)
cpp_reader *pfile;
{
cpp_buffer *buffer = pfile->buffer;
+ struct include_file *inc = buffer->inc;
struct if_stack *ifs;
- bool pushed = false;
/* Walk back up the conditional stack till we reach its level at
entry to this file, issuing error messages. */
@@ -1920,14 +1919,28 @@ _cpp_pop_buffer (pfile)
/* In case of a missing #endif. */
pfile->state.skipping = 0;
- /* Update the reader's buffer before _cpp_do_file_change. */
+ /* _cpp_do_file_change expects pfile->buffer to be the new one. */
pfile->buffer = buffer->prev;
- if (buffer->inc)
- pushed = _cpp_pop_file_buffer (pfile, buffer->inc);
+ /* Free the buffer object now; we may want to push a new buffer
+ in _cpp_push_next_include_file. */
+ obstack_free (&pfile->buffer_ob, buffer);
- if (!pushed)
- obstack_free (&pfile->buffer_ob, buffer);
+ if (inc)
+ {
+ _cpp_pop_file_buffer (pfile, inc);
+
+ /* Don't generate a callback for popping the main file. */
+ if (pfile->buffer)
+ {
+ _cpp_do_file_change (pfile, LC_LEAVE, 0, 0, 0);
+
+ /* If this is the main file, there may be some -include
+ files left to push. */
+ if (!pfile->buffer->prev)
+ _cpp_maybe_push_include_file (pfile);
+ }
+ }
}
/* Enter all recognised directives in the hash table. */
diff --git a/gcc/cppmacro.c b/gcc/cppmacro.c
index aa2e58b..876506b 100644
--- a/gcc/cppmacro.c
+++ b/gcc/cppmacro.c
@@ -1074,12 +1074,16 @@ cpp_sys_macro_p (pfile)
return node && node->value.macro && node->value.macro->syshdr;
}
-/* Read each token in, until EOF. Directives are transparently
- processed. */
+/* Read each token in, until end of the current file. Directives are
+ transparently processed. */
void
cpp_scan_nooutput (pfile)
cpp_reader *pfile;
{
+ /* Request a CPP_EOF token at the end of this file, rather than
+ transparently continuing with the including file. */
+ pfile->buffer->return_at_eof = true;
+
while (cpp_get_token (pfile)->type != CPP_EOF)
;
}