diff options
Diffstat (limited to 'include/clang/Lex/HeaderSearch.h')
-rw-r--r-- | include/clang/Lex/HeaderSearch.h | 98 |
1 files changed, 69 insertions, 29 deletions
diff --git a/include/clang/Lex/HeaderSearch.h b/include/clang/Lex/HeaderSearch.h index fb1a86206354..034262982770 100644 --- a/include/clang/Lex/HeaderSearch.h +++ b/include/clang/Lex/HeaderSearch.h @@ -18,10 +18,10 @@ #include "clang/Lex/ModuleMap.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" -#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/Allocator.h" +#include <memory> #include <vector> namespace clang { @@ -73,6 +73,9 @@ struct HeaderFileInfo { /// provided via a header map. This bit indicates when this is one of /// those framework headers. unsigned IndexHeaderMapHeader : 1; + + /// \brief Whether this file had been looked up as a header. + unsigned IsValid : 1; /// \brief The number of times the file has been included already. unsigned short NumIncludes; @@ -102,8 +105,8 @@ struct HeaderFileInfo { : isImport(false), isPragmaOnce(false), DirInfo(SrcMgr::C_User), External(false), isModuleHeader(false), isCompilingModuleHeader(false), HeaderRole(ModuleMap::NormalHeader), - Resolved(false), IndexHeaderMapHeader(false), - NumIncludes(0), ControllingMacroID(0), ControllingMacro(0) {} + Resolved(false), IndexHeaderMapHeader(false), IsValid(0), + NumIncludes(0), ControllingMacroID(0), ControllingMacro(nullptr) {} /// \brief Retrieve the controlling macro for this header file, if /// any. @@ -158,6 +161,7 @@ class HeaderSearch { /// \brief Header-search options used to initialize this header search. IntrusiveRefCntPtr<HeaderSearchOptions> HSOpts; + DiagnosticsEngine &Diags; FileManager &FileMgr; /// \#include search path information. Requests for \#include "x" search the /// directory of the \#including file first, then each directory in SearchDirs @@ -185,15 +189,27 @@ class HeaderSearch { /// included, indexed by the FileEntry's UID. std::vector<HeaderFileInfo> FileInfo; - /// \brief Keeps track of each lookup performed by LookupFile. - /// - /// The first part of the value is the starting index in SearchDirs - /// that the cached search was performed from. If there is a hit and - /// this value doesn't match the current query, the cache has to be - /// ignored. The second value is the entry in SearchDirs that satisfied - /// the query. - llvm::StringMap<std::pair<unsigned, unsigned>, llvm::BumpPtrAllocator> - LookupFileCache; + /// Keeps track of each lookup performed by LookupFile. + struct LookupFileCacheInfo { + /// Starting index in SearchDirs that the cached search was performed from. + /// If there is a hit and this value doesn't match the current query, the + /// cache has to be ignored. + unsigned StartIdx; + /// The entry in SearchDirs that satisfied the query. + unsigned HitIdx; + /// This is non-null if the original filename was mapped to a framework + /// include via a headermap. + const char *MappedName; + + /// Default constructor -- Initialize all members with zero. + LookupFileCacheInfo(): StartIdx(0), HitIdx(0), MappedName(nullptr) {} + + void reset(unsigned StartIdx) { + this->StartIdx = StartIdx; + this->MappedName = nullptr; + } + }; + llvm::StringMap<LookupFileCacheInfo, llvm::BumpPtrAllocator> LookupFileCache; /// \brief Collection mapping a framework or subframework /// name like "Carbon" to the Carbon.framework directory. @@ -204,7 +220,7 @@ class HeaderSearch { /// include_alias pragma for Microsoft compatibility. typedef llvm::StringMap<std::string, llvm::BumpPtrAllocator> IncludeAliasMap; - OwningPtr<IncludeAliasMap> IncludeAliases; + std::unique_ptr<IncludeAliasMap> IncludeAliases; /// HeaderMaps - This is a mapping from FileEntry -> HeaderMap, uniquing /// headermaps. This vector owns the headermap. @@ -232,6 +248,8 @@ class HeaderSearch { unsigned NumMultiIncludeFileOptzn; unsigned NumFrameworkLookups, NumSubFrameworkLookups; + bool EnabledModules; + // HeaderSearch doesn't support default or copy construction. HeaderSearch(const HeaderSearch&) LLVM_DELETED_FUNCTION; void operator=(const HeaderSearch&) LLVM_DELETED_FUNCTION; @@ -278,9 +296,7 @@ public: } /// \brief Checks whether the map exists or not. - bool HasIncludeAliasMap() const { - return IncludeAliases.isValid(); - } + bool HasIncludeAliasMap() const { return (bool)IncludeAliases; } /// \brief Map the source include name to the dest include name. /// @@ -347,13 +363,15 @@ public: /// \returns If successful, this returns 'UsedDir', the DirectoryLookup member /// the file was found in, or null if not applicable. /// + /// \param IncludeLoc Used for diagnostics if valid. + /// /// \param isAngled indicates whether the file reference is a <> reference. /// /// \param CurDir If non-null, the file was found in the specified directory /// search location. This is used to implement \#include_next. /// - /// \param CurFileEnt If non-null, indicates where the \#including file is, in - /// case a relative search is needed. + /// \param Includers Indicates where the \#including file(s) are, in case + /// relative searches are needed. In reverse order of inclusion. /// /// \param SearchPath If non-null, will be set to the search path relative /// to which the file was found. If the include path is absolute, SearchPath @@ -366,10 +384,10 @@ public: /// \param SuggestedModule If non-null, and the file found is semantically /// part of a known module, this will be set to the module that should /// be imported instead of preprocessing/parsing the file found. - const FileEntry *LookupFile(StringRef Filename, bool isAngled, - const DirectoryLookup *FromDir, + const FileEntry *LookupFile(StringRef Filename, SourceLocation IncludeLoc, + bool isAngled, const DirectoryLookup *FromDir, const DirectoryLookup *&CurDir, - const FileEntry *CurFileEnt, + ArrayRef<const FileEntry *> Includers, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, ModuleMap::KnownHeader *SuggestedModule, @@ -458,6 +476,9 @@ public: /// FileEntry, uniquing them through the 'HeaderMaps' datastructure. const HeaderMap *CreateHeaderMap(const FileEntry *FE); + /// Returns true if modules are enabled. + bool enabledModules() const { return EnabledModules; } + /// \brief Retrieve the name of the module file that should be used to /// load the given module. /// @@ -472,9 +493,12 @@ public: /// /// \param ModuleName The module whose module file name will be returned. /// + /// \param ModuleMapPath A path that when combined with \c ModuleName + /// uniquely identifies this module. See Module::ModuleMap. + /// /// \returns The name of the module file that corresponds to this module, /// or an empty string if this module does not correspond to any module file. - std::string getModuleFileName(StringRef ModuleName); + std::string getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath); /// \brief Lookup a module Search for a module with the given name. /// @@ -486,11 +510,17 @@ public: /// /// \returns The module with the given name. Module *lookupModule(StringRef ModuleName, bool AllowSearch = true); + + /// \brief Try to find a module map file in the given directory, returning + /// \c nullptr if none is found. + const FileEntry *lookupModuleMapFile(const DirectoryEntry *Dir, + bool IsFramework); void IncrementFrameworkLookupCount() { ++NumFrameworkLookups; } /// \brief Determine whether there is a module map that may map the header /// with the given file name to a (sub)module. + /// Always returns false if modules are disabled. /// /// \param Filename The name of the file. /// @@ -543,16 +573,20 @@ private: /// of the given search directory. void loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir); + /// \brief Return the HeaderFileInfo structure for the specified FileEntry. + const HeaderFileInfo &getFileInfo(const FileEntry *FE) const { + return const_cast<HeaderSearch*>(this)->getFileInfo(FE); + } + public: /// \brief Retrieve the module map. ModuleMap &getModuleMap() { return ModMap; } unsigned header_file_size() const { return FileInfo.size(); } - /// \brief Return the HeaderFileInfo structure for the specified FileEntry. - const HeaderFileInfo &getFileInfo(const FileEntry *FE) const { - return const_cast<HeaderSearch*>(this)->getFileInfo(FE); - } + /// \brief Get a \c HeaderFileInfo structure for the specified \c FileEntry, + /// if one exists. + bool tryGetFileInfo(const FileEntry *FE, HeaderFileInfo &Result) const; // Used by external tools typedef std::vector<DirectoryLookup>::const_iterator search_dir_iterator; @@ -602,26 +636,32 @@ private: /// invalid. LMM_InvalidModuleMap }; - + + LoadModuleMapResult loadModuleMapFileImpl(const FileEntry *File, + bool IsSystem); + /// \brief Try to load the module map file in the given directory. /// /// \param DirName The name of the directory where we will look for a module /// map file. /// \param IsSystem Whether this is a system header directory. + /// \param IsFramework Whether this is a framework directory. /// /// \returns The result of attempting to load the module map file from the /// named directory. - LoadModuleMapResult loadModuleMapFile(StringRef DirName, bool IsSystem); + LoadModuleMapResult loadModuleMapFile(StringRef DirName, bool IsSystem, + bool IsFramework); /// \brief Try to load the module map file in the given directory. /// /// \param Dir The directory where we will look for a module map file. /// \param IsSystem Whether this is a system header directory. + /// \param IsFramework Whether this is a framework directory. /// /// \returns The result of attempting to load the module map file from the /// named directory. LoadModuleMapResult loadModuleMapFile(const DirectoryEntry *Dir, - bool IsSystem); + bool IsSystem, bool IsFramework); /// \brief Return the HeaderFileInfo structure for the specified FileEntry. HeaderFileInfo &getFileInfo(const FileEntry *FE); |