aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/HeaderMap.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-02-14 14:58:28 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2014-02-14 14:58:28 +0000
commit75fa9eddae9bcc85aa4ed9125be1e5823a02d73e (patch)
tree901b03eec0f07c2dadffebcbe9427d8bdb78876a /clang/lib/Lex/HeaderMap.cpp
parent96430645eb672a8c8e547a49f1f9fff82b11fe10 (diff)
downloadllvm-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/HeaderMap.cpp')
-rw-r--r--clang/lib/Lex/HeaderMap.cpp25
1 files changed, 19 insertions, 6 deletions
diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index 478462c..0432e09 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -201,18 +201,29 @@ void HeaderMap::dump() const {
/// this HeaderMap. If so, open it and return its FileEntry.
const FileEntry *HeaderMap::LookupFile(
StringRef Filename, FileManager &FM) const {
+
+ SmallString<1024> Path;
+ StringRef Dest = lookupFilename(Filename, Path);
+ if (Dest.empty())
+ return 0;
+
+ return FM.getFile(Dest);
+}
+
+StringRef HeaderMap::lookupFilename(StringRef Filename,
+ SmallVectorImpl<char> &DestPath) const {
const HMapHeader &Hdr = getHeader();
unsigned NumBuckets = getEndianAdjustedWord(Hdr.NumBuckets);
// If the number of buckets is not a power of two, the headermap is corrupt.
// Don't probe infinitely.
if (NumBuckets & (NumBuckets-1))
- return 0;
+ return StringRef();
// Linearly probe the hash table.
for (unsigned Bucket = HashHMapKey(Filename);; ++Bucket) {
HMapBucket B = getBucket(Bucket & (NumBuckets-1));
- if (B.Key == HMAP_EmptyBucketKey) return 0; // Hash miss.
+ if (B.Key == HMAP_EmptyBucketKey) return StringRef(); // Hash miss.
// See if the key matches. If not, probe on.
if (!Filename.equals_lower(getString(B.Key)))
@@ -220,9 +231,11 @@ const FileEntry *HeaderMap::LookupFile(
// If so, we have a match in the hash table. Construct the destination
// path.
- SmallString<1024> DestPath;
- DestPath += getString(B.Prefix);
- DestPath += getString(B.Suffix);
- return FM.getFile(DestPath.str());
+ StringRef Prefix = getString(B.Prefix);
+ StringRef Suffix = getString(B.Suffix);
+ DestPath.clear();
+ DestPath.append(Prefix.begin(), Prefix.end());
+ DestPath.append(Suffix.begin(), Suffix.end());
+ return StringRef(DestPath.begin(), DestPath.size());
}
}