diff options
Diffstat (limited to 'lib/Lex/HeaderSearch.cpp')
| -rw-r--r-- | lib/Lex/HeaderSearch.cpp | 47 | 
1 files changed, 29 insertions, 18 deletions
| diff --git a/lib/Lex/HeaderSearch.cpp b/lib/Lex/HeaderSearch.cpp index d6b255fb014e..ad7d3449ac4a 100644 --- a/lib/Lex/HeaderSearch.cpp +++ b/lib/Lex/HeaderSearch.cpp @@ -18,6 +18,7 @@  #include "clang/Lex/HeaderSearchOptions.h"  #include "clang/Lex/LexDiagnostic.h"  #include "clang/Lex/Lexer.h" +#include "clang/Lex/Preprocessor.h"  #include "llvm/ADT/APInt.h"  #include "llvm/ADT/Hashing.h"  #include "llvm/ADT/SmallString.h" @@ -149,7 +150,7 @@ std::string HeaderSearch::getModuleFileName(StringRef ModuleName,      SmallString<128> HashStr;      llvm::APInt(64, size_t(Hash)).toStringUnsigned(HashStr, /*Radix*/36); -    llvm::sys::path::append(Result, ModuleName + "-" + HashStr.str() + ".pcm"); +    llvm::sys::path::append(Result, ModuleName + "-" + HashStr + ".pcm");    }    return Result.str().str();  } @@ -297,7 +298,7 @@ const FileEntry *DirectoryLookup::LookupFile(        RelativePath->append(Filename.begin(), Filename.end());      } -    return getFileAndSuggestModule(HS, TmpDir.str(), getDir(), +    return getFileAndSuggestModule(HS, TmpDir, getDir(),                                     isSystemHeaderDirectory(),                                     SuggestedModule);    } @@ -438,7 +439,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(      HS.IncrementFrameworkLookupCount();      // If the framework dir doesn't exist, we fail. -    const DirectoryEntry *Dir = FileMgr.getDirectory(FrameworkName.str()); +    const DirectoryEntry *Dir = FileMgr.getDirectory(FrameworkName);      if (!Dir) return nullptr;      // Otherwise, if it does, remember that this is the right direntry for this @@ -450,7 +451,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(      if (getDirCharacteristic() == SrcMgr::C_User) {        SmallString<1024> SystemFrameworkMarker(FrameworkName);        SystemFrameworkMarker += ".system_framework"; -      if (llvm::sys::fs::exists(SystemFrameworkMarker.str())) { +      if (llvm::sys::fs::exists(SystemFrameworkMarker)) {          CacheEntry.IsUserSpecifiedSystemFramework = true;        }      } @@ -476,7 +477,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(    }    FrameworkName.append(Filename.begin()+SlashPos+1, Filename.end()); -  const FileEntry *FE = FileMgr.getFile(FrameworkName.str(), +  const FileEntry *FE = FileMgr.getFile(FrameworkName,                                          /*openFile=*/!SuggestedModule);    if (!FE) {      // Check "/System/Library/Frameworks/Cocoa.framework/PrivateHeaders/file.h" @@ -487,7 +488,7 @@ const FileEntry *DirectoryLookup::DoFrameworkLookup(        SearchPath->insert(SearchPath->begin()+OrigSize, Private,                           Private+strlen(Private)); -    FE = FileMgr.getFile(FrameworkName.str(), /*openFile=*/!SuggestedModule); +    FE = FileMgr.getFile(FrameworkName, /*openFile=*/!SuggestedModule);    }    // If we found the header and are allowed to suggest a module, do so now. @@ -594,7 +595,13 @@ const FileEntry *HeaderSearch::LookupFile(        RelativePath->append(Filename.begin(), Filename.end());      }      // Otherwise, just return the file. -    return FileMgr.getFile(Filename, /*openFile=*/true); +    const FileEntry *File = FileMgr.getFile(Filename, /*openFile=*/true); +    if (File && SuggestedModule) { +      // If there is a module that corresponds to this header, suggest it. +      hasModuleMap(Filename, File->getDir(), /*SystemHeaderDir*/false); +      *SuggestedModule = findModuleForHeader(File); +    } +    return File;    }    // This is the header that MSVC's header search would have found. @@ -628,7 +635,7 @@ const FileEntry *HeaderSearch::LookupFile(        bool IncluderIsSystemHeader =            Includer && getFileInfo(Includer).DirInfo != SrcMgr::C_User;        if (const FileEntry *FE = getFileAndSuggestModule( -              *this, TmpDir.str(), IncluderAndDir.second, +              *this, TmpDir, IncluderAndDir.second,                IncluderIsSystemHeader, SuggestedModule)) {          if (!Includer) {            assert(First && "only first includer can have no file"); @@ -865,7 +872,7 @@ LookupSubframeworkHeader(StringRef Filename,      ++NumSubFrameworkLookups;      // If the framework dir doesn't exist, we fail. -    const DirectoryEntry *Dir = FileMgr.getDirectory(FrameworkName.str()); +    const DirectoryEntry *Dir = FileMgr.getDirectory(FrameworkName);      if (!Dir) return nullptr;      // Otherwise, if it does, remember that this is the right direntry for this @@ -890,7 +897,7 @@ LookupSubframeworkHeader(StringRef Filename,    }    HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end()); -  if (!(FE = FileMgr.getFile(HeadersFilename.str(), /*openFile=*/true))) { +  if (!(FE = FileMgr.getFile(HeadersFilename, /*openFile=*/true))) {      // Check ".../Frameworks/HIToolbox.framework/PrivateHeaders/HIToolbox.h"      HeadersFilename = FrameworkName; @@ -902,7 +909,7 @@ LookupSubframeworkHeader(StringRef Filename,      }      HeadersFilename.append(Filename.begin()+SlashPos+1, Filename.end()); -    if (!(FE = FileMgr.getFile(HeadersFilename.str(), /*openFile=*/true))) +    if (!(FE = FileMgr.getFile(HeadersFilename, /*openFile=*/true)))        return nullptr;    } @@ -1016,7 +1023,9 @@ void HeaderSearch::MarkFileModuleHeader(const FileEntry *FE,    HFI.setHeaderRole(Role);  } -bool HeaderSearch::ShouldEnterIncludeFile(const FileEntry *File, bool isImport){ +bool HeaderSearch::ShouldEnterIncludeFile(Preprocessor &PP, +                                          const FileEntry *File, +                                          bool isImport) {    ++NumIncluded; // Count # of attempted #includes.    // Get information about this file. @@ -1041,7 +1050,7 @@ bool HeaderSearch::ShouldEnterIncludeFile(const FileEntry *File, bool isImport){    // if the macro that guards it is defined, we know the #include has no effect.    if (const IdentifierInfo *ControllingMacro        = FileInfo.getControllingMacro(ExternalLookup)) -    if (ControllingMacro->hasMacroDefinition()) { +    if (PP.isMacroDefined(ControllingMacro)) {        ++NumMultiIncludeFileOptzn;        return false;      } @@ -1067,7 +1076,7 @@ StringRef HeaderSearch::getUniqueFrameworkName(StringRef Framework) {  bool HeaderSearch::hasModuleMap(StringRef FileName,                                   const DirectoryEntry *Root,                                  bool IsSystem) { -  if (!enabledModules() || !LangOpts.ModulesImplicitMaps) +  if (!HSOpts->ModuleMaps || !LangOpts.ModulesImplicitMaps)      return false;    SmallVector<const DirectoryEntry *, 2> FixUpDirectories; @@ -1284,7 +1293,7 @@ void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) {                                  DirNative);          // Search each of the ".framework" directories to load them as modules. -        for (llvm::sys::fs::directory_iterator Dir(DirNative.str(), EC), DirEnd; +        for (llvm::sys::fs::directory_iterator Dir(DirNative, EC), DirEnd;               Dir != DirEnd && !EC; Dir.increment(EC)) {            if (llvm::sys::path::extension(Dir->path()) != ".framework")              continue; @@ -1351,10 +1360,12 @@ void HeaderSearch::loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir) {    std::error_code EC;    SmallString<128> DirNative;    llvm::sys::path::native(SearchDir.getDir()->getName(), DirNative); -  for (llvm::sys::fs::directory_iterator Dir(DirNative.str(), EC), DirEnd; +  for (llvm::sys::fs::directory_iterator Dir(DirNative, EC), DirEnd;         Dir != DirEnd && !EC; Dir.increment(EC)) { -    loadModuleMapFile(Dir->path(), SearchDir.isSystemHeaderDirectory(), -                      SearchDir.isFramework()); +    bool IsFramework = llvm::sys::path::extension(Dir->path()) == ".framework"; +    if (IsFramework == SearchDir.isFramework()) +      loadModuleMapFile(Dir->path(), SearchDir.isSystemHeaderDirectory(), +                        SearchDir.isFramework());    }    SearchDir.setSearchedAllModuleMaps(true); | 
