aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNeil Booth <neil@daikokuya.demon.co.uk>2001-03-12 19:33:08 +0000
committerNeil Booth <neil@gcc.gnu.org>2001-03-12 19:33:08 +0000
commita36c54fabab4595c4161a79e26e045cd1597c971 (patch)
tree3888ea0f212aaf4b34b075ff3e0afebc5629539e /gcc
parente6ff97b1c4f478ca3565810aa4bc81cc3aa114ae (diff)
downloadgcc-a36c54fabab4595c4161a79e26e045cd1597c971.zip
gcc-a36c54fabab4595c4161a79e26e045cd1597c971.tar.gz
gcc-a36c54fabab4595c4161a79e26e045cd1597c971.tar.bz2
cppfiles.c: Update comments.
* cppfiles.c: Update comments. (destroy_include_file_node): Rename destroy_node. (find_or_create_entry): New function. (open_file, _cpp_fake_include): Use it. (handle_missing_header): New function, broken out of _cpp_execute include. Don't segfault if there is no system or quoted path. (_cpp_execute_include): Use handle_missing_header. From-SVN: r40423
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog11
-rw-r--r--gcc/cppfiles.c221
2 files changed, 127 insertions, 105 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 439959a..5870db9 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@
+2001-03-12 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * cppfiles.c: Update comments.
+ (destroy_include_file_node): Rename destroy_node.
+ (find_or_create_entry): New function.
+ (open_file, _cpp_fake_include): Use it.
+ (handle_missing_header): New function, broken out of
+ _cpp_execute include. Don't segfault if there is no
+ system or quoted path.
+ (_cpp_execute_include): Use handle_missing_header.
+
2001-03-12 Jeffrey Oldham <oldham@codesourcery.com>
* jump.c (reversed_comparison_code_parts): Reverse Jan Hubricka's
diff --git a/gcc/cppfiles.c b/gcc/cppfiles.c
index e4d8ec1..197a8bc 100644
--- a/gcc/cppfiles.c
+++ b/gcc/cppfiles.c
@@ -97,27 +97,24 @@ static struct include_file *open_file PARAMS ((cpp_reader *, const char *));
static void read_include_file PARAMS ((cpp_reader *, struct include_file *));
static void stack_include_file PARAMS ((cpp_reader *, struct include_file *));
static void purge_cache PARAMS ((struct include_file *));
-static void destroy_include_file_node PARAMS ((splay_tree_value));
+static void destroy_node PARAMS ((splay_tree_value));
static int report_missing_guard PARAMS ((splay_tree_node, void *));
-
-/* We use a splay tree to store information about all the include
- files seen in this compilation. The key of each tree node is the
- physical path to the file. The value is 0 if the file does not
- exist, or a struct include_file pointer. */
-
-static void
-destroy_include_file_node (v)
- splay_tree_value v;
-{
- struct include_file *f = (struct include_file *)v;
-
- if (f)
- {
- purge_cache (f);
- free (f); /* The tree is registered with free to free f->name. */
- }
-}
-
+static splay_tree_node find_or_create_entry PARAMS ((cpp_reader *,
+ const char *));
+static void handle_missing_header PARAMS ((cpp_reader *, const char *, int));
+
+/* Set up the splay tree we use to store information about all the
+ file names seen in this compilation. We also have entries for each
+ file we tried to open but failed; this saves system calls since we
+ don't try to open it again in future.
+
+ The key of each node is the file name, after processing by
+ _cpp_simplify_pathname. The path name may or may not be absolute.
+ The path string has been malloced, as is automatically freed by
+ registering free () as the splay tree key deletion function.
+
+ A node's value is a pointer to a struct include_file, and is never
+ NULL. */
void
_cpp_init_includes (pfile)
cpp_reader *pfile;
@@ -125,9 +122,10 @@ _cpp_init_includes (pfile)
pfile->all_include_files
= splay_tree_new ((splay_tree_compare_fn) strcmp,
(splay_tree_delete_key_fn) free,
- destroy_include_file_node);
+ destroy_node);
}
+/* Tear down the splay tree. */
void
_cpp_cleanup_includes (pfile)
cpp_reader *pfile;
@@ -135,6 +133,20 @@ _cpp_cleanup_includes (pfile)
splay_tree_delete (pfile->all_include_files);
}
+/* Free a node. The path string is automatically freed. */
+static void
+destroy_node (v)
+ splay_tree_value v;
+{
+ struct include_file *f = (struct include_file *)v;
+
+ if (f)
+ {
+ purge_cache (f);
+ free (f);
+ }
+}
+
/* Mark a file to not be reread (e.g. #import, read failure). */
void
_cpp_never_reread (file)
@@ -143,24 +155,36 @@ _cpp_never_reread (file)
file->cmacro = NEVER_REREAD;
}
-/* Put a file name in the splay tree, for the sake of cpp_included ().
- Assume that FNAME has already had its path simplified. */
-void
-_cpp_fake_include (pfile, fname)
+/* Lookup a simplified filename, and create an entry if none exists. */
+static splay_tree_node
+find_or_create_entry (pfile, fname)
cpp_reader *pfile;
const char *fname;
{
- splay_tree_node nd;
+ splay_tree_node node;
+ struct include_file *file;
- nd = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) fname);
- if (! nd)
+ node = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) fname);
+ if (! node)
{
- struct include_file *file = xcnew (struct include_file);
+ file = xcnew (struct include_file);
file->name = xstrdup (fname);
- splay_tree_insert (pfile->all_include_files,
- (splay_tree_key) file->name,
- (splay_tree_value) file);
+ node = splay_tree_insert (pfile->all_include_files,
+ (splay_tree_key) file->name,
+ (splay_tree_value) file);
}
+
+ return node;
+}
+
+/* Enter a simplified file name in the splay tree, for the sake of
+ cpp_included (). */
+void
+_cpp_fake_include (pfile, fname)
+ cpp_reader *pfile;
+ const char *fname;
+{
+ find_or_create_entry (pfile, fname);
}
/* Given a file name, look it up in the cache; if there is no entry,
@@ -178,36 +202,20 @@ open_file (pfile, filename)
cpp_reader *pfile;
const char *filename;
{
- splay_tree_node nd;
- struct include_file *file;
-
- nd = splay_tree_lookup (pfile->all_include_files, (splay_tree_key) filename);
-
- if (nd)
- {
- file = (struct include_file *) nd->value;
+ splay_tree_node nd = find_or_create_entry (pfile, filename);
+ struct include_file *file = (struct include_file *) nd->value;
- /* Don't retry opening if we failed previously. */
- if (file->fd == -2)
- return 0;
+ /* Don't retry opening if we failed previously. */
+ if (file->fd == -2)
+ return 0;
- /* Don't reopen an idempotent file. */
- if (DO_NOT_REREAD (file))
- return file;
+ /* Don't reopen an idempotent file. */
+ if (DO_NOT_REREAD (file))
+ return file;
- /* Don't reopen one which is already loaded. */
- if (file->buffer != NULL)
- return file;
- }
- else
- {
- /* In particular, this clears foundhere. */
- file = xcnew (struct include_file);
- file->name = xstrdup (filename);
- splay_tree_insert (pfile->all_include_files,
- (splay_tree_key) file->name,
- (splay_tree_value) file);
- }
+ /* Don't reopen one which is already loaded. */
+ if (file->buffer != NULL)
+ return file;
/* We used to open files in nonblocking mode, but that caused more
problems than it solved. Do take care not to acquire a
@@ -568,6 +576,54 @@ report_missing_guard (n, b)
return 0;
}
+/* Create a dependency, or issue an error message as appropriate. */
+static void
+handle_missing_header (pfile, fname, angle_brackets)
+ cpp_reader *pfile;
+ const char *fname;
+ int angle_brackets;
+{
+ /* We will try making the RHS pfile->buffer->sysp after 3.0. */
+ int print_dep = CPP_PRINT_DEPS(pfile) > (angle_brackets
+ || pfile->system_include_depth);
+ if (CPP_OPTION (pfile, print_deps_missing_files) && print_dep)
+ {
+ if (!angle_brackets || IS_ABSOLUTE_PATHNAME (fname))
+ deps_add_dep (pfile->deps, fname);
+ else
+ {
+ /* If requested as a system header, assume it belongs in
+ the first system header directory. */
+ struct search_path *ptr = CPP_OPTION (pfile, bracket_include);
+ char *p;
+ int len = 0, fname_len = strlen (fname);
+
+ if (ptr)
+ len = ptr->len;
+
+ p = (char *) alloca (len + fname_len + 2);
+ if (len)
+ {
+ memcpy (p, ptr->name, len);
+ p[len++] = '/';
+ }
+ memcpy (p + len, fname, fname_len + 1);
+ _cpp_simplify_pathname (p);
+ deps_add_dep (pfile->deps, p);
+ }
+ }
+ /* If -M was specified, and this header file won't be added to
+ the dependency list, then don't count this as an error,
+ because we can still produce correct output. Otherwise, we
+ can't produce correct output, because there may be
+ dependencies we need inside the missing file, and we don't
+ know what directory this missing file exists in. */
+ else if (CPP_PRINT_DEPS (pfile) && ! print_dep)
+ cpp_warning (pfile, "No include path in which to find %s", fname);
+ else
+ cpp_error_from_errno (pfile, fname);
+}
+
void
_cpp_execute_include (pfile, header, no_reinclude, include_next)
cpp_reader *pfile;
@@ -579,7 +635,6 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
unsigned int angle_brackets = header->type == CPP_HEADER_NAME;
const char *fname = (const char *) header->val.str.text;
struct include_file *inc;
- int print_dep;
/* Help protect #include or similar from recursion. */
if (pfile->buffer_stack_depth >= CPP_STACK_MAX)
@@ -652,53 +707,9 @@ _cpp_execute_include (pfile, header, no_reinclude, include_next)
fprintf (stderr, " %s\n", inc->name);
}
}
-
- return;
}
-
- /* We will try making the RHS pfile->buffer->sysp after 3.0. */
- print_dep = CPP_PRINT_DEPS(pfile) > (angle_brackets
- || pfile->system_include_depth);
- if (CPP_OPTION (pfile, print_deps_missing_files) && print_dep)
- {
- if (!angle_brackets || IS_ABSOLUTE_PATHNAME (fname))
- deps_add_dep (pfile->deps, fname);
- else
- {
- char *p;
- struct search_path *ptr;
- int len;
-
- /* If requested as a system header, assume it belongs in
- the first system header directory. */
- if (CPP_OPTION (pfile, bracket_include))
- ptr = CPP_OPTION (pfile, bracket_include);
- else
- ptr = CPP_OPTION (pfile, quote_include);
-
- /* FIXME: ptr can be null, no? */
- len = ptr->len;
- p = (char *) alloca (len + header->val.str.len + 2);
- if (len)
- {
- memcpy (p, ptr->name, len);
- p[len++] = '/';
- }
- memcpy (p + len, fname, header->val.str.len + 1);
- _cpp_simplify_pathname (p);
- deps_add_dep (pfile->deps, p);
- }
- }
- /* If -M was specified, and this header file won't be added to
- the dependency list, then don't count this as an error,
- because we can still produce correct output. Otherwise, we
- can't produce correct output, because there may be
- dependencies we need inside the missing file, and we don't
- know what directory this missing file exists in. */
- else if (CPP_PRINT_DEPS (pfile) && ! print_dep)
- cpp_warning (pfile, "No include path in which to find %s", fname);
else
- cpp_error_from_errno (pfile, fname);
+ handle_missing_header (pfile, fname, angle_brackets);
}
/* Locate file F, and determine whether it is newer than PFILE. Return -1,