aboutsummaryrefslogtreecommitdiff
path: root/gcc/cppinit.c
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 /gcc/cppinit.c
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
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r--gcc/cppinit.c76
1 files changed, 29 insertions, 47 deletions
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. */