aboutsummaryrefslogtreecommitdiff
path: root/libcpp/files.c
diff options
context:
space:
mode:
authorZack Weinberg <zack@gcc.gnu.org>2004-06-05 20:58:06 +0000
committerZack Weinberg <zack@gcc.gnu.org>2004-06-05 20:58:06 +0000
commitc6e8380069ff630939beec0b5872a37f5b710189 (patch)
treef9776b653c83d7c1faa17b330fe162333d109cc2 /libcpp/files.c
parentdbeff3e56d566719bb3f0c1ba29362d61fe3ff85 (diff)
downloadgcc-c6e8380069ff630939beec0b5872a37f5b710189.zip
gcc-c6e8380069ff630939beec0b5872a37f5b710189.tar.gz
gcc-c6e8380069ff630939beec0b5872a37f5b710189.tar.bz2
Makefile.am: Add makedepend.
libcpp: * Makefile.am: Add makedepend. * Makefile.in, aclocal.m4: Regenerate. * charset.c: Insert a space to avoid a warning. * directives.c: Include mkdeps.h. (_cpp_handle_directive): Reenable macro expander if appropriate. (undefine_macros): Inline body of _cpp_free_definition for speed. Do not call undef callback or _cpp_warn_if_unused_macro. (cpp_get_deps): New interface. * files.c (search_cache): Add pfile argument. Check for file that would be found by "" or <> search here... (_cpp_find_file): ...not here. Correct recorded start_dir of files found by directory-of-current-file search that would be found by "" or <> search. * init.c (cpp_add_dependency_target): Delete. * internal.h (struct lexer_state): Add discarding_output flag. * lex.c (lex_identifier): Compute hash function while scanning. * macro.c (cpp_scan_nooutput): Disable macro expansion outside directives. * makedepend.c: New file. * mkdeps.c (struct deps): Add vpath vector. (apply_vpath, deps_add_vpath): New function. (deps_free): Free vpath vector. (deps_add_dep, deps_add_target): Use apply_vpath. * symtab.c (calc_hash): Use HT_HASHSTEP and HT_FINISH. (ht_lookup_with_hash): New function. * cpplib.h, mkdeps.h: Update prototypes. * symtab.h: Update prototypes. (HT_HASHSTEP, HT_FINISH): New macros. gcc: * Makefile.in (MKDEPS_H): New shorthand. (c-opts.o): Update dependencies. * c-opts.c: Include mkdeps.h. (handle_deferred_opts): Use cpp_get_deps and deps_add_target, not cpp_add_dependency_target. From-SVN: r82654
Diffstat (limited to 'libcpp/files.c')
-rw-r--r--libcpp/files.c79
1 files changed, 62 insertions, 17 deletions
diff --git a/libcpp/files.c b/libcpp/files.c
index 7d7b271..6a18d71 100644
--- a/libcpp/files.c
+++ b/libcpp/files.c
@@ -158,7 +158,8 @@ static struct cpp_dir *search_path_head (cpp_reader *, const char *fname,
int angle_brackets, enum include_type);
static const char *dir_name_of_file (_cpp_file *file);
static void open_file_failed (cpp_reader *pfile, _cpp_file *file);
-static struct file_hash_entry *search_cache (struct file_hash_entry *head,
+static struct file_hash_entry *search_cache (cpp_reader *pfile,
+ struct file_hash_entry *head,
const cpp_dir *start_dir);
static _cpp_file *make_cpp_file (cpp_reader *, cpp_dir *, const char *fname);
static cpp_dir *make_cpp_dir (cpp_reader *, const char *dir_name, int sysp);
@@ -406,7 +407,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f
INSERT);
/* First check the cache before we resort to memory allocation. */
- entry = search_cache (*hash_slot, start_dir);
+ entry = search_cache (pfile, *hash_slot, start_dir);
if (entry)
return entry->u.file;
@@ -435,17 +436,6 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f
}
break;
}
-
- /* Only check the cache for the starting location (done above)
- and the quote and bracket chain heads because there are no
- other possible starting points for searches. */
- if (file->dir != pfile->bracket_include
- && file->dir != pfile->quote_include)
- continue;
-
- entry = search_cache (*hash_slot, file->dir);
- if (entry)
- break;
}
if (entry)
@@ -462,6 +452,33 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f
pfile->all_files = file;
}
+ /* If this file was found in the directory-of-the-current-file,
+ check whether that directory is reachable via one of the normal
+ search paths. If so, we must record this entry as being
+ reachable that way, otherwise we will mistakenly reprocess this
+ file if it is included later from the normal search path. */
+ if (file->dir && start_dir->next == pfile->quote_include)
+ {
+ cpp_dir *d;
+ cpp_dir *proper_start_dir = pfile->quote_include;
+
+ for (d = proper_start_dir;; d = d->next)
+ {
+ if (d == pfile->bracket_include)
+ proper_start_dir = d;
+ if (d == 0)
+ {
+ proper_start_dir = 0;
+ break;
+ }
+ /* file->dir->name will have a trailing slash. */
+ if (!strncmp (d->name, file->dir->name, file->dir->len - 1))
+ break;
+ }
+ if (proper_start_dir)
+ start_dir = proper_start_dir;
+ }
+
/* Store this new result in the hash table. */
entry = new_file_hash_entry (pfile);
entry->next = *hash_slot;
@@ -821,12 +838,40 @@ open_file_failed (cpp_reader *pfile, _cpp_file *file)
/* Search in the chain beginning at HEAD for a file whose search path
started at START_DIR != NULL. */
static struct file_hash_entry *
-search_cache (struct file_hash_entry *head, const cpp_dir *start_dir)
+search_cache (cpp_reader *pfile, struct file_hash_entry *head,
+ const cpp_dir *start_dir)
{
- while (head && head->start_dir != start_dir)
- head = head->next;
+ struct file_hash_entry *p;
+
+ /* Look for a file that was found from a search starting at the
+ given location. */
+ for (p = head; p; p = p->next)
+ if (p->start_dir == start_dir)
+ return p;
+
+ /* If the given location is for a search of the directory containing
+ the current file, check for a match starting at the base of the
+ quoted include chain. */
+ if (start_dir->next == pfile->quote_include)
+ {
+ start_dir = pfile->quote_include;
+ for (p = head; p; p = p->next)
+ if (p->start_dir == start_dir)
+ return p;
+ }
- return head;
+ /* If the given location is for a search from the base of the quoted
+ include chain, check for a match starting at the base of the
+ bracket include chain. */
+ if (start_dir == pfile->quote_include)
+ {
+ start_dir = pfile->bracket_include;
+ for (p = head; p; p = p->next)
+ if (p->start_dir == start_dir)
+ return p;
+ }
+
+ return 0;
}
/* Allocate a new _cpp_file structure. */