diff options
Diffstat (limited to 'clang/lib')
30 files changed, 94 insertions, 119 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index d690d4c..ce1decd 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -156,7 +156,7 @@ protected: return AllowListFilenames.find(llvm::sys::path::filename(Path)) != AllowListFilenames.end(); } - bool canModifyFile(Optional<FileEntryRef> FE) { + bool canModifyFile(OptionalFileEntryRef FE) { if (!FE) return false; return canModifyFile(FE->getName()); @@ -1958,7 +1958,8 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { FileID FID = I->first; RewriteBuffer &buf = I->second; - Optional<FileEntryRef> file = Ctx.getSourceManager().getFileEntryRefForID(FID); + OptionalFileEntryRef file = + Ctx.getSourceManager().getFileEntryRefForID(FID); assert(file); SmallString<512> newText; llvm::raw_svector_ostream vecOS(newText); @@ -2028,7 +2029,7 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { namespace { struct EditEntry { - Optional<FileEntryRef> File; + OptionalFileEntryRef File; unsigned Offset = 0; unsigned RemoveLen = 0; std::string Text; diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 4fefbaa..e8d0f20 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -471,7 +471,7 @@ FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size, return FileEntryRef(NamedFileEnt); } -llvm::Optional<FileEntryRef> FileManager::getBypassFile(FileEntryRef VF) { +OptionalFileEntryRef FileManager::getBypassFile(FileEntryRef VF) { // Stat of the file and return nullptr if it doesn't exist. llvm::vfs::Status Status; if (getStatValue(VF.getName(), Status, /*isFile=*/true, /*F=*/nullptr)) diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 8eca151..63dd4d6 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -712,10 +712,10 @@ void SourceManager::overrideFileContents(const FileEntry *SourceFile, Pair.first->second = NewFile; } -Optional<FileEntryRef> +OptionalFileEntryRef SourceManager::bypassFileContentsOverride(FileEntryRef File) { assert(isFileOverridden(&File.getFileEntry())); - llvm::Optional<FileEntryRef> BypassFile = FileMgr.getBypassFile(File); + OptionalFileEntryRef BypassFile = FileMgr.getBypassFile(File); // If the file can't be found in the FS, give up. if (!BypassFile) diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index 45e2f4a..8ee4326 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -510,7 +510,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) { } if (Opts.MaxBitIntWidth) - MaxBitIntWidth = Opts.MaxBitIntWidth; + MaxBitIntWidth = static_cast<unsigned>(Opts.MaxBitIntWidth); if (Opts.FakeAddressSpaceMap) AddrSpaceMap = &FakeAddrSpaceMap; diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 382b7f3..4d1b0b6 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -536,7 +536,7 @@ void CGDebugInfo::CreateCompileUnit() { // a relative path, so we look into the actual file entry for the main // file to determine the real absolute path for the file. std::string MainFileDir; - if (Optional<FileEntryRef> MainFile = + if (OptionalFileEntryRef MainFile = SM.getFileEntryRefForID(SM.getMainFileID())) { MainFileDir = std::string(MainFile->getDir().getName()); if (!llvm::sys::path::is_absolute(MainFileName)) { diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 563d540..ea62d5d 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -3864,8 +3864,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() { // The path to the source file where this module was declared SourceManager &SM = CGM.getContext().getSourceManager(); - Optional<FileEntryRef> mainFile = - SM.getFileEntryRefForID(SM.getMainFileID()); + OptionalFileEntryRef mainFile = SM.getFileEntryRefForID(SM.getMainFileID()); std::string path = (mainFile->getDir().getName() + "/" + mainFile->getName()).str(); module.add(MakeConstantString(path, ".objc_source_file_name")); diff --git a/clang/lib/CodeGen/MacroPPCallbacks.cpp b/clang/lib/CodeGen/MacroPPCallbacks.cpp index 076d299..8589869 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.cpp +++ b/clang/lib/CodeGen/MacroPPCallbacks.cpp @@ -167,7 +167,7 @@ void MacroPPCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason, void MacroPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { diff --git a/clang/lib/CodeGen/MacroPPCallbacks.h b/clang/lib/CodeGen/MacroPPCallbacks.h index 01041b16..5af177d 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.h +++ b/clang/lib/CodeGen/MacroPPCallbacks.h @@ -101,7 +101,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index acb3cb8..a124566 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -426,7 +426,7 @@ static void InitializeFileRemapping(DiagnosticsEngine &Diags, // Remap files in the source manager (with other files). for (const auto &RF : InitOpts.RemappedFiles) { // Find the file that we're mapping to. - Optional<FileEntryRef> ToFile = FileMgr.getOptionalFileRef(RF.second); + OptionalFileEntryRef ToFile = FileMgr.getOptionalFileRef(RF.second); if (!ToFile) { Diags.Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second; continue; @@ -1281,8 +1281,8 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, Instance.getFrontendOpts().AllowPCMWithCompilerErrors; } -static Optional<FileEntryRef> getPublicModuleMap(FileEntryRef File, - FileManager &FileMgr) { +static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File, + FileManager &FileMgr) { StringRef Filename = llvm::sys::path::filename(File.getName()); SmallString<128> PublicFilename(File.getDir().getName()); if (Filename == "module_private.map") @@ -1307,12 +1307,12 @@ static bool compileModule(CompilerInstance &ImportingInstance, ModuleMap &ModMap = ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); bool Result; - if (Optional<FileEntryRef> ModuleMapFile = + if (OptionalFileEntryRef ModuleMapFile = ModMap.getContainingModuleMapFile(Module)) { // Canonicalize compilation to start with the public module map. This is // vital for submodules declarations in the private module maps to be // correctly parsed when depending on a top level module in the public one. - if (Optional<FileEntryRef> PublicMMFile = getPublicModuleMap( + if (OptionalFileEntryRef PublicMMFile = getPublicModuleMap( *ModuleMapFile, ImportingInstance.getFileManager())) ModuleMapFile = PublicMMFile; diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 8d712a2..6a0a718 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -64,7 +64,7 @@ struct DepCollectorPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { if (!File) @@ -75,7 +75,7 @@ struct DepCollectorPPCallbacks : public PPCallbacks { } void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled, - Optional<FileEntryRef> File, + OptionalFileEntryRef File, SrcMgr::CharacteristicKind FileType) override { if (!File) return; diff --git a/clang/lib/Frontend/DependencyGraph.cpp b/clang/lib/Frontend/DependencyGraph.cpp index 4cbdb3d..6aad043 100644 --- a/clang/lib/Frontend/DependencyGraph.cpp +++ b/clang/lib/Frontend/DependencyGraph.cpp @@ -48,7 +48,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -66,21 +66,15 @@ void clang::AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, } void DependencyGraphCallback::InclusionDirective( - SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional<FileEntryRef> File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported, + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!File) return; SourceManager &SM = PP->getSourceManager(); - Optional<FileEntryRef> FromFile = + OptionalFileEntryRef FromFile = SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(HashLoc))); if (!FromFile) return; diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index e97a2dd..6ec6fa0 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -823,7 +823,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, Dir = *DirOrErr; SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 1> CWD; CWD.push_back({nullptr, Dir}); - Optional<FileEntryRef> FE = + OptionalFileEntryRef FE = HS.LookupFile(FileName, SourceLocation(), /*Angled*/ Input.getKind().getHeaderUnitKind() == InputKind::HeaderUnit_System, diff --git a/clang/lib/Frontend/ModuleDependencyCollector.cpp b/clang/lib/Frontend/ModuleDependencyCollector.cpp index 7e19ed3..99a2875d 100644 --- a/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -48,7 +48,7 @@ struct ModuleDependencyPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { if (!File) diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index e3c3466..17f960f 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -97,7 +97,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { // File is None if it wasn't found. diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index d81a11a..ffa85e5 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -146,7 +146,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void Ident(SourceLocation Loc, StringRef str) override; @@ -389,15 +389,9 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, } void PrintPPOutputPPCallbacks::InclusionDirective( - SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional<FileEntryRef> File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported, + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { // In -dI mode, dump #include directives prior to dumping their content or // interpretation. diff --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp index 37178d1..810ec68 100644 --- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -74,7 +74,7 @@ private: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void If(SourceLocation Loc, SourceRange ConditionRange, @@ -182,16 +182,12 @@ void InclusionRewriter::FileSkipped(const FileEntryRef & /*SkippedFile*/, /// FileChanged() or FileSkipped() is called after this (or neither is /// called if this #include results in an error or does not textually include /// anything). -void InclusionRewriter::InclusionDirective(SourceLocation HashLoc, - const Token &/*IncludeTok*/, - StringRef /*FileName*/, - bool /*IsAngled*/, - CharSourceRange /*FilenameRange*/, - Optional<FileEntryRef> /*File*/, - StringRef /*SearchPath*/, - StringRef /*RelativePath*/, - const Module *Imported, - SrcMgr::CharacteristicKind FileType){ +void InclusionRewriter::InclusionDirective( + SourceLocation HashLoc, const Token & /*IncludeTok*/, + StringRef /*FileName*/, bool /*IsAngled*/, + CharSourceRange /*FilenameRange*/, OptionalFileEntryRef /*File*/, + StringRef /*SearchPath*/, StringRef /*RelativePath*/, + const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (Imported) { auto P = ModuleIncludes.insert(std::make_pair(HashLoc, Imported)); (void)P; diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index f67dcee..378f7dd 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -541,7 +541,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, ExpectedLoc = SourceLocation(); } else { // Lookup file via Preprocessor, like a #include. - Optional<FileEntryRef> File = + OptionalFileEntryRef File = PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (!File) { diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 1ce6df4..074c147 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -171,7 +171,7 @@ void HeaderSearch::getHeaderMapFileNames( } std::string HeaderSearch::getCachedModuleFileName(Module *Module) { - Optional<FileEntryRef> ModuleMap = + OptionalFileEntryRef ModuleMap = getModuleMap().getModuleMapFileForUniquing(Module); // The ModuleMap maybe a nullptr, when we load a cached C++ module without // *.modulemap file. In this case, just return an empty string. @@ -212,7 +212,7 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName, } std::string HeaderSearch::getPrebuiltImplicitModuleFileName(Module *Module) { - Optional<FileEntryRef> ModuleMap = + OptionalFileEntryRef ModuleMap = getModuleMap().getModuleMapFileForUniquing(Module); StringRef ModuleName = Module->Name; StringRef ModuleMapPath = ModuleMap->getName(); @@ -415,7 +415,7 @@ StringRef DirectoryLookup::getName() const { return getHeaderMap()->getFileName(); } -Optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule( +OptionalFileEntryRef HeaderSearch::getFileAndSuggestModule( StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir, bool IsSystemHeaderDir, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool OpenFile /*=true*/, @@ -447,7 +447,7 @@ Optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule( /// LookupFile - Lookup the specified file in this search path, returning it /// if it exists or returning null if not. -Optional<FileEntryRef> DirectoryLookup::LookupFile( +OptionalFileEntryRef DirectoryLookup::LookupFile( StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, @@ -532,7 +532,7 @@ Optional<FileEntryRef> DirectoryLookup::LookupFile( /// \param DirName The name of the framework directory. /// \param SubmodulePath Will be populated with the submodule path from the /// returned top-level module to the originally named framework. -static Optional<DirectoryEntryRef> +static OptionalDirectoryEntryRef getTopFrameworkDir(FileManager &FileMgr, StringRef DirName, SmallVectorImpl<std::string> &SubmodulePath) { assert(llvm::sys::path::extension(DirName) == ".framework" && @@ -586,7 +586,7 @@ static bool needModuleLookup(Module *RequestingModule, /// DoFrameworkLookup - Do a lookup of the specified file in the current /// DirectoryLookup, which is a framework directory. -Optional<FileEntryRef> DirectoryLookup::DoFrameworkLookup( +OptionalFileEntryRef DirectoryLookup::DoFrameworkLookup( StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, @@ -855,7 +855,7 @@ diagnoseFrameworkInclude(DiagnosticsEngine &Diags, SourceLocation IncludeLoc, /// for system \#include's or not (i.e. using <> instead of ""). Includers, if /// non-empty, indicates where the \#including file(s) are, in case a relative /// search is needed. Microsoft mode will pass all \#including files. -Optional<FileEntryRef> HeaderSearch::LookupFile( +OptionalFileEntryRef HeaderSearch::LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg, ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers, @@ -898,7 +898,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( // This is the header that MSVC's header search would have found. ModuleMap::KnownHeader MSSuggestedModule; - Optional<FileEntryRef> MSFE; + OptionalFileEntryRef MSFE; // Unless disabled, check to see if the file is in the #includer's // directory. This cannot be based on CurDir, because each includer could be @@ -927,7 +927,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( bool IncluderIsSystemHeader = Includer ? getFileInfo(Includer).DirInfo != SrcMgr::C_User : BuildSystemModule; - if (Optional<FileEntryRef> FE = getFileAndSuggestModule( + if (OptionalFileEntryRef FE = getFileAndSuggestModule( TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader, RequestingModule, SuggestedModule)) { if (!Includer) { @@ -1043,7 +1043,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( bool InUserSpecifiedSystemFramework = false; bool IsInHeaderMap = false; bool IsFrameworkFoundInDir = false; - Optional<FileEntryRef> File = It->LookupFile( + OptionalFileEntryRef File = It->LookupFile( Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule, SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir, IsInHeaderMap, MappedName, OpenFile); @@ -1138,7 +1138,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( ScratchFilename += '/'; ScratchFilename += Filename; - Optional<FileEntryRef> File = LookupFile( + OptionalFileEntryRef File = LookupFile( ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, &CurDir, Includers.front(), SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, /*IsFrameworkFound=*/nullptr); @@ -1175,7 +1175,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( /// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox /// is a subframework within Carbon.framework. If so, return the FileEntry /// for the designated file, otherwise return null. -Optional<FileEntryRef> HeaderSearch::LookupSubframeworkHeader( +OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader( StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule) { @@ -1628,7 +1628,7 @@ bool HeaderSearch::findUsableModuleForFrameworkHeader( if (needModuleLookup(RequestingModule, SuggestedModule)) { // Find the top-level framework based on this framework. SmallVector<std::string, 4> SubmodulePath; - Optional<DirectoryEntryRef> TopFrameworkDir = + OptionalDirectoryEntryRef TopFrameworkDir = ::getTopFrameworkDir(FileMgr, FrameworkName, SubmodulePath); assert(TopFrameworkDir && "Could not find the top-most framework dir"); @@ -1668,7 +1668,7 @@ bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem, StringRef OriginalModuleMapFile) { // Find the directory for the module. For frameworks, that may require going // up from the 'Modules' directory. - Optional<DirectoryEntryRef> Dir; + OptionalDirectoryEntryRef Dir; if (getHeaderSearchOpts().ModuleMapFileHomeIsCwd) { Dir = FileMgr.getOptionalDirectoryRef("."); } else { diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index f5a7f51..633ea26 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -176,14 +176,14 @@ static void appendSubframeworkPaths(Module *Mod, llvm::sys::path::append(Path, "Frameworks", Framework + ".framework"); } -Optional<FileEntryRef> ModuleMap::findHeader( +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; SmallString<128> FullPathName(Directory->getName()); - auto GetFile = [&](StringRef Filename) -> Optional<FileEntryRef> { + auto GetFile = [&](StringRef Filename) -> OptionalFileEntryRef { auto File = expectedToOptional(SourceMgr.getFileManager().getFileRef(Filename)); if (!File || (Header.Size && File->getSize() != *Header.Size) || @@ -192,7 +192,7 @@ Optional<FileEntryRef> ModuleMap::findHeader( return *File; }; - auto GetFrameworkFile = [&]() -> Optional<FileEntryRef> { + auto GetFrameworkFile = [&]() -> OptionalFileEntryRef { unsigned FullPathLength = FullPathName.size(); appendSubframeworkPaths(M, RelativePathName); unsigned RelativePathLength = RelativePathName.size(); @@ -256,7 +256,7 @@ void ModuleMap::resolveHeader(Module *Mod, const Module::UnresolvedHeaderDirective &Header, bool &NeedsFramework) { SmallString<128> RelativePathName; - if (Optional<FileEntryRef> File = + if (OptionalFileEntryRef File = findHeader(Mod, Header, RelativePathName, NeedsFramework)) { if (Header.IsUmbrella) { const DirectoryEntry *UmbrellaDir = &File->getDir().getDirEntry(); @@ -1258,7 +1258,7 @@ void ModuleMap::addHeader(Module *Mod, Module::Header Header, Cb->moduleMapAddHeader(Header.Entry->getName()); } -Optional<FileEntryRef> +OptionalFileEntryRef ModuleMap::getContainingModuleMapFile(const Module *Module) const { if (Module->DefinitionLoc.isInvalid()) return std::nullopt; @@ -1267,7 +1267,7 @@ ModuleMap::getContainingModuleMapFile(const Module *Module) const { SourceMgr.getFileID(Module->DefinitionLoc)); } -Optional<FileEntryRef> +OptionalFileEntryRef ModuleMap::getModuleMapFileForUniquing(const Module *M) const { if (M->IsInferred) { assert(InferredModuleAllowedBy.count(M) && "missing inferred module map"); diff --git a/clang/lib/Lex/PPCallbacks.cpp b/clang/lib/Lex/PPCallbacks.cpp index b618071..f2b60a7 100644 --- a/clang/lib/Lex/PPCallbacks.cpp +++ b/clang/lib/Lex/PPCallbacks.cpp @@ -15,16 +15,15 @@ using namespace clang; PPCallbacks::~PPCallbacks() = default; void PPCallbacks::HasInclude(SourceLocation Loc, StringRef FileName, - bool IsAngled, Optional<FileEntryRef> File, + bool IsAngled, OptionalFileEntryRef File, SrcMgr::CharacteristicKind FileType) {} // Out of line key method. PPChainedCallbacks::~PPChainedCallbacks() = default; void PPChainedCallbacks::HasInclude(SourceLocation Loc, StringRef FileName, - bool IsAngled, Optional<FileEntryRef> File, + bool IsAngled, OptionalFileEntryRef File, SrcMgr::CharacteristicKind FileType) { First->HasInclude(Loc, FileName, IsAngled, File, FileType); Second->HasInclude(Loc, FileName, IsAngled, File, FileType); } - diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 5264c00..8a38fb4 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -947,7 +947,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc, return nullptr; } -Optional<FileEntryRef> Preprocessor::LookupFile( +OptionalFileEntryRef Preprocessor::LookupFile( SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDirArg, SmallVectorImpl<char> *SearchPath, @@ -1012,7 +1012,7 @@ Optional<FileEntryRef> Preprocessor::LookupFile( // the include path until we find that file or run out of files. ConstSearchDirIterator TmpCurDir = CurDir; ConstSearchDirIterator TmpFromDir = nullptr; - while (Optional<FileEntryRef> FE = HeaderInfo.LookupFile( + while (OptionalFileEntryRef FE = HeaderInfo.LookupFile( Filename, FilenameLoc, isAngled, TmpFromDir, &TmpCurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, /*IsMapped=*/nullptr, @@ -1030,7 +1030,7 @@ Optional<FileEntryRef> Preprocessor::LookupFile( } // Do a standard file entry lookup. - Optional<FileEntryRef> FE = HeaderInfo.LookupFile( + OptionalFileEntryRef FE = HeaderInfo.LookupFile( Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures); @@ -1048,7 +1048,7 @@ Optional<FileEntryRef> Preprocessor::LookupFile( // headers on the #include stack and pass them to HeaderInfo. if (IsFileLexer()) { if ((CurFileEnt = CurPPLexer->getFileEntry())) { - if (Optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader( + if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader( Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule, SuggestedModule)) { if (SuggestedModule && !LangOpts.AsmPreprocessor) @@ -1063,7 +1063,7 @@ Optional<FileEntryRef> Preprocessor::LookupFile( for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) { if (IsFileLexer(ISEntry)) { if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) { - if (Optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader( + if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader( Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule, SuggestedModule)) { if (SuggestedModule && !LangOpts.AsmPreprocessor) @@ -2003,7 +2003,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, } } -Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( +OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport( ConstSearchDirIterator *CurDir, StringRef &Filename, SourceLocation FilenameLoc, CharSourceRange FilenameRange, const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl, @@ -2011,9 +2011,8 @@ Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( const FileEntry *LookupFromFile, StringRef &LookupFilename, SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath, ModuleMap::KnownHeader &SuggestedModule, bool isAngled) { - Optional<FileEntryRef> File = LookupFile( - FilenameLoc, LookupFilename, - isAngled, LookupFrom, LookupFromFile, CurDir, + OptionalFileEntryRef File = LookupFile( + FilenameLoc, LookupFilename, isAngled, LookupFrom, LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, &IsFrameworkFound); if (File) @@ -2026,9 +2025,8 @@ Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( // brackets, we can attempt a lookup as though it were a quoted path to // provide the user with a possible fixit. if (isAngled) { - Optional<FileEntryRef> File = LookupFile( - FilenameLoc, LookupFilename, - false, LookupFrom, LookupFromFile, CurDir, + OptionalFileEntryRef File = LookupFile( + FilenameLoc, LookupFilename, false, LookupFrom, LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, /*IsFrameworkFound=*/nullptr); @@ -2057,9 +2055,9 @@ Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( StringRef TypoCorrectionName = CorrectTypoFilename(Filename); StringRef TypoCorrectionLookupName = CorrectTypoFilename(LookupFilename); - Optional<FileEntryRef> File = LookupFile( - FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom, LookupFromFile, - CurDir, Callbacks ? &SearchPath : nullptr, + OptionalFileEntryRef File = LookupFile( + FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom, + LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, /*IsFrameworkFound=*/nullptr); if (File) { @@ -2182,7 +2180,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( BackslashStyle = llvm::sys::path::Style::windows; } - Optional<FileEntryRef> File = LookupHeaderIncludeOrImport( + OptionalFileEntryRef File = LookupHeaderIncludeOrImport( &CurDir, Filename, FilenameLoc, FilenameRange, FilenameTok, IsFrameworkFound, IsImportDecl, IsMapped, LookupFrom, LookupFromFile, LookupFilename, RelativePath, SearchPath, SuggestedModule, isAngled); diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index 36d3aa5..570728e 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -94,7 +94,7 @@ bool Preprocessor::EnterSourceFile(FileID FID, ConstSearchDirIterator CurDir, Lexer *TheLexer = new Lexer(FID, *InputFile, *this, IsFirstIncludeOfFile); if (getPreprocessorOpts().DependencyDirectivesForFile && FID != PredefinesFileID) { - if (Optional<FileEntryRef> File = SourceMgr.getFileEntryRefForID(FID)) { + if (OptionalFileEntryRef File = SourceMgr.getFileEntryRefForID(FID)) { if (Optional<ArrayRef<dependency_directives_scan::Directive>> DepDirectives = getPreprocessorOpts().DependencyDirectivesForFile(*File)) { diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index c33c9d1..9262d1c 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1249,7 +1249,7 @@ static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II, return false; // Search include directories. - Optional<FileEntryRef> File = + OptionalFileEntryRef File = PP.LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 01e0dbe..fc86f7d 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -527,7 +527,7 @@ void Preprocessor::HandlePragmaDependency(Token &DependencyTok) { return; // Search include directories for this file. - Optional<FileEntryRef> File = + OptionalFileEntryRef File = LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (!File) { diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index 35f9e4d..1b13d09 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -42,7 +42,7 @@ ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() = InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, - Optional<FileEntryRef> File, + OptionalFileEntryRef File, SourceRange Range) : PreprocessingDirective(InclusionDirectiveKind, Range), InQuotes(InQuotes), Kind(Kind), ImportedModule(ImportedModule), File(File) { @@ -475,15 +475,9 @@ void PreprocessingRecord::MacroUndefined(const Token &Id, } void PreprocessingRecord::InclusionDirective( - SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional<FileEntryRef> File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported, + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { InclusionDirective::InclusionKind Kind = InclusionDirective::Include; diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 281683b..5f54c3b 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -580,7 +580,7 @@ void Preprocessor::EnterMainSourceFile() { if (!PPOpts->PCHThroughHeader.empty()) { // Lookup and save the FileID for the through header. If it isn't found // in the search path, it's a fatal error. - Optional<FileEntryRef> File = LookupFile( + OptionalFileEntryRef File = LookupFile( SourceLocation(), PPOpts->PCHThroughHeader, /*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr, /*CurDir=*/nullptr, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr, diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index bb045760..0adcc68 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -320,7 +320,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, Diag(Path[0].second, diag::err_module_redefinition) << ModuleName; if (M->DefinitionLoc.isValid()) Diag(M->DefinitionLoc, diag::note_prev_module_definition); - else if (Optional<FileEntryRef> FE = M->getASTFile()) + else if (OptionalFileEntryRef FE = M->getASTFile()) Diag(M->DefinitionLoc, diag::note_prev_module_definition_from_ast_file) << FE->getName(); Mod = M; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 63c525a..35632d9 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1520,7 +1520,7 @@ bool ASTReader::ReadSLocEntry(int ID) { // we will also try to fail gracefully by setting up the SLocEntry. unsigned InputID = Record[4]; InputFile IF = getInputFile(*F, InputID); - Optional<FileEntryRef> File = IF.getFile(); + OptionalFileEntryRef File = IF.getFile(); bool OverriddenBuffer = IF.isOverridden(); // Note that we only check if a File was returned. If it was out-of-date @@ -2361,8 +2361,8 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { StringRef Filename = FI.Filename; uint64_t StoredContentHash = FI.ContentHash; - OptionalFileEntryRefDegradesToFileEntryPtr File = - expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)); + OptionalFileEntryRefDegradesToFileEntryPtr File = OptionalFileEntryRef( + expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false))); // For an overridden file, create a virtual file with the stored // size/timestamp. @@ -3964,7 +3964,7 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName, F.ImportLoc); auto &Map = PP.getHeaderSearchInfo().getModuleMap(); - Optional<FileEntryRef> ModMap = + OptionalFileEntryRef ModMap = M ? Map.getModuleMapFileForUniquing(M) : std::nullopt; // Don't emit module relocation error if we have -fno-validate-pch if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation & @@ -6126,7 +6126,7 @@ PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { case PPD_INCLUSION_DIRECTIVE: { const char *FullFileNameStart = Blob.data() + Record[0]; StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); - Optional<FileEntryRef> File; + OptionalFileEntryRef File; if (!FullFileName.empty()) File = PP.getFileManager().getOptionalFileRef(FullFileName); diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index ae4ea61..81dd546 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -444,14 +444,14 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor, bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize, time_t ExpectedModTime, - Optional<FileEntryRef> &File) { + OptionalFileEntryRef &File) { File = std::nullopt; if (FileName == "-") return false; // Open the file immediately to ensure there is no race between stat'ing and // opening the file. - Optional<FileEntryRef> FileOrErr = + OptionalFileEntryRef FileOrErr = expectedToOptional(FileMgr.getFileRef(FileName, /*OpenFile=*/true, /*CacheFailure=*/false)); if (!FileOrErr) diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index e599681..61191fc 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -237,7 +237,7 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) { if (llvm::any_of(CI.getFrontendOpts().Inputs, needsModules)) { Preprocessor &PP = ScanInstance.getPreprocessor(); if (Module *CurrentModule = PP.getCurrentModuleImplementation()) - if (Optional<FileEntryRef> CurrentModuleMap = + if (OptionalFileEntryRef CurrentModuleMap = PP.getHeaderSearchInfo() .getModuleMap() .getModuleMapFileForUniquing(CurrentModule)) @@ -334,7 +334,7 @@ void ModuleDepCollectorPP::FileChanged(SourceLocation Loc, void ModuleDepCollectorPP::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!File && !Imported) { @@ -419,7 +419,7 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) { ModuleMap &ModMapInfo = MDC.ScanInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); - Optional<FileEntryRef> ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M); + OptionalFileEntryRef ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M); if (ModuleMap) { SmallString<128> Path = ModuleMap->getNameAsRequested(); |