From f1e207107a8fca7d0f8792502b576688ede5df58 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 12 Nov 2007 00:38:48 +0000 Subject: re PR c++/17577 (#pragma implementation no longer diagnoses use after file to which it applies) gcc/cp PR c++/17577: * lex.c (handle_pragma_implementation): Use cpp_included_before. gcc/testsuite PR c++/17577: * g++.dg/ext/pr17577.h: New file. * g++.dg/ext/pr17577.C: New file. libcpp PR c++/17557: * include/cpplib.h (cpp_included_before): Declare. * files.c (struct file_hash_entry) : New field. (_cpp_find_file): Initialize new field. (make_cpp_dir): Likewise. (cpp_included_before): New function. From-SVN: r130093 --- libcpp/files.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'libcpp/files.c') diff --git a/libcpp/files.c b/libcpp/files.c index 73f88bb3cde..ae2f2945d9e 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -142,6 +142,7 @@ struct file_hash_entry { struct file_hash_entry *next; cpp_dir *start_dir; + source_location location; union { _cpp_file *file; @@ -521,6 +522,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f entry = new_file_hash_entry (pfile); entry->next = *hash_slot; entry->start_dir = start_dir; + entry->location = pfile->line_table->highest_location; entry->u.file = file; *hash_slot = entry; @@ -533,6 +535,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f entry = new_file_hash_entry (pfile); entry->next = *hash_slot; entry->start_dir = pfile->bracket_include; + entry->location = pfile->line_table->highest_location; entry->u.file = file; *hash_slot = entry; } @@ -543,6 +546,7 @@ _cpp_find_file (cpp_reader *pfile, const char *fname, cpp_dir *start_dir, bool f entry = new_file_hash_entry (pfile); entry->next = *hash_slot; entry->start_dir = pfile->quote_include; + entry->location = pfile->line_table->highest_location; entry->u.file = file; *hash_slot = entry; } @@ -993,6 +997,7 @@ make_cpp_dir (cpp_reader *pfile, const char *dir_name, int sysp) entry = new_file_hash_entry (pfile); entry->next = *hash_slot; entry->start_dir = NULL; + entry->location = pfile->line_table->highest_location; entry->u.dir = dir; *hash_slot = entry; @@ -1036,6 +1041,25 @@ cpp_included (cpp_reader *pfile, const char *fname) return entry != NULL; } +/* Returns TRUE if a file FNAME has ever been successfully opened + before LOCATION. This routine is not intended to correctly handle + filenames aliased by links or redundant . or .. traversals etc. */ +bool +cpp_included_before (cpp_reader *pfile, const char *fname, + source_location location) +{ + struct file_hash_entry *entry; + + entry = (struct file_hash_entry *) + htab_find_with_hash (pfile->file_hash, fname, htab_hash_string (fname)); + + while (entry && (entry->start_dir == NULL || entry->u.file->err_no + || entry->location > location)) + entry = entry->next; + + return entry != NULL; +} + /* Calculate the hash value of a file hash entry P. */ static hashval_t -- cgit v1.2.1