diff options
author | Nico Weber <thakis@chromium.org> | 2020-12-14 22:04:41 -0500 |
---|---|---|
committer | Nico Weber <thakis@chromium.org> | 2020-12-14 22:05:08 -0500 |
commit | 7799ef7121aa7d59f4bd95cdf70035de724ead6f (patch) | |
tree | 40636554c805435ee0c8c9862116f3a0f20c3799 /clang/lib | |
parent | c9ede6f3367a627baeef78f30d18078af9a4ffca (diff) | |
download | llvm-7799ef7121aa7d59f4bd95cdf70035de724ead6f.zip llvm-7799ef7121aa7d59f4bd95cdf70035de724ead6f.tar.gz llvm-7799ef7121aa7d59f4bd95cdf70035de724ead6f.tar.bz2 |
Revert "Lex: Migrate HeaderSearch::LoadedModuleMaps to FileEntryRef"
This reverts commit a40db5502b2515a6f2f1676b5d7a655ae0f41179.
and follow-up d636b881bb9214938973098a012fad453082c444
Somewhat speculative, likely broke check-clang on Windows:
https://reviews.llvm.org/D92975#2453482
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 49 | ||||
-rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 12 |
3 files changed, 35 insertions, 32 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index d3891eb..2317873 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -432,7 +432,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem, // Map the current input to a file. FileID ModuleMapID = SrcMgr.getMainFileID(); - Optional<FileEntryRef> ModuleMap = SrcMgr.getFileEntryRefForID(ModuleMapID); + const FileEntry *ModuleMap = SrcMgr.getFileEntryForID(ModuleMapID); // If the module map is preprocessed, handle the initial line marker; // line directives are not part of the module map syntax in general. @@ -445,7 +445,7 @@ static bool loadModuleMapForModuleBuild(CompilerInstance &CI, bool IsSystem, } // Load the module map file. - if (HS.loadModuleMapFile(*ModuleMap, IsSystem, ModuleMapID, &Offset, + if (HS.loadModuleMapFile(ModuleMap, IsSystem, ModuleMapID, &Offset, PresumedModuleMapFile)) return true; @@ -807,7 +807,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, // If we were asked to load any module map files, do so now. for (const auto &Filename : CI.getFrontendOpts().ModuleMapFiles) { - if (auto File = CI.getFileManager().getOptionalFileRef(Filename)) + if (auto File = CI.getFileManager().getFile(Filename)) CI.getPreprocessor().getHeaderSearchInfo().loadModuleMapFile( *File, /*IsSystem*/false); else diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 3cc8ce4..99c92e9 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1499,20 +1499,22 @@ bool HeaderSearch::findUsableModuleForFrameworkHeader( return true; } -static Optional<FileEntryRef> getPrivateModuleMap(FileEntryRef File, - FileManager &FileMgr) { - StringRef Filename = llvm::sys::path::filename(File.getName()); - SmallString<128> PrivateFilename(File.getDir().getName()); +static const FileEntry *getPrivateModuleMap(const FileEntry *File, + FileManager &FileMgr) { + StringRef Filename = llvm::sys::path::filename(File->getName()); + SmallString<128> PrivateFilename(File->getDir()->getName()); if (Filename == "module.map") llvm::sys::path::append(PrivateFilename, "module_private.map"); else if (Filename == "module.modulemap") llvm::sys::path::append(PrivateFilename, "module.private.modulemap"); else - return None; - return FileMgr.getOptionalFileRef(PrivateFilename); + return nullptr; + if (auto File = FileMgr.getFile(PrivateFilename)) + return *File; + return nullptr; } -bool HeaderSearch::loadModuleMapFile(FileEntryRef File, bool IsSystem, +bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem, FileID ID, unsigned *Offset, StringRef OriginalModuleMapFile) { // Find the directory for the module. For frameworks, that may require going @@ -1534,7 +1536,7 @@ bool HeaderSearch::loadModuleMapFile(FileEntryRef File, bool IsSystem, Dir = FakeFile->getDir(); } } else { - Dir = File.getDir(); + Dir = File->getDir(); } StringRef DirName(Dir->getName()); @@ -1561,9 +1563,11 @@ bool HeaderSearch::loadModuleMapFile(FileEntryRef File, bool IsSystem, } HeaderSearch::LoadModuleMapResult -HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem, +HeaderSearch::loadModuleMapFileImpl(const FileEntry *File, bool IsSystem, const DirectoryEntry *Dir, FileID ID, unsigned *Offset) { + assert(File && "expected FileEntry"); + // Check whether we've already loaded this module map, and mark it as being // loaded in case we recursively try to load it from itself. auto AddResult = LoadedModuleMaps.insert(std::make_pair(File, true)); @@ -1576,8 +1580,8 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem, } // Try to load a corresponding private module map. - if (Optional<FileEntryRef> PMMFile = getPrivateModuleMap(File, FileMgr)) { - if (ModMap.parseModuleMapFile(*PMMFile, IsSystem, Dir)) { + if (const FileEntry *PMMFile = getPrivateModuleMap(File, FileMgr)) { + if (ModMap.parseModuleMapFile(PMMFile, IsSystem, Dir)) { LoadedModuleMaps[File] = false; return LMM_InvalidModuleMap; } @@ -1587,24 +1591,24 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem, return LMM_NewlyLoaded; } -Optional<FileEntryRef> +const FileEntry * HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) { if (!HSOpts->ImplicitModuleMaps) - return None; + return nullptr; // For frameworks, the preferred spelling is Modules/module.modulemap, but // module.map at the framework root is also accepted. SmallString<128> ModuleMapFileName(Dir->getName()); if (IsFramework) llvm::sys::path::append(ModuleMapFileName, "Modules"); llvm::sys::path::append(ModuleMapFileName, "module.modulemap"); - if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName)) - return F; + if (auto F = FileMgr.getFile(ModuleMapFileName)) + return *F; // Continue to allow module.map ModuleMapFileName = Dir->getName(); llvm::sys::path::append(ModuleMapFileName, "module.map"); - if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName)) - return F; + if (auto F = FileMgr.getFile(ModuleMapFileName)) + return *F; // For frameworks, allow to have a private module map with a preferred // spelling when a public module map is absent. @@ -1612,10 +1616,10 @@ HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) { ModuleMapFileName = Dir->getName(); llvm::sys::path::append(ModuleMapFileName, "Modules", "module.private.modulemap"); - if (auto F = FileMgr.getOptionalFileRef(ModuleMapFileName)) - return F; + if (auto F = FileMgr.getFile(ModuleMapFileName)) + return *F; } - return None; + return nullptr; } Module *HeaderSearch::loadFrameworkModule(StringRef Name, @@ -1659,10 +1663,9 @@ HeaderSearch::loadModuleMapFile(const DirectoryEntry *Dir, bool IsSystem, if (KnownDir != DirectoryHasModuleMap.end()) return KnownDir->second ? LMM_AlreadyLoaded : LMM_InvalidModuleMap; - if (Optional<FileEntryRef> ModuleMapFile = - lookupModuleMapFile(Dir, IsFramework)) { + if (const FileEntry *ModuleMapFile = lookupModuleMapFile(Dir, IsFramework)) { LoadModuleMapResult Result = - loadModuleMapFileImpl(*ModuleMapFile, IsSystem, Dir); + loadModuleMapFileImpl(ModuleMapFile, IsSystem, Dir); // Add Dir explicitly in case ModuleMapFile is in a subdirectory. // E.g. Foo.framework/Modules/module.modulemap // ^Dir ^ModuleMapFile diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 152fc9e..bbda1f1 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -973,9 +973,9 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir, // We haven't looked here before. Load a module map, if there is // one. bool IsFrameworkDir = Parent.endswith(".framework"); - if (Optional<FileEntryRef> ModMapFile = - HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) { - parseModuleMapFile(*ModMapFile, Attrs.IsSystem, *ParentDir); + if (const FileEntry *ModMapFile = + HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) { + parseModuleMapFile(ModMapFile, Attrs.IsSystem, *ParentDir); inferred = InferredDirectories.find(*ParentDir); } @@ -2163,12 +2163,12 @@ void ModuleMapParser::parseExternModuleDecl() { llvm::sys::path::append(ModuleMapFileName, FileName); FileNameRef = ModuleMapFileName; } - if (auto File = SourceMgr.getFileManager().getOptionalFileRef(FileNameRef)) + if (auto File = SourceMgr.getFileManager().getFile(FileNameRef)) Map.parseModuleMapFile( *File, /*IsSystem=*/false, Map.HeaderInfo.getHeaderSearchOpts().ModuleMapFileHomeIsCwd ? Directory - : File->getDir(), + : (*File)->getDir(), FileID(), nullptr, ExternLoc); } @@ -2984,7 +2984,7 @@ bool ModuleMapParser::parseModuleMapFile() { } while (true); } -bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem, +bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem, const DirectoryEntry *Dir, FileID ID, unsigned *Offset, SourceLocation ExternModuleLoc) { |