36 changes: 17 additions & 19 deletions clang/lib/Lex/ModuleMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ OptionalFileEntryRef ModuleMap::findHeader(
Module *M, const Module::UnresolvedHeaderDirective &Header,
SmallVectorImpl<char> &RelativePathName, bool &NeedsFramework) {
// Search for the header file within the module's home directory.
auto *Directory = M->Directory;
auto Directory = M->Directory;
SmallString<128> FullPathName(Directory->getName());

auto GetFile = [&](StringRef Filename) -> OptionalFileEntryRef {
Expand Down Expand Up @@ -972,14 +972,14 @@ static void inferFrameworkLink(Module *Mod) {
/*IsFramework=*/true));
}

Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir,
bool IsSystem, Module *Parent) {
Attributes Attrs;
Attrs.IsSystem = IsSystem;
return inferFrameworkModule(FrameworkDir, Attrs, Parent);
}

Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
Module *ModuleMap::inferFrameworkModule(DirectoryEntryRef FrameworkDir,
Attributes Attrs, Module *Parent) {
// Note: as an egregious but useful hack we use the real path here, because
// we might be looking at an embedded framework that symlinks out to a
Expand Down Expand Up @@ -1010,7 +1010,7 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
if (llvm::sys::path::has_parent_path(FrameworkDirName)) {
// Figure out the parent path.
StringRef Parent = llvm::sys::path::parent_path(FrameworkDirName);
if (auto ParentDir = FileMgr.getDirectory(Parent)) {
if (auto ParentDir = FileMgr.getOptionalDirectoryRef(Parent)) {
// Check whether we have already looked into the parent directory
// for a module map.
llvm::DenseMap<const DirectoryEntry *, InferredDirectory>::const_iterator
Expand All @@ -1019,9 +1019,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 (const FileEntry *ModMapFile =
HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
parseModuleMapFile(ModMapFile, Attrs.IsSystem, *ParentDir);
if (OptionalFileEntryRef ModMapFile =
HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
parseModuleMapFile(*ModMapFile, Attrs.IsSystem, *ParentDir);
inferred = InferredDirectories.find(*ParentDir);
}

Expand Down Expand Up @@ -1057,7 +1057,7 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
}

// Look for an umbrella header.
SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName());
SmallString<128> UmbrellaName = FrameworkDir.getName();
llvm::sys::path::append(UmbrellaName, "Headers", ModuleName + ".h");
auto UmbrellaHeader = FileMgr.getOptionalFileRef(UmbrellaName);

Expand Down Expand Up @@ -1103,8 +1103,7 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,

// Look for subframeworks.
std::error_code EC;
SmallString<128> SubframeworksDirName
= StringRef(FrameworkDir->getName());
SmallString<128> SubframeworksDirName = FrameworkDir.getName();
llvm::sys::path::append(SubframeworksDirName, "Frameworks");
llvm::sys::path::native(SubframeworksDirName);
llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
Expand All @@ -1115,8 +1114,7 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
if (!StringRef(Dir->path()).endswith(".framework"))
continue;

if (auto SubframeworkDir =
FileMgr.getDirectory(Dir->path())) {
if (auto SubframeworkDir = FileMgr.getOptionalDirectoryRef(Dir->path())) {
// Note: as an egregious but useful hack, we use the real path here and
// check whether it is actually a subdirectory of the parent directory.
// This will not be the case if the 'subframework' is actually a symlink
Expand Down Expand Up @@ -1520,7 +1518,7 @@ namespace clang {

/// The directory that file names in this module map file should
/// be resolved relative to.
const DirectoryEntry *Directory;
DirectoryEntryRef Directory;

/// Whether this module map is in a system header directory.
bool IsSystem;
Expand Down Expand Up @@ -1586,7 +1584,7 @@ namespace clang {
explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr,
const TargetInfo *Target, DiagnosticsEngine &Diags,
ModuleMap &Map, const FileEntry *ModuleMapFile,
const DirectoryEntry *Directory, bool IsSystem)
DirectoryEntryRef Directory, bool IsSystem)
: L(L), SourceMgr(SourceMgr), Target(Target), Diags(Diags), Map(Map),
ModuleMapFile(ModuleMapFile), Directory(Directory),
IsSystem(IsSystem) {
Expand Down Expand Up @@ -2256,16 +2254,16 @@ void ModuleMapParser::parseExternModuleDecl() {
StringRef FileNameRef = FileName;
SmallString<128> ModuleMapFileName;
if (llvm::sys::path::is_relative(FileNameRef)) {
ModuleMapFileName += Directory->getName();
ModuleMapFileName += Directory.getName();
llvm::sys::path::append(ModuleMapFileName, FileName);
FileNameRef = ModuleMapFileName;
}
if (auto File = SourceMgr.getFileManager().getFile(FileNameRef))
if (auto File = SourceMgr.getFileManager().getOptionalFileRef(FileNameRef))
Map.parseModuleMapFile(
*File, IsSystem,
Map.HeaderInfo.getHeaderSearchOpts().ModuleMapFileHomeIsCwd
? Directory
: (*File)->getDir(),
: File->getDir(),
FileID(), nullptr, ExternLoc);
}

Expand Down Expand Up @@ -2520,7 +2518,7 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(DirName);
} else {
SmallString<128> PathName;
PathName = Directory->getName();
PathName = Directory.getName();
llvm::sys::path::append(PathName, DirName);
Dir = SourceMgr.getFileManager().getOptionalDirectoryRef(PathName);
}
Expand Down Expand Up @@ -3082,7 +3080,7 @@ bool ModuleMapParser::parseModuleMapFile() {
}

bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
const DirectoryEntry *Dir, FileID ID,
DirectoryEntryRef Dir, FileID ID,
unsigned *Offset,
SourceLocation ExternModuleLoc) {
assert(Target && "Missing target information");
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Lex/PPDirectives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ OptionalFileEntryRef Preprocessor::LookupFile(
// map file.
if (!FileEnt) {
if (FID == SourceMgr.getMainFileID() && MainFileDir) {
Includers.push_back(std::make_pair(nullptr, MainFileDir));
Includers.push_back(std::make_pair(nullptr, *MainFileDir));
BuildSystemModule = getCurrentModule()->IsSystem;
} else if ((FileEnt =
SourceMgr.getFileEntryForID(SourceMgr.getMainFileID())))
Expand Down
11 changes: 5 additions & 6 deletions clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10055,12 +10055,12 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) {
// header maps are not (currently) enumerable.
break;
case DirectoryLookup::LT_NormalDir:
AddFilesFromIncludeDir(IncludeDir.getDir()->getName(), IsSystem,
AddFilesFromIncludeDir(IncludeDir.getDirRef()->getName(), IsSystem,
DirectoryLookup::LT_NormalDir);
break;
case DirectoryLookup::LT_Framework:
AddFilesFromIncludeDir(IncludeDir.getFrameworkDir()->getName(), IsSystem,
DirectoryLookup::LT_Framework);
AddFilesFromIncludeDir(IncludeDir.getFrameworkDirRef()->getName(),
IsSystem, DirectoryLookup::LT_Framework);
break;
}
};
Expand All @@ -10072,9 +10072,8 @@ void Sema::CodeCompleteIncludedFile(llvm::StringRef Dir, bool Angled) {
using llvm::make_range;
if (!Angled) {
// The current directory is on the include path for "quoted" includes.
const FileEntry *CurFile = PP.getCurrentFileLexer()->getFileEntry();
if (CurFile && CurFile->getDir())
AddFilesFromIncludeDir(CurFile->getDir()->getName(), false,
if (auto CurFile = PP.getCurrentFileLexer()->getFileEntry())
AddFilesFromIncludeDir(CurFile->getDir().getName(), false,
DirectoryLookup::LT_NormalDir);
for (const auto &D : make_range(S.quoted_dir_begin(), S.quoted_dir_end()))
AddFilesFromDirLookup(D, false);
Expand Down