diff options
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Basic/VirtualFileSystem.cpp | 81 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains/BareMetal.cpp | 2 | ||||
| -rw-r--r-- | clang/lib/Driver/ToolChains/Gnu.cpp | 8 | ||||
| -rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 14 | ||||
| -rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 13 | ||||
| -rw-r--r-- | clang/lib/Lex/ModuleMap.cpp | 9 | ||||
| -rw-r--r-- | clang/lib/Lex/PPLexerChange.cpp | 4 |
8 files changed, 63 insertions, 72 deletions
diff --git a/clang/lib/Basic/VirtualFileSystem.cpp b/clang/lib/Basic/VirtualFileSystem.cpp index 9972ac4cba9..e5eb5e47fdf 100644 --- a/clang/lib/Basic/VirtualFileSystem.cpp +++ b/clang/lib/Basic/VirtualFileSystem.cpp @@ -315,27 +315,16 @@ class RealFSDirIter : public clang::vfs::detail::DirIterImpl { public: RealFSDirIter(const Twine &Path, std::error_code &EC) : Iter(Path, EC) { - if (Iter != llvm::sys::fs::directory_iterator()) { - llvm::sys::fs::file_status S; - std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S, true); - CurrentEntry = Status::copyWithNewName(S, Iter->path()); - if (!EC) - EC = ErrorCode; - } + if (Iter != llvm::sys::fs::directory_iterator()) + CurrentEntry = directory_entry(Iter->path(), Iter->type()); } std::error_code increment() override { std::error_code EC; Iter.increment(EC); - if (Iter == llvm::sys::fs::directory_iterator()) { - CurrentEntry = Status(); - } else { - llvm::sys::fs::file_status S; - std::error_code ErrorCode = llvm::sys::fs::status(Iter->path(), S, true); - CurrentEntry = Status::copyWithNewName(S, Iter->path()); - if (!EC) - EC = ErrorCode; - } + CurrentEntry = (Iter == llvm::sys::fs::directory_iterator()) + ? directory_entry() + : directory_entry(Iter->path(), Iter->type()); return EC; } }; @@ -446,11 +435,11 @@ class OverlayFSDirIterImpl : public clang::vfs::detail::DirIterImpl { while (true) { std::error_code EC = incrementDirIter(IsFirstTime); if (EC || CurrentDirIter == directory_iterator()) { - CurrentEntry = Status(); + CurrentEntry = directory_entry(); return EC; } CurrentEntry = *CurrentDirIter; - StringRef Name = llvm::sys::path::filename(CurrentEntry.getName()); + StringRef Name = llvm::sys::path::filename(CurrentEntry.path()); if (SeenNames.insert(Name).second) return EC; // name not seen before } @@ -850,11 +839,21 @@ class InMemoryDirIterator : public clang::vfs::detail::DirIterImpl { if (I != E) { SmallString<256> Path(RequestedDirName); llvm::sys::path::append(Path, I->second->getFileName()); - CurrentEntry = detail::getNodeStatus(I->second.get(), Path); + sys::fs::file_type Type; + switch (I->second->getKind()) { + case detail::IME_File: + case detail::IME_HardLink: + Type = sys::fs::file_type::regular_file; + break; + case detail::IME_Directory: + Type = sys::fs::file_type::directory_file; + break; + } + CurrentEntry = directory_entry(Path.str(), Type); } else { // When we're at the end, make CurrentEntry invalid and DirIterImpl will // do the rest. - CurrentEntry = Status(); + CurrentEntry = directory_entry(); } } @@ -1010,17 +1009,14 @@ public: static bool classof(const Entry *E) { return E->getKind() == EK_File; } }; -class RedirectingFileSystem; - class VFSFromYamlDirIterImpl : public clang::vfs::detail::DirIterImpl { std::string Dir; - RedirectingFileSystem &FS; RedirectingDirectoryEntry::iterator Current, End; std::error_code incrementImpl(); public: - VFSFromYamlDirIterImpl(const Twine &Path, RedirectingFileSystem &FS, + VFSFromYamlDirIterImpl(const Twine &Path, RedirectingDirectoryEntry::iterator Begin, RedirectingDirectoryEntry::iterator End, std::error_code &EC); @@ -1184,8 +1180,8 @@ public: } auto *D = cast<RedirectingDirectoryEntry>(*E); - return directory_iterator(std::make_shared<VFSFromYamlDirIterImpl>(Dir, - *this, D->contents_begin(), D->contents_end(), EC)); + return directory_iterator(std::make_shared<VFSFromYamlDirIterImpl>( + Dir, D->contents_begin(), D->contents_end(), EC)); } void setExternalContentsPrefixDir(StringRef PrefixDir) { @@ -2079,10 +2075,9 @@ void YAMLVFSWriter::write(llvm::raw_ostream &OS) { } VFSFromYamlDirIterImpl::VFSFromYamlDirIterImpl( - const Twine &_Path, RedirectingFileSystem &FS, - RedirectingDirectoryEntry::iterator Begin, + const Twine &_Path, RedirectingDirectoryEntry::iterator Begin, RedirectingDirectoryEntry::iterator End, std::error_code &EC) - : Dir(_Path.str()), FS(FS), Current(Begin), End(End) { + : Dir(_Path.str()), Current(Begin), End(End) { EC = incrementImpl(); } @@ -2096,23 +2091,21 @@ std::error_code VFSFromYamlDirIterImpl::incrementImpl() { while (Current != End) { SmallString<128> PathStr(Dir); llvm::sys::path::append(PathStr, (*Current)->getName()); - llvm::ErrorOr<vfs::Status> S = FS.status(PathStr); - if (!S) { - // Skip entries which do not map to a reliable external content. - if (FS.ignoreNonExistentContents() && - S.getError() == llvm::errc::no_such_file_or_directory) { - ++Current; - continue; - } else { - return S.getError(); - } + sys::fs::file_type Type; + switch ((*Current)->getKind()) { + case EK_Directory: + Type = sys::fs::file_type::directory_file; + break; + case EK_File: + Type = sys::fs::file_type::regular_file; + break; } - CurrentEntry = *S; + CurrentEntry = directory_entry(PathStr.str(), Type); break; } if (Current == End) - CurrentEntry = Status(); + CurrentEntry = directory_entry(); return {}; } @@ -2130,10 +2123,10 @@ vfs::recursive_directory_iterator::recursive_directory_iterator(FileSystem &FS_, vfs::recursive_directory_iterator & recursive_directory_iterator::increment(std::error_code &EC) { assert(FS && State && !State->empty() && "incrementing past end"); - assert(State->top()->isStatusKnown() && "non-canonical end iterator"); + assert(!State->top()->path().empty() && "non-canonical end iterator"); vfs::directory_iterator End; - if (State->top()->isDirectory()) { - vfs::directory_iterator I = FS->dir_begin(State->top()->getName(), EC); + if (State->top()->type() == sys::fs::file_type::directory_file) { + vfs::directory_iterator I = FS->dir_begin(State->top()->path(), EC); if (I != End) { State->push(I); return *this; diff --git a/clang/lib/Driver/ToolChains/BareMetal.cpp b/clang/lib/Driver/ToolChains/BareMetal.cpp index c302d647b97..adce10854bb 100644 --- a/clang/lib/Driver/ToolChains/BareMetal.cpp +++ b/clang/lib/Driver/ToolChains/BareMetal.cpp @@ -122,7 +122,7 @@ void BareMetal::AddClangCXXStdlibIncludeArgs( for (vfs::directory_iterator LI = getDriver().getVFS().dir_begin(Dir.str(), EC), LE; !EC && LI != LE; LI = LI.increment(EC)) { - StringRef VersionText = llvm::sys::path::filename(LI->getName()); + StringRef VersionText = llvm::sys::path::filename(LI->path()); auto CandidateVersion = Generic_GCC::GCCVersion::Parse(VersionText); if (CandidateVersion.Major == -1) continue; diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 89119308490..fda02b50a27 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -1764,7 +1764,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes( std::error_code EC; for (vfs::directory_iterator LI = D.getVFS().dir_begin(PrefixDir, EC), LE; !EC && LI != LE; LI = LI.increment(EC)) { - StringRef VersionText = llvm::sys::path::filename(LI->getName()); + StringRef VersionText = llvm::sys::path::filename(LI->path()); GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); // Filter out obviously bad entries. @@ -2209,17 +2209,17 @@ void Generic_GCC::GCCInstallationDetector::ScanLibDirForGCCTriple( LI = D.getVFS().dir_begin(LibDir + "/" + LibSuffix, EC), LE; !EC && LI != LE; LI = LI.increment(EC)) { - StringRef VersionText = llvm::sys::path::filename(LI->getName()); + StringRef VersionText = llvm::sys::path::filename(LI->path()); GCCVersion CandidateVersion = GCCVersion::Parse(VersionText); if (CandidateVersion.Major != -1) // Filter obviously bad entries. - if (!CandidateGCCInstallPaths.insert(LI->getName()).second) + if (!CandidateGCCInstallPaths.insert(LI->path()).second) continue; // Saw this path before; no need to look at it again. if (CandidateVersion.isOlderThan(4, 1, 1)) continue; if (CandidateVersion <= Version) continue; - if (!ScanGCCForMultilibs(TargetTriple, Args, LI->getName(), + if (!ScanGCCForMultilibs(TargetTriple, Args, LI->path(), NeedsBiarchSuffix)) continue; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index f1a8720045e..38a09a0dac3 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -185,10 +185,10 @@ static void collectIncludePCH(CompilerInstance &CI, // used here since we're not interested in validating the PCH at this time, // but only to check whether this is a file containing an AST. if (!ASTReader::readASTFileControlBlock( - Dir->getName(), FileMgr, CI.getPCHContainerReader(), + Dir->path(), FileMgr, CI.getPCHContainerReader(), /*FindModuleFileExtensions=*/false, Validator, /*ValidateDiagnosticOptions=*/false)) - MDC->addFile(Dir->getName()); + MDC->addFile(Dir->path()); } } diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 74550c41039..ddb522ae05f 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -347,12 +347,12 @@ static std::error_code collectModuleHeaderIncludes( Dir != End && !EC; Dir.increment(EC)) { // Check whether this entry has an extension typically associated with // headers. - if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->getName())) - .Cases(".h", ".H", ".hh", ".hpp", true) - .Default(false)) + if (!llvm::StringSwitch<bool>(llvm::sys::path::extension(Dir->path())) + .Cases(".h", ".H", ".hh", ".hpp", true) + .Default(false)) continue; - const FileEntry *Header = FileMgr.getFile(Dir->getName()); + const FileEntry *Header = FileMgr.getFile(Dir->path()); // FIXME: This shouldn't happen unless there is a file system race. Is // that worth diagnosing? if (!Header) @@ -365,7 +365,7 @@ static std::error_code collectModuleHeaderIncludes( // Compute the relative path from the directory to this file. SmallVector<StringRef, 16> Components; - auto PathIt = llvm::sys::path::rbegin(Dir->getName()); + auto PathIt = llvm::sys::path::rbegin(Dir->path()); for (int I = 0; I != Dir.level() + 1; ++I, ++PathIt) Components.push_back(*PathIt); SmallString<128> RelativeHeader(UmbrellaDir.NameAsWritten); @@ -696,10 +696,10 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, Dir != DirEnd && !EC; Dir.increment(EC)) { // Check whether this is an acceptable AST file. if (ASTReader::isAcceptableASTFile( - Dir->getName(), FileMgr, CI.getPCHContainerReader(), + Dir->path(), FileMgr, CI.getPCHContainerReader(), CI.getLangOpts(), CI.getTargetOpts(), CI.getPreprocessorOpts(), SpecificModuleCachePath)) { - PPOpts.ImplicitPCHInclude = Dir->getName(); + PPOpts.ImplicitPCHInclude = Dir->path(); Found = true; break; } diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 2ab020f36cc..99b9cce7f45 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -1574,17 +1574,17 @@ void HeaderSearch::collectAllModules(SmallVectorImpl<Module *> &Modules) { vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); for (vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { - if (llvm::sys::path::extension(Dir->getName()) != ".framework") + if (llvm::sys::path::extension(Dir->path()) != ".framework") continue; const DirectoryEntry *FrameworkDir = - FileMgr.getDirectory(Dir->getName()); + FileMgr.getDirectory(Dir->path()); if (!FrameworkDir) continue; // Load this framework module. - loadFrameworkModule(llvm::sys::path::stem(Dir->getName()), - FrameworkDir, IsSystem); + loadFrameworkModule(llvm::sys::path::stem(Dir->path()), FrameworkDir, + IsSystem); } continue; } @@ -1642,10 +1642,9 @@ void HeaderSearch::loadSubdirectoryModuleMaps(DirectoryLookup &SearchDir) { vfs::FileSystem &FS = *FileMgr.getVirtualFileSystem(); for (vfs::directory_iterator Dir = FS.dir_begin(DirNative, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { - bool IsFramework = - llvm::sys::path::extension(Dir->getName()) == ".framework"; + bool IsFramework = llvm::sys::path::extension(Dir->path()) == ".framework"; if (IsFramework == SearchDir.isFramework()) - loadModuleMapFile(Dir->getName(), SearchDir.isSystemHeaderDirectory(), + loadModuleMapFile(Dir->path(), SearchDir.isSystemHeaderDirectory(), SearchDir.isFramework()); } diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index 87749f74734..a1e91382175 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -1001,11 +1001,11 @@ Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir, for (vfs::directory_iterator Dir = FS.dir_begin(SubframeworksDirName, EC), DirEnd; Dir != DirEnd && !EC; Dir.increment(EC)) { - if (!StringRef(Dir->getName()).endswith(".framework")) + if (!StringRef(Dir->path()).endswith(".framework")) continue; if (const DirectoryEntry *SubframeworkDir = - FileMgr.getDirectory(Dir->getName())) { + FileMgr.getDirectory(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 @@ -2374,10 +2374,9 @@ void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) { vfs::FileSystem &FS = *SourceMgr.getFileManager().getVirtualFileSystem(); for (vfs::recursive_directory_iterator I(FS, Dir->getName(), EC), E; I != E && !EC; I.increment(EC)) { - if (const FileEntry *FE = - SourceMgr.getFileManager().getFile(I->getName())) { + if (const FileEntry *FE = SourceMgr.getFileManager().getFile(I->path())) { - Module::Header Header = {I->getName(), FE}; + Module::Header Header = {I->path(), FE}; Headers.push_back(std::move(Header)); } } diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index 6631b13b158..2ec075fa348 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -312,12 +312,12 @@ void Preprocessor::diagnoseMissingHeaderInUmbrellaDir(const Module &Mod) { // Check whether this entry has an extension typically associated with // headers. - if (!StringSwitch<bool>(llvm::sys::path::extension(Entry->getName())) + if (!StringSwitch<bool>(llvm::sys::path::extension(Entry->path())) .Cases(".h", ".H", ".hh", ".hpp", true) .Default(false)) continue; - if (const FileEntry *Header = getFileManager().getFile(Entry->getName())) + if (const FileEntry *Header = getFileManager().getFile(Entry->path())) if (!getSourceManager().hasFileInfo(Header)) { if (!ModMap.isHeaderInUnavailableModule(Header)) { // Find the relative path that would access this header. |

