@@ -79,11 +79,6 @@ HeaderFileInfo::getControllingMacro(ExternalPreprocessorSource *External) {
79
79
80
80
ExternalHeaderFileInfoSource::~ExternalHeaderFileInfoSource () = default ;
81
81
82
- const DirectoryLookup &ConstSearchDirIterator::operator *() const {
83
- assert (*this && " Invalid iterator." );
84
- return HS->SearchDirs [Idx];
85
- }
86
-
87
82
HeaderSearch::HeaderSearch (std::shared_ptr<HeaderSearchOptions> HSOpts,
88
83
SourceManager &SourceMgr, DiagnosticsEngine &Diags,
89
84
const LangOptions &LangOpts,
@@ -304,21 +299,20 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
304
299
SourceLocation ImportLoc,
305
300
bool AllowExtraModuleMapSearch) {
306
301
Module *Module = nullptr ;
307
- unsigned Idx ;
302
+ SearchDirIterator It = nullptr ;
308
303
309
304
// Look through the various header search paths to load any available module
310
305
// maps, searching for a module map that describes this module.
311
- for (Idx = 0 ; Idx != SearchDirs. size (); ++Idx ) {
312
- if (SearchDirs[Idx]. isFramework ()) {
306
+ for (It = search_dir_begin (); It != search_dir_end (); ++It ) {
307
+ if (It-> isFramework ()) {
313
308
// Search for or infer a module map for a framework. Here we use
314
309
// SearchName rather than ModuleName, to permit finding private modules
315
310
// named FooPrivate in buggy frameworks named Foo.
316
311
SmallString<128 > FrameworkDirName;
317
- FrameworkDirName += SearchDirs[Idx]. getFrameworkDir ()->getName ();
312
+ FrameworkDirName += It-> getFrameworkDir ()->getName ();
318
313
llvm::sys::path::append (FrameworkDirName, SearchName + " .framework" );
319
314
if (auto FrameworkDir = FileMgr.getDirectory (FrameworkDirName)) {
320
- bool IsSystem
321
- = SearchDirs[Idx].getDirCharacteristic () != SrcMgr::C_User;
315
+ bool IsSystem = It->getDirCharacteristic () != SrcMgr::C_User;
322
316
Module = loadFrameworkModule (ModuleName, *FrameworkDir, IsSystem);
323
317
if (Module)
324
318
break ;
@@ -328,12 +322,12 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
328
322
// FIXME: Figure out how header maps and module maps will work together.
329
323
330
324
// Only deal with normal search directories.
331
- if (!SearchDirs[Idx]. isNormalDir ())
325
+ if (!It-> isNormalDir ())
332
326
continue ;
333
327
334
- bool IsSystem = SearchDirs[Idx]. isSystemHeaderDirectory ();
328
+ bool IsSystem = It-> isSystemHeaderDirectory ();
335
329
// Search for a module map file in this directory.
336
- if (loadModuleMapFile (SearchDirs[Idx]. getDir (), IsSystem,
330
+ if (loadModuleMapFile (It-> getDir (), IsSystem,
337
331
/* IsFramework*/ false ) == LMM_NewlyLoaded) {
338
332
// We just loaded a module map file; check whether the module is
339
333
// available now.
@@ -345,7 +339,7 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
345
339
// Search for a module map in a subdirectory with the same name as the
346
340
// module.
347
341
SmallString<128 > NestedModuleMapDirName;
348
- NestedModuleMapDirName = SearchDirs[Idx]. getDir ()->getName ();
342
+ NestedModuleMapDirName = It-> getDir ()->getName ();
349
343
llvm::sys::path::append (NestedModuleMapDirName, ModuleName);
350
344
if (loadModuleMapFile (NestedModuleMapDirName, IsSystem,
351
345
/* IsFramework*/ false ) == LMM_NewlyLoaded){
@@ -357,13 +351,13 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
357
351
358
352
// If we've already performed the exhaustive search for module maps in this
359
353
// search directory, don't do it again.
360
- if (SearchDirs[Idx]. haveSearchedAllModuleMaps ())
354
+ if (It-> haveSearchedAllModuleMaps ())
361
355
continue ;
362
356
363
357
// Load all module maps in the immediate subdirectories of this search
364
358
// directory if ModuleName was from @import.
365
359
if (AllowExtraModuleMapSearch)
366
- loadSubdirectoryModuleMaps (SearchDirs[Idx] );
360
+ loadSubdirectoryModuleMaps (*It );
367
361
368
362
// Look again for the module.
369
363
Module = ModMap.findModule (ModuleName);
@@ -372,7 +366,7 @@ Module *HeaderSearch::lookupModule(StringRef ModuleName, StringRef SearchName,
372
366
}
373
367
374
368
if (Module)
375
- noteLookupUsage (Idx, ImportLoc);
369
+ noteLookupUsage (It. Idx , ImportLoc);
376
370
377
371
return Module;
378
372
}
@@ -498,7 +492,7 @@ Optional<FileEntryRef> DirectoryLookup::LookupFile(
498
492
// The case where the target file **exists** is handled by callee of this
499
493
// function as part of the regular logic that applies to include search paths.
500
494
// The case where the target file **does not exist** is handled here:
501
- HS.noteLookupUsage (* HS.searchDirIdx (*this ), IncludeLoc);
495
+ HS.noteLookupUsage (HS.searchDirIdx (*this ), IncludeLoc);
502
496
return None;
503
497
}
504
498
@@ -1452,11 +1446,8 @@ size_t HeaderSearch::getTotalMemory() const {
1452
1446
+ FrameworkMap.getAllocator ().getTotalMemory ();
1453
1447
}
1454
1448
1455
- Optional<unsigned > HeaderSearch::searchDirIdx (const DirectoryLookup &DL) const {
1456
- for (unsigned I = 0 ; I < SearchDirs.size (); ++I)
1457
- if (&SearchDirs[I] == &DL)
1458
- return I;
1459
- return None;
1449
+ unsigned HeaderSearch::searchDirIdx (const DirectoryLookup &DL) const {
1450
+ return &DL - &*SearchDirs.begin ();
1460
1451
}
1461
1452
1462
1453
StringRef HeaderSearch::getUniqueFrameworkName (StringRef Framework) {
@@ -1785,13 +1776,12 @@ void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) {
1785
1776
1786
1777
if (HSOpts->ImplicitModuleMaps ) {
1787
1778
// Load module maps for each of the header search directories.
1788
- for (unsigned Idx = 0 , N = SearchDirs. size (); Idx != N; ++Idx ) {
1789
- bool IsSystem = SearchDirs[Idx] .isSystemHeaderDirectory ();
1790
- if (SearchDirs[Idx] .isFramework ()) {
1779
+ for (DirectoryLookup &DL : search_dir_range () ) {
1780
+ bool IsSystem = DL .isSystemHeaderDirectory ();
1781
+ if (DL .isFramework ()) {
1791
1782
std::error_code EC;
1792
1783
SmallString<128 > DirNative;
1793
- llvm::sys::path::native (SearchDirs[Idx].getFrameworkDir ()->getName (),
1794
- DirNative);
1784
+ llvm::sys::path::native (DL.getFrameworkDir ()->getName (), DirNative);
1795
1785
1796
1786
// Search each of the ".framework" directories to load them as modules.
1797
1787
llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem ();
@@ -1814,16 +1804,15 @@ void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) {
1814
1804
}
1815
1805
1816
1806
// FIXME: Deal with header maps.
1817
- if (SearchDirs[Idx] .isHeaderMap ())
1807
+ if (DL .isHeaderMap ())
1818
1808
continue ;
1819
1809
1820
1810
// Try to load a module map file for the search directory.
1821
- loadModuleMapFile (SearchDirs[Idx].getDir (), IsSystem,
1822
- /* IsFramework*/ false );
1811
+ loadModuleMapFile (DL.getDir (), IsSystem, /* IsFramework*/ false );
1823
1812
1824
1813
// Try to load module map files for immediate subdirectories of this
1825
1814
// search directory.
1826
- loadSubdirectoryModuleMaps (SearchDirs[Idx] );
1815
+ loadSubdirectoryModuleMaps (DL );
1827
1816
}
1828
1817
}
1829
1818
@@ -1837,16 +1826,14 @@ void HeaderSearch::loadTopLevelSystemModules() {
1837
1826
return ;
1838
1827
1839
1828
// Load module maps for each of the header search directories.
1840
- for (unsigned Idx = 0 , N = SearchDirs. size (); Idx != N; ++Idx ) {
1829
+ for (const DirectoryLookup &DL : search_dir_range () ) {
1841
1830
// We only care about normal header directories.
1842
- if (!SearchDirs[Idx] .isNormalDir ()) {
1831
+ if (!DL .isNormalDir ())
1843
1832
continue ;
1844
- }
1845
1833
1846
1834
// Try to load a module map file for the search directory.
1847
- loadModuleMapFile (SearchDirs[Idx].getDir (),
1848
- SearchDirs[Idx].isSystemHeaderDirectory (),
1849
- SearchDirs[Idx].isFramework ());
1835
+ loadModuleMapFile (DL.getDir (), DL.isSystemHeaderDirectory (),
1836
+ DL.isFramework ());
1850
1837
}
1851
1838
}
1852
1839
@@ -1943,19 +1930,19 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
1943
1930
};
1944
1931
1945
1932
bool BestPrefixIsFramework = false ;
1946
- for (unsigned I = 0 ; I != SearchDirs. size (); ++I ) {
1947
- if (SearchDirs[I] .isNormalDir ()) {
1948
- StringRef Dir = SearchDirs[I] .getDir ()->getName ();
1933
+ for (const DirectoryLookup &DL : search_dir_range () ) {
1934
+ if (DL .isNormalDir ()) {
1935
+ StringRef Dir = DL .getDir ()->getName ();
1949
1936
if (CheckDir (Dir)) {
1950
1937
if (IsSystem)
1951
- *IsSystem = BestPrefixLength ? I >= SystemDirIdx : false ;
1938
+ *IsSystem = BestPrefixLength && isSystem (DL. getDirCharacteristic ()) ;
1952
1939
BestPrefixIsFramework = false ;
1953
1940
}
1954
- } else if (SearchDirs[I] .isFramework ()) {
1955
- StringRef Dir = SearchDirs[I] .getFrameworkDir ()->getName ();
1941
+ } else if (DL .isFramework ()) {
1942
+ StringRef Dir = DL .getFrameworkDir ()->getName ();
1956
1943
if (CheckDir (Dir)) {
1957
1944
if (IsSystem)
1958
- *IsSystem = BestPrefixLength ? I >= SystemDirIdx : false ;
1945
+ *IsSystem = BestPrefixLength && isSystem (DL. getDirCharacteristic ()) ;
1959
1946
BestPrefixIsFramework = true ;
1960
1947
}
1961
1948
}
@@ -1972,12 +1959,12 @@ std::string HeaderSearch::suggestPathToFileForDiagnostics(
1972
1959
// Try resolving resulting filename via reverse search in header maps,
1973
1960
// key from header name is user prefered name for the include file.
1974
1961
StringRef Filename = File.drop_front (BestPrefixLength);
1975
- for (unsigned I = 0 ; I != SearchDirs. size (); ++I ) {
1976
- if (!SearchDirs[I] .isHeaderMap ())
1962
+ for (const DirectoryLookup &DL : search_dir_range () ) {
1963
+ if (!DL .isHeaderMap ())
1977
1964
continue ;
1978
1965
1979
1966
StringRef SpelledFilename =
1980
- SearchDirs[I] .getHeaderMap ()->reverseLookupFilename (Filename);
1967
+ DL .getHeaderMap ()->reverseLookupFilename (Filename);
1981
1968
if (!SpelledFilename.empty ()) {
1982
1969
Filename = SpelledFilename;
1983
1970
BestPrefixIsFramework = false ;
0 commit comments