Skip to content

Commit

Permalink
[clang] NFCI: Use FileEntryRef in ModuleMapParser
Browse files Browse the repository at this point in the history
  • Loading branch information
jansvoboda11 committed Sep 9, 2023
1 parent ef99617 commit c23d65b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Lex/ModuleMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ class ModuleMap {
/// that caused us to load this module map file, if any.
///
/// \returns true if an error occurred, false otherwise.
bool parseModuleMapFile(const FileEntry *File, bool IsSystem,
bool parseModuleMapFile(FileEntryRef File, bool IsSystem,
DirectoryEntryRef HomeDir, FileID ID = FileID(),
unsigned *Offset = nullptr,
SourceLocation ExternModuleLoc = SourceLocation());
Expand Down
14 changes: 6 additions & 8 deletions clang/lib/Lex/HeaderSearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1660,19 +1660,17 @@ bool HeaderSearch::findUsableModuleForFrameworkHeader(
return true;
}

static const FileEntry *getPrivateModuleMap(FileEntryRef File,
FileManager &FileMgr) {
static OptionalFileEntryRef getPrivateModuleMap(FileEntryRef 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 nullptr;
if (auto File = FileMgr.getFile(PrivateFilename))
return *File;
return nullptr;
return std::nullopt;
return FileMgr.getOptionalFileRef(PrivateFilename);
}

bool HeaderSearch::loadModuleMapFile(FileEntryRef File, bool IsSystem,
Expand Down Expand Up @@ -1738,8 +1736,8 @@ HeaderSearch::loadModuleMapFileImpl(FileEntryRef File, bool IsSystem,
}

// Try to load a corresponding private module map.
if (const FileEntry *PMMFile = getPrivateModuleMap(File, FileMgr)) {
if (ModMap.parseModuleMapFile(PMMFile, IsSystem, Dir)) {
if (OptionalFileEntryRef PMMFile = getPrivateModuleMap(File, FileMgr)) {
if (ModMap.parseModuleMapFile(*PMMFile, IsSystem, Dir)) {
LoadedModuleMaps[File] = false;
return LMM_InvalidModuleMap;
}
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Lex/ModuleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ namespace clang {
ModuleMap &Map;

/// The current module map file.
const FileEntry *ModuleMapFile;
FileEntryRef ModuleMapFile;

/// Source location of most recent parsed module declaration
SourceLocation CurrModuleDeclLoc;
Expand Down Expand Up @@ -1562,7 +1562,7 @@ namespace clang {
public:
explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr,
const TargetInfo *Target, DiagnosticsEngine &Diags,
ModuleMap &Map, const FileEntry *ModuleMapFile,
ModuleMap &Map, FileEntryRef ModuleMapFile,
DirectoryEntryRef Directory, bool IsSystem)
: L(L), SourceMgr(SourceMgr), Target(Target), Diags(Diags), Map(Map),
ModuleMapFile(ModuleMapFile), Directory(Directory),
Expand Down Expand Up @@ -2095,7 +2095,7 @@ void ModuleMapParser::parseModuleDecl() {
ActiveModule->NoUndeclaredIncludes = true;
ActiveModule->Directory = Directory;

StringRef MapFileName(ModuleMapFile->getName());
StringRef MapFileName(ModuleMapFile.getName());
if (MapFileName.endswith("module.private.modulemap") ||
MapFileName.endswith("module_private.map")) {
ActiveModule->ModuleMapIsPrivate = true;
Expand Down Expand Up @@ -3077,7 +3077,7 @@ bool ModuleMapParser::parseModuleMapFile() {
} while (true);
}

bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
bool ModuleMap::parseModuleMapFile(FileEntryRef File, bool IsSystem,
DirectoryEntryRef Dir, FileID ID,
unsigned *Offset,
SourceLocation ExternModuleLoc) {
Expand Down

0 comments on commit c23d65b

Please sign in to comment.