diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2014-02-14 14:58:28 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2014-02-14 14:58:28 +0000 |
commit | 75fa9eddae9bcc85aa4ed9125be1e5823a02d73e (patch) | |
tree | 901b03eec0f07c2dadffebcbe9427d8bdb78876a /clang/lib/Lex/HeaderSearch.cpp | |
parent | 96430645eb672a8c8e547a49f1f9fff82b11fe10 (diff) | |
download | llvm-75fa9eddae9bcc85aa4ed9125be1e5823a02d73e.zip llvm-75fa9eddae9bcc85aa4ed9125be1e5823a02d73e.tar.gz llvm-75fa9eddae9bcc85aa4ed9125be1e5823a02d73e.tar.bz2 |
If the headermap maps the filename to a framework include ("Foo.h" -> "Foo/Foo.h"),
continue header lookup using the framework include as filename.
This allows us to conveniently treat
#import "Foo.h"
as an implicit module import if we can resolve "Foo/Foo.h" as such.
rdar://16042979
llvm-svn: 201419
Diffstat (limited to 'clang/lib/Lex/HeaderSearch.cpp')
-rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 868c33b..b9dd22d 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -223,12 +223,13 @@ const char *DirectoryLookup::getName() const { /// LookupFile - Lookup the specified file in this search path, returning it /// if it exists or returning null if not. const FileEntry *DirectoryLookup::LookupFile( - StringRef Filename, + StringRef &Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, ModuleMap::KnownHeader *SuggestedModule, - bool &InUserSpecifiedSystemFramework) const { + bool &InUserSpecifiedSystemFramework, + SmallVectorImpl<char> &MappedName) const { InUserSpecifiedSystemFramework = false; SmallString<1024> TmpDir; @@ -271,8 +272,27 @@ const FileEntry *DirectoryLookup::LookupFile( SuggestedModule, InUserSpecifiedSystemFramework); assert(isHeaderMap() && "Unknown directory lookup"); - const FileEntry * const Result = getHeaderMap()->LookupFile( - Filename, HS.getFileMgr()); + const HeaderMap *HM = getHeaderMap(); + SmallString<1024> Path; + StringRef Dest = HM->lookupFilename(Filename, Path); + if (Dest.empty()) + return 0; + + const FileEntry *Result; + + // Check if the headermap maps the filename to a framework include + // ("Foo.h" -> "Foo/Foo.h"), in which case continue header lookup using the + // framework include. + if (llvm::sys::path::is_relative(Dest)) { + MappedName.clear(); + MappedName.append(Dest.begin(), Dest.end()); + Filename = StringRef(MappedName.begin(), MappedName.size()); + Result = HM->LookupFile(Filename, HS.getFileMgr()); + + } else { + Result = HS.getFileMgr().getFile(Dest); + } + if (Result) { if (SearchPath != NULL) { StringRef SearchPathRef(getName()); @@ -620,12 +640,15 @@ const FileEntry *HeaderSearch::LookupFile( CacheLookup.first = i+1; } + SmallString<64> MappedName; + // Check each directory in sequence to see if it contains this file. for (; i != SearchDirs.size(); ++i) { bool InUserSpecifiedSystemFramework = false; const FileEntry *FE = SearchDirs[i].LookupFile(Filename, *this, SearchPath, RelativePath, - SuggestedModule, InUserSpecifiedSystemFramework); + SuggestedModule, InUserSpecifiedSystemFramework, + MappedName); if (!FE) continue; CurDir = &SearchDirs[i]; |