<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 14, 2014 at 6:58 AM, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:akyrtzi@gmail.com" target="_blank">akyrtzi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: akirtzidis<br>
Date: Fri Feb 14 08:58:28 2014<br>
New Revision: 201419<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=201419&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=201419&view=rev</a><br>
Log:<br>
If the headermap maps the filename to a framework include ("Foo.h" -> "Foo/Foo.h"),<br>
continue header lookup using the framework include as filename.<br>
<br>
This allows us to conveniently treat<br>
  #import "Foo.h"<br>
as an implicit module import if we can resolve "Foo/Foo.h" as such.<br>
<br>
rdar://16042979<br>
<br>
Added:<br>
    cfe/trunk/test/Preprocessor/headermap-rel/<br>
    cfe/trunk/test/Preprocessor/headermap-rel/Foo.framework/<br>
    cfe/trunk/test/Preprocessor/headermap-rel/Foo.framework/Headers/<br>
    cfe/trunk/test/Preprocessor/headermap-rel/Foo.framework/Headers/Foo.h<br>
    cfe/trunk/test/Preprocessor/headermap-rel/foo.hmap<br>
    cfe/trunk/test/Preprocessor/headermap-rel/headermap-rel.c<br></blockquote><div><br></div><div>I've reconfigured this test case a little in r201458. It's preferable (we've got a test system that requires this) if inputs for test cases go in an "Inputs" directory, so I moved the headermap-rel directory into Preprocessor/Inputs and moved the headermap-rel.c test case out into the Preprocessor directory directly.<br>
<br>- David</div>







<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Modified:<br>
    cfe/trunk/include/clang/Lex/DirectoryLookup.h<br>
    cfe/trunk/include/clang/Lex/HeaderMap.h<br>
    cfe/trunk/lib/Lex/HeaderMap.cpp<br>
    cfe/trunk/lib/Lex/HeaderSearch.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Lex/DirectoryLookup.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=201419&r1=201418&r2=201419&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/DirectoryLookup.h?rev=201419&r1=201418&r2=201419&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/include/clang/Lex/DirectoryLookup.h (original)<br>
+++ cfe/trunk/include/clang/Lex/DirectoryLookup.h Fri Feb 14 08:58:28 2014<br>
@@ -161,11 +161,16 @@ public:<br>
   /// \param [out] InUserSpecifiedSystemFramework If the file is found,<br>
   /// set to true if the file is located in a framework that has been<br>
   /// user-specified to be treated as a system framework.<br>
-  const FileEntry *LookupFile(StringRef Filename, HeaderSearch &HS,<br>
+  ///<br>
+  /// \param [out] MappedName if this is a headermap which maps the filename to<br>
+  /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this<br>
+  /// vector and point Filename to it.<br>
+  const FileEntry *LookupFile(StringRef &Filename, HeaderSearch &HS,<br>
                               SmallVectorImpl<char> *SearchPath,<br>
                               SmallVectorImpl<char> *RelativePath,<br>
                               ModuleMap::KnownHeader *SuggestedModule,<br>
-                              bool &InUserSpecifiedSystemFramework) const;<br>
+                              bool &InUserSpecifiedSystemFramework,<br>
+                              SmallVectorImpl<char> &MappedName) const;<br>
<br>
 private:<br>
   const FileEntry *DoFrameworkLookup(<br>
<br>
Modified: cfe/trunk/include/clang/Lex/HeaderMap.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderMap.h?rev=201419&r1=201418&r2=201419&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderMap.h?rev=201419&r1=201418&r2=201419&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/include/clang/Lex/HeaderMap.h (original)<br>
+++ cfe/trunk/include/clang/Lex/HeaderMap.h Fri Feb 14 08:58:28 2014<br>
@@ -55,6 +55,11 @@ public:<br>
   /// "../../file.h".<br>
   const FileEntry *LookupFile(StringRef Filename, FileManager &FM) const;<br>
<br>
+  /// If the specified relative filename is located in this HeaderMap return<br>
+  /// the filename it is mapped to, otherwise return an empty StringRef.<br>
+  StringRef lookupFilename(StringRef Filename,<br>
+                           SmallVectorImpl<char> &DestPath) const;<br>
+<br>
   /// getFileName - Return the filename of the headermap.<br>
   const char *getFileName() const;<br>
<br>
<br>
Modified: cfe/trunk/lib/Lex/HeaderMap.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp?rev=201419&r1=201418&r2=201419&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderMap.cpp?rev=201419&r1=201418&r2=201419&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Lex/HeaderMap.cpp (original)<br>
+++ cfe/trunk/lib/Lex/HeaderMap.cpp Fri Feb 14 08:58:28 2014<br>
@@ -201,18 +201,29 @@ void HeaderMap::dump() const {<br>
 /// this HeaderMap.  If so, open it and return its FileEntry.<br>
 const FileEntry *HeaderMap::LookupFile(<br>
     StringRef Filename, FileManager &FM) const {<br>
+<br>
+  SmallString<1024> Path;<br>
+  StringRef Dest = lookupFilename(Filename, Path);<br>
+  if (Dest.empty())<br>
+    return 0;<br>
+<br>
+  return FM.getFile(Dest);<br>
+}<br>
+<br>
+StringRef HeaderMap::lookupFilename(StringRef Filename,<br>
+                                    SmallVectorImpl<char> &DestPath) const {<br>
   const HMapHeader &Hdr = getHeader();<br>
   unsigned NumBuckets = getEndianAdjustedWord(Hdr.NumBuckets);<br>
<br>
   // If the number of buckets is not a power of two, the headermap is corrupt.<br>
   // Don't probe infinitely.<br>
   if (NumBuckets & (NumBuckets-1))<br>
-    return 0;<br>
+    return StringRef();<br>
<br>
   // Linearly probe the hash table.<br>
   for (unsigned Bucket = HashHMapKey(Filename);; ++Bucket) {<br>
     HMapBucket B = getBucket(Bucket & (NumBuckets-1));<br>
-    if (B.Key == HMAP_EmptyBucketKey) return 0; // Hash miss.<br>
+    if (B.Key == HMAP_EmptyBucketKey) return StringRef(); // Hash miss.<br>
<br>
     // See if the key matches.  If not, probe on.<br>
     if (!Filename.equals_lower(getString(B.Key)))<br>
@@ -220,9 +231,11 @@ const FileEntry *HeaderMap::LookupFile(<br>
<br>
     // If so, we have a match in the hash table.  Construct the destination<br>
     // path.<br>
-    SmallString<1024> DestPath;<br>
-    DestPath += getString(B.Prefix);<br>
-    DestPath += getString(B.Suffix);<br>
-    return FM.getFile(DestPath.str());<br>
+    StringRef Prefix = getString(B.Prefix);<br>
+    StringRef Suffix = getString(B.Suffix);<br>
+    DestPath.clear();<br>
+    DestPath.append(Prefix.begin(), Prefix.end());<br>
+    DestPath.append(Suffix.begin(), Suffix.end());<br>
+    return StringRef(DestPath.begin(), DestPath.size());<br>
   }<br>
 }<br>
<br>
Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=201419&r1=201418&r2=201419&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=201419&r1=201418&r2=201419&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/Lex/HeaderSearch.cpp (original)<br>
+++ cfe/trunk/lib/Lex/HeaderSearch.cpp Fri Feb 14 08:58:28 2014<br>
@@ -223,12 +223,13 @@ const char *DirectoryLookup::getName() c<br>
 /// LookupFile - Lookup the specified file in this search path, returning it<br>
 /// if it exists or returning null if not.<br>
 const FileEntry *DirectoryLookup::LookupFile(<br>
-    StringRef Filename,<br>
+    StringRef &Filename,<br>
     HeaderSearch &HS,<br>
     SmallVectorImpl<char> *SearchPath,<br>
     SmallVectorImpl<char> *RelativePath,<br>
     ModuleMap::KnownHeader *SuggestedModule,<br>
-    bool &InUserSpecifiedSystemFramework) const {<br>
+    bool &InUserSpecifiedSystemFramework,<br>
+    SmallVectorImpl<char> &MappedName) const {<br>
   InUserSpecifiedSystemFramework = false;<br>
<br>
   SmallString<1024> TmpDir;<br>
@@ -271,8 +272,27 @@ const FileEntry *DirectoryLookup::Lookup<br>
                              SuggestedModule, InUserSpecifiedSystemFramework);<br>
<br>
   assert(isHeaderMap() && "Unknown directory lookup");<br>
-  const FileEntry * const Result = getHeaderMap()->LookupFile(<br>
-      Filename, HS.getFileMgr());<br>
+  const HeaderMap *HM = getHeaderMap();<br>
+  SmallString<1024> Path;<br>
+  StringRef Dest = HM->lookupFilename(Filename, Path);<br>
+  if (Dest.empty())<br>
+    return 0;<br>
+<br>
+  const FileEntry *Result;<br>
+<br>
+  // Check if the headermap maps the filename to a framework include<br>
+  // ("Foo.h" -> "Foo/Foo.h"), in which case continue header lookup using the<br>
+  // framework include.<br>
+  if (llvm::sys::path::is_relative(Dest)) {<br>
+    MappedName.clear();<br>
+    MappedName.append(Dest.begin(), Dest.end());<br>
+    Filename = StringRef(MappedName.begin(), MappedName.size());<br>
+    Result = HM->LookupFile(Filename, HS.getFileMgr());<br>
+<br>
+  } else {<br>
+    Result = HS.getFileMgr().getFile(Dest);<br>
+  }<br>
+<br>
   if (Result) {<br>
     if (SearchPath != NULL) {<br>
       StringRef SearchPathRef(getName());<br>
@@ -620,12 +640,15 @@ const FileEntry *HeaderSearch::LookupFil<br>
     CacheLookup.first = i+1;<br>
   }<br>
<br>
+  SmallString<64> MappedName;<br>
+<br>
   // Check each directory in sequence to see if it contains this file.<br>
   for (; i != SearchDirs.size(); ++i) {<br>
     bool InUserSpecifiedSystemFramework = false;<br>
     const FileEntry *FE =<br>
       SearchDirs[i].LookupFile(Filename, *this, SearchPath, RelativePath,<br>
-                               SuggestedModule, InUserSpecifiedSystemFramework);<br>
+                               SuggestedModule, InUserSpecifiedSystemFramework,<br>
+                               MappedName);<br>
     if (!FE) continue;<br>
<br>
     CurDir = &SearchDirs[i];<br>
<br>
Added: cfe/trunk/test/Preprocessor/headermap-rel/Foo.framework/Headers/Foo.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/headermap-rel/Foo.framework/Headers/Foo.h?rev=201419&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/headermap-rel/Foo.framework/Headers/Foo.h?rev=201419&view=auto</a><br>

==============================================================================<br>
--- cfe/trunk/test/Preprocessor/headermap-rel/Foo.framework/Headers/Foo.h (added)<br>
+++ cfe/trunk/test/Preprocessor/headermap-rel/Foo.framework/Headers/Foo.h Fri Feb 14 08:58:28 2014<br>
@@ -0,0 +1,2 @@<br>
+<br>
+Foo.h is parsed<br>
<br>
Added: cfe/trunk/test/Preprocessor/headermap-rel/foo.hmap<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/headermap-rel/foo.hmap?rev=201419&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/headermap-rel/foo.hmap?rev=201419&view=auto</a><br>

==============================================================================<br>
Binary files cfe/trunk/test/Preprocessor/headermap-rel/foo.hmap (added) and cfe/trunk/test/Preprocessor/headermap-rel/foo.hmap Fri Feb 14 08:58:28 2014 differ<br>
<br>
Added: cfe/trunk/test/Preprocessor/headermap-rel/headermap-rel.c<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/headermap-rel/headermap-rel.c?rev=201419&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/headermap-rel/headermap-rel.c?rev=201419&view=auto</a><br>

==============================================================================<br>
--- cfe/trunk/test/Preprocessor/headermap-rel/headermap-rel.c (added)<br>
+++ cfe/trunk/test/Preprocessor/headermap-rel/headermap-rel.c Fri Feb 14 08:58:28 2014<br>
@@ -0,0 +1,10 @@<br>
+<br>
+// This uses a headermap with this entry:<br>
+//   Foo.h -> Foo/Foo.h<br>
+<br>
+// RUN: %clang_cc1 -E %s -o %t.i -I %S/foo.hmap -F %S<br>
+// RUN: FileCheck %s -input-file %t.i<br>
+<br>
+// CHECK: Foo.h is parsed<br>
+<br>
+#include "Foo.h"<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>