summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex/PPDirectives.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2011-11-20 17:46:46 +0000
committerDouglas Gregor <dgregor@apple.com>2011-11-20 17:46:46 +0000
commit8ad31c2e360411db9035fa502817f8ca63b99893 (patch)
tree4dacb5a742c501a8a01d5f0ab6832f02d08c3e0f /clang/lib/Lex/PPDirectives.cpp
parent76dfa03874141c1fe1ba6217c2ba606874467438 (diff)
downloadbcm5719-llvm-8ad31c2e360411db9035fa502817f8ca63b99893.tar.gz
bcm5719-llvm-8ad31c2e360411db9035fa502817f8ca63b99893.zip
Allow preprocessor callbacks to recover from a "file not found" error,
from Jason Haslam! llvm-svn: 145012
Diffstat (limited to 'clang/lib/Lex/PPDirectives.cpp')
-rw-r--r--clang/lib/Lex/PPDirectives.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 2444364f358..88d9429f001 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -486,7 +486,8 @@ const FileEntry *Preprocessor::LookupFile(
const DirectoryLookup *&CurDir,
SmallVectorImpl<char> *SearchPath,
SmallVectorImpl<char> *RelativePath,
- ModuleMap::Module **SuggestedModule) {
+ ModuleMap::Module **SuggestedModule,
+ bool SkipCache) {
// If the header lookup mechanism may be relative to the current file, pass in
// info about where the current file is.
const FileEntry *CurFileEnt = 0;
@@ -510,7 +511,7 @@ const FileEntry *Preprocessor::LookupFile(
CurDir = CurDirLookup;
const FileEntry *FE = HeaderInfo.LookupFile(
Filename, isAngled, FromDir, CurDir, CurFileEnt,
- SearchPath, RelativePath, SuggestedModule);
+ SearchPath, RelativePath, SuggestedModule, SkipCache);
if (FE) return FE;
// Otherwise, see if this is a subframework header. If so, this is relative
@@ -1288,10 +1289,28 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
return;
}
- // Notify the callback object that we've seen an inclusion directive.
- if (Callbacks)
+ if (Callbacks) {
+ if (!File) {
+ // Give the clients a chance to recover.
+ llvm::SmallString<128> RecoveryPath;
+ if (Callbacks->FileNotFound(Filename, RecoveryPath)) {
+ if (const DirectoryEntry *DE = FileMgr.getDirectory(RecoveryPath)) {
+ // Add the recovery path to the list of search paths.
+ DirectoryLookup DL(DE, SrcMgr::C_User, true, false);
+ HeaderInfo.AddSearchPath(DL, isAngled);
+
+ // Try the lookup again, skipping the cache.
+ File = LookupFile(Filename, isAngled, LookupFrom, CurDir, 0, 0,
+ AutoModuleImport ? &SuggestedModule : 0,
+ /*SkipCache*/true);
+ }
+ }
+ }
+
+ // Notify the callback object that we've seen an inclusion directive.
Callbacks->InclusionDirective(HashLoc, IncludeTok, Filename, isAngled, File,
End, SearchPath, RelativePath);
+ }
if (File == 0) {
if (!SuppressIncludeNotFoundError)
OpenPOWER on IntegriCloud