@@ -319,7 +319,8 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
319
319
SmallString<128 > FrameworkDirName;
320
320
FrameworkDirName += Dir.getFrameworkDir ()->getName ();
321
321
llvm::sys::path::append (FrameworkDirName, SearchName + " .framework" );
322
- if (auto FrameworkDir = FileMgr.getDirectory (FrameworkDirName)) {
322
+ if (auto FrameworkDir =
323
+ FileMgr.getOptionalDirectoryRef (FrameworkDirName)) {
323
324
bool IsSystem = Dir.getDirCharacteristic () != SrcMgr::C_User;
324
325
Module = loadFrameworkModule (ModuleName, *FrameworkDir, IsSystem);
325
326
if (Module)
@@ -334,8 +335,10 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
334
335
continue ;
335
336
336
337
bool IsSystem = Dir.isSystemHeaderDirectory ();
338
+ // Only returns None if not a normal directory, which we just checked
339
+ DirectoryEntryRef NormalDir = *Dir.getDirRef ();
337
340
// Search for a module map file in this directory.
338
- if (loadModuleMapFile (Dir. getDir () , IsSystem,
341
+ if (loadModuleMapFile (NormalDir , IsSystem,
339
342
/* IsFramework*/ false ) == LMM_NewlyLoaded) {
340
343
// We just loaded a module map file; check whether the module is
341
344
// available now.
@@ -507,7 +510,7 @@ Optional<FileEntryRef> DirectoryLookup::LookupFile(
507
510
// / \param DirName The name of the framework directory.
508
511
// / \param SubmodulePath Will be populated with the submodule path from the
509
512
// / returned top-level module to the originally named framework.
510
- static const DirectoryEntry *
513
+ static Optional<DirectoryEntryRef>
511
514
getTopFrameworkDir (FileManager &FileMgr, StringRef DirName,
512
515
SmallVectorImpl<std::string> &SubmodulePath) {
513
516
assert (llvm::sys::path::extension (DirName) == " .framework" &&
@@ -527,20 +530,18 @@ getTopFrameworkDir(FileManager &FileMgr, StringRef DirName,
527
530
//
528
531
// Similar issues occur when a top-level framework has moved into an
529
532
// embedded framework.
530
- const DirectoryEntry *TopFrameworkDir = nullptr ;
531
- if (auto TopFrameworkDirOrErr = FileMgr.getDirectory (DirName))
532
- TopFrameworkDir = *TopFrameworkDirOrErr;
533
+ auto TopFrameworkDir = FileMgr.getOptionalDirectoryRef (DirName);
533
534
534
535
if (TopFrameworkDir)
535
- DirName = FileMgr.getCanonicalName (TopFrameworkDir);
536
+ DirName = FileMgr.getCanonicalName (* TopFrameworkDir);
536
537
do {
537
538
// Get the parent directory name.
538
539
DirName = llvm::sys::path::parent_path (DirName);
539
540
if (DirName.empty ())
540
541
break ;
541
542
542
543
// Determine whether this directory exists.
543
- auto Dir = FileMgr.getDirectory (DirName);
544
+ auto Dir = FileMgr.getOptionalDirectoryRef (DirName);
544
545
if (!Dir)
545
546
break ;
546
547
@@ -1476,13 +1477,13 @@ bool HeaderSearch::hasModuleMap(StringRef FileName,
1476
1477
return false ;
1477
1478
1478
1479
// Determine whether this directory exists.
1479
- auto Dir = FileMgr.getDirectory (DirName);
1480
+ auto Dir = FileMgr.getOptionalDirectoryRef (DirName);
1480
1481
if (!Dir)
1481
1482
return false ;
1482
1483
1483
1484
// Try to load the module map file in this directory.
1484
1485
switch (loadModuleMapFile (*Dir, IsSystem,
1485
- llvm::sys::path::extension ((* Dir) ->getName ()) ==
1486
+ llvm::sys::path::extension (Dir->getName ()) ==
1486
1487
" .framework" )) {
1487
1488
case LMM_NewlyLoaded:
1488
1489
case LMM_AlreadyLoaded:
@@ -1579,15 +1580,16 @@ bool HeaderSearch::findUsableModuleForFrameworkHeader(
1579
1580
if (needModuleLookup (RequestingModule, SuggestedModule)) {
1580
1581
// Find the top-level framework based on this framework.
1581
1582
SmallVector<std::string, 4 > SubmodulePath;
1582
- const DirectoryEntry *TopFrameworkDir
1583
- = ::getTopFrameworkDir (FileMgr, FrameworkName, SubmodulePath);
1583
+ Optional<DirectoryEntryRef> TopFrameworkDir =
1584
+ ::getTopFrameworkDir (FileMgr, FrameworkName, SubmodulePath);
1585
+ assert (TopFrameworkDir && " Could not find the top-most framework dir" );
1584
1586
1585
1587
// Determine the name of the top-level framework.
1586
1588
StringRef ModuleName = llvm::sys::path::stem (TopFrameworkDir->getName ());
1587
1589
1588
1590
// Load this framework module. If that succeeds, find the suggested module
1589
1591
// for this header, if any.
1590
- loadFrameworkModule (ModuleName, TopFrameworkDir, IsSystemFramework);
1592
+ loadFrameworkModule (ModuleName, * TopFrameworkDir, IsSystemFramework);
1591
1593
1592
1594
// FIXME: This can find a module not part of ModuleName, which is
1593
1595
// important so that we're consistent about whether this header
@@ -1618,39 +1620,38 @@ bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem,
1618
1620
StringRef OriginalModuleMapFile) {
1619
1621
// Find the directory for the module. For frameworks, that may require going
1620
1622
// up from the 'Modules' directory.
1621
- const DirectoryEntry * Dir = nullptr ;
1623
+ Optional<DirectoryEntryRef> Dir;
1622
1624
if (getHeaderSearchOpts ().ModuleMapFileHomeIsCwd ) {
1623
- if (auto DirOrErr = FileMgr.getDirectory (" ." ))
1624
- Dir = *DirOrErr;
1625
+ Dir = FileMgr.getOptionalDirectoryRef (" ." );
1625
1626
} else {
1626
1627
if (!OriginalModuleMapFile.empty ()) {
1627
1628
// We're building a preprocessed module map. Find or invent the directory
1628
1629
// that it originally occupied.
1629
- auto DirOrErr = FileMgr.getDirectory (
1630
+ Dir = FileMgr.getOptionalDirectoryRef (
1630
1631
llvm::sys::path::parent_path (OriginalModuleMapFile));
1631
- if (DirOrErr) {
1632
- Dir = *DirOrErr;
1633
- } else {
1634
- auto *FakeFile = FileMgr.getVirtualFile (OriginalModuleMapFile, 0 , 0 );
1635
- Dir = FakeFile->getDir ();
1632
+ if (!Dir) {
1633
+ auto FakeFile = FileMgr.getVirtualFileRef (OriginalModuleMapFile, 0 , 0 );
1634
+ Dir = FakeFile.getDir ();
1636
1635
}
1637
1636
} else {
1638
- Dir = File->getDir ();
1637
+ Dir = File->getLastRef (). getDir ();
1639
1638
}
1640
1639
1640
+ assert (Dir && " parent must exist" );
1641
1641
StringRef DirName (Dir->getName ());
1642
1642
if (llvm::sys::path::filename (DirName) == " Modules" ) {
1643
1643
DirName = llvm::sys::path::parent_path (DirName);
1644
1644
if (DirName.endswith (" .framework" ))
1645
- if (auto DirOrErr = FileMgr.getDirectory (DirName))
1646
- Dir = *DirOrErr ;
1645
+ if (auto MaybeDir = FileMgr.getOptionalDirectoryRef (DirName))
1646
+ Dir = *MaybeDir ;
1647
1647
// FIXME: This assert can fail if there's a race between the above check
1648
1648
// and the removal of the directory.
1649
1649
assert (Dir && " parent must exist" );
1650
1650
}
1651
1651
}
1652
1652
1653
- switch (loadModuleMapFileImpl (File, IsSystem, Dir, ID, Offset)) {
1653
+ assert (Dir && " module map home directory must exist" );
1654
+ switch (loadModuleMapFileImpl (File, IsSystem, *Dir, ID, Offset)) {
1654
1655
case LMM_AlreadyLoaded:
1655
1656
case LMM_NewlyLoaded:
1656
1657
return false ;
@@ -1663,7 +1664,7 @@ bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem,
1663
1664
1664
1665
HeaderSearch::LoadModuleMapResult
1665
1666
HeaderSearch::loadModuleMapFileImpl (const FileEntry *File, bool IsSystem,
1666
- const DirectoryEntry * Dir, FileID ID,
1667
+ DirectoryEntryRef Dir, FileID ID,
1667
1668
unsigned *Offset) {
1668
1669
assert (File && " expected FileEntry" );
1669
1670
@@ -1721,8 +1722,7 @@ HeaderSearch::lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework) {
1721
1722
return nullptr ;
1722
1723
}
1723
1724
1724
- Module *HeaderSearch::loadFrameworkModule (StringRef Name,
1725
- const DirectoryEntry *Dir,
1725
+ Module *HeaderSearch::loadFrameworkModule (StringRef Name, DirectoryEntryRef Dir,
1726
1726
bool IsSystem) {
1727
1727
if (Module *Module = ModMap.findModule (Name))
1728
1728
return Module;
@@ -1749,14 +1749,14 @@ Module *HeaderSearch::loadFrameworkModule(StringRef Name,
1749
1749
HeaderSearch::LoadModuleMapResult
1750
1750
HeaderSearch::loadModuleMapFile (StringRef DirName, bool IsSystem,
1751
1751
bool IsFramework) {
1752
- if (auto Dir = FileMgr.getDirectory (DirName))
1752
+ if (auto Dir = FileMgr.getOptionalDirectoryRef (DirName))
1753
1753
return loadModuleMapFile (*Dir, IsSystem, IsFramework);
1754
1754
1755
1755
return LMM_NoDirectory;
1756
1756
}
1757
1757
1758
1758
HeaderSearch::LoadModuleMapResult
1759
- HeaderSearch::loadModuleMapFile (const DirectoryEntry * Dir, bool IsSystem,
1759
+ HeaderSearch::loadModuleMapFile (DirectoryEntryRef Dir, bool IsSystem,
1760
1760
bool IsFramework) {
1761
1761
auto KnownDir = DirectoryHasModuleMap.find (Dir);
1762
1762
if (KnownDir != DirectoryHasModuleMap.end ())
@@ -1797,8 +1797,7 @@ void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) {
1797
1797
if (llvm::sys::path::extension (Dir->path ()) != " .framework" )
1798
1798
continue ;
1799
1799
1800
- auto FrameworkDir =
1801
- FileMgr.getDirectory (Dir->path ());
1800
+ auto FrameworkDir = FileMgr.getOptionalDirectoryRef (Dir->path ());
1802
1801
if (!FrameworkDir)
1803
1802
continue ;
1804
1803
@@ -1814,7 +1813,7 @@ void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) {
1814
1813
continue ;
1815
1814
1816
1815
// Try to load a module map file for the search directory.
1817
- loadModuleMapFile (DL.getDir (), IsSystem, /* IsFramework*/ false );
1816
+ loadModuleMapFile (* DL.getDirRef (), IsSystem, /* IsFramework*/ false );
1818
1817
1819
1818
// Try to load module map files for immediate subdirectories of this
1820
1819
// search directory.
@@ -1838,7 +1837,7 @@ void HeaderSearch::loadTopLevelSystemModules() {
1838
1837
continue ;
1839
1838
1840
1839
// Try to load a module map file for the search directory.
1841
- loadModuleMapFile (DL.getDir (), DL.isSystemHeaderDirectory (),
1840
+ loadModuleMapFile (* DL.getDirRef (), DL.isSystemHeaderDirectory (),
1842
1841
DL.isFramework ());
1843
1842
}
1844
1843
}
0 commit comments