From 854c10f8d185286d941307e1033eb492e085c203 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 20 Dec 2022 00:15:11 +0100 Subject: [PATCH] [Clang] Prepare for llvm::Optional becoming std::optional. The needed tweaks are mostly trivial, the one nasty bit is Clang's usage of OptionalStorage. To keep this working old Optional stays around as clang::CustomizableOptional, with the default Storage removed. Optional is replaced with a typedef. I tested this with GCC 7.5, the oldest supported GCC I had around. Differential Revision: https://reviews.llvm.org/D140332 --- clang-tools-extra/clang-move/Move.cpp | 2 +- .../clang-tidy/ExpandModularHeadersPPCallbacks.cpp | 4 +- .../clang-tidy/ExpandModularHeadersPPCallbacks.h | 4 +- .../altera/KernelNameRestrictionCheck.cpp | 6 +- .../clang-tidy/bugprone/SuspiciousIncludeCheck.cpp | 6 +- .../clang-tidy/llvm/IncludeOrderCheck.cpp | 4 +- .../llvmlibc/RestrictSystemLibcHeadersCheck.cpp | 4 +- .../modernize/DeprecatedHeadersCheck.cpp | 4 +- .../clang-tidy/modernize/MacroToEnumCheck.cpp | 2 +- .../portability/RestrictSystemIncludesCheck.cpp | 2 +- .../portability/RestrictSystemIncludesCheck.h | 2 +- .../readability/DuplicateIncludeCheck.cpp | 4 +- .../clang-tidy/utils/IncludeInserter.cpp | 2 +- clang-tools-extra/clangd/ConfigCompile.cpp | 2 +- clang-tools-extra/clangd/Headers.cpp | 2 +- clang-tools-extra/clangd/ParsedAST.cpp | 4 +- clang-tools-extra/clangd/index/IndexAction.cpp | 5 +- clang-tools-extra/clangd/unittests/HoverTests.cpp | 24 +- .../clangd/unittests/ParsedASTTests.cpp | 5 +- clang-tools-extra/include-cleaner/lib/Record.cpp | 8 +- clang-tools-extra/modularize/CoverageChecker.cpp | 2 +- .../modularize/PreprocessorTracker.cpp | 9 +- clang-tools-extra/pp-trace/PPCallbacksTracker.cpp | 4 +- clang-tools-extra/pp-trace/PPCallbacksTracker.h | 5 +- clang/include/clang/Basic/CustomizableOptional.h | 280 +++++++++++++++++++++ clang/include/clang/Basic/Diagnostic.h | 6 + clang/include/clang/Basic/DirectoryEntry.h | 46 ++-- clang/include/clang/Basic/FileEntry.h | 67 +++-- clang/include/clang/Basic/FileManager.h | 14 +- clang/include/clang/Basic/LLVM.h | 2 +- clang/include/clang/Basic/Module.h | 4 +- clang/include/clang/Basic/SourceManager.h | 4 +- clang/include/clang/Lex/DirectoryLookup.h | 12 +- clang/include/clang/Lex/HeaderSearch.h | 8 +- clang/include/clang/Lex/ModuleMap.h | 6 +- clang/include/clang/Lex/PPCallbacks.h | 20 +- clang/include/clang/Lex/PreprocessingRecord.h | 8 +- clang/include/clang/Lex/Preprocessor.h | 4 +- clang/include/clang/Serialization/ModuleManager.h | 2 +- clang/include/clang/Tooling/Core/Replacement.h | 3 + .../DependencyScanning/ModuleDepCollector.h | 2 +- .../clang/Tooling/Inclusions/StandardLibrary.h | 1 + clang/lib/ARCMigrate/ObjCMT.cpp | 7 +- clang/lib/Basic/FileManager.cpp | 2 +- clang/lib/Basic/SourceManager.cpp | 4 +- clang/lib/Basic/TargetInfo.cpp | 2 +- clang/lib/CodeGen/CGDebugInfo.cpp | 2 +- clang/lib/CodeGen/CGObjCGNU.cpp | 3 +- clang/lib/CodeGen/MacroPPCallbacks.cpp | 2 +- clang/lib/CodeGen/MacroPPCallbacks.h | 2 +- clang/lib/Frontend/CompilerInstance.cpp | 10 +- clang/lib/Frontend/DependencyFile.cpp | 4 +- clang/lib/Frontend/DependencyGraph.cpp | 16 +- clang/lib/Frontend/FrontendAction.cpp | 2 +- clang/lib/Frontend/ModuleDependencyCollector.cpp | 2 +- clang/lib/Frontend/PrecompiledPreamble.cpp | 2 +- clang/lib/Frontend/PrintPreprocessedOutput.cpp | 14 +- clang/lib/Frontend/Rewrite/InclusionRewriter.cpp | 18 +- clang/lib/Frontend/VerifyDiagnosticConsumer.cpp | 2 +- clang/lib/Lex/HeaderSearch.cpp | 28 +-- clang/lib/Lex/ModuleMap.cpp | 12 +- clang/lib/Lex/PPCallbacks.cpp | 5 +- clang/lib/Lex/PPDirectives.cpp | 30 ++- clang/lib/Lex/PPLexerChange.cpp | 2 +- clang/lib/Lex/PPMacroExpansion.cpp | 2 +- clang/lib/Lex/Pragma.cpp | 2 +- clang/lib/Lex/PreprocessingRecord.cpp | 14 +- clang/lib/Lex/Preprocessor.cpp | 2 +- clang/lib/Sema/SemaModule.cpp | 2 +- clang/lib/Serialization/ASTReader.cpp | 10 +- clang/lib/Serialization/ModuleManager.cpp | 4 +- .../DependencyScanning/ModuleDepCollector.cpp | 6 +- clang/tools/libclang/CIndex.cpp | 2 +- clang/tools/libclang/CXIndexDataConsumer.cpp | 8 +- clang/tools/libclang/CXIndexDataConsumer.h | 2 +- clang/tools/libclang/Indexing.cpp | 2 +- .../Analysis/FlowSensitive/TransferBranchTest.cpp | 4 +- clang/unittests/Basic/FileManagerTest.cpp | 5 +- clang/unittests/Lex/PPCallbacksTest.cpp | 4 +- clang/unittests/Lex/PPDependencyDirectivesTest.cpp | 2 +- 80 files changed, 541 insertions(+), 306 deletions(-) create mode 100644 clang/include/clang/Basic/CustomizableOptional.h diff --git a/clang-tools-extra/clang-move/Move.cpp b/clang-tools-extra/clang-move/Move.cpp index 9e44fe1..e237a8e 100644 --- a/clang-tools-extra/clang-move/Move.cpp +++ b/clang-tools-extra/clang-move/Move.cpp @@ -131,7 +131,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token & /*IncludeTok*/, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional /*File*/, StringRef SearchPath, + OptionalFileEntryRef /*File*/, StringRef SearchPath, StringRef /*RelativePath*/, const Module * /*Imported*/, SrcMgr::CharacteristicKind /*FileType*/) override { diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index f88e24c..9df2641 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -162,7 +162,7 @@ void ExpandModularHeadersPPCallbacks::FileChanged( void ExpandModularHeadersPPCallbacks::InclusionDirective( SourceLocation DirectiveLoc, const Token &IncludeToken, StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange, - Optional IncludedFile, StringRef SearchPath, + OptionalFileEntryRef IncludedFile, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (Imported) { @@ -224,7 +224,7 @@ void ExpandModularHeadersPPCallbacks::PragmaDiagnostic(SourceLocation Loc, parseToLocation(Loc); } void ExpandModularHeadersPPCallbacks::HasInclude(SourceLocation Loc, StringRef, - bool, Optional, + bool, OptionalFileEntryRef, SrcMgr::CharacteristicKind) { parseToLocation(Loc); } diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h index 29f0605..7585fd3 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h @@ -69,7 +69,7 @@ private: void InclusionDirective(SourceLocation DirectiveLoc, const Token &IncludeToken, StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange, - Optional IncludedFile, + OptionalFileEntryRef IncludedFile, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -91,7 +91,7 @@ private: void PragmaDiagnosticPop(SourceLocation Loc, StringRef) override; void PragmaDiagnostic(SourceLocation Loc, StringRef, diag::Severity, StringRef) override; - void HasInclude(SourceLocation Loc, StringRef, bool, Optional , + void HasInclude(SourceLocation Loc, StringRef, bool, OptionalFileEntryRef, SrcMgr::CharacteristicKind) override; void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *, SourceLocation StateLoc, unsigned) override; diff --git a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp index c51fd53..ddf09ca 100644 --- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp @@ -30,7 +30,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FileNameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -62,8 +62,8 @@ void KernelNameRestrictionCheck::registerPPCallbacks(const SourceManager &SM, void KernelNameRestrictionPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &, StringRef FileName, bool, - CharSourceRange, Optional, StringRef, StringRef, - const Module *, SrcMgr::CharacteristicKind) { + CharSourceRange, OptionalFileEntryRef, StringRef, StringRef, const Module *, + SrcMgr::CharacteristicKind) { IncludeDirective ID = {HashLoc, FileName}; IncludeDirectives.push_back(std::move(ID)); } diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp index b8fbc6e..cd9aa00 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp @@ -25,7 +25,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -72,7 +72,7 @@ void SuspiciousIncludeCheck::registerPPCallbacks( void SuspiciousIncludePPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import) @@ -93,7 +93,7 @@ void SuspiciousIncludePPCallbacks::InclusionDirective( llvm::sys::path::replace_extension(GuessedFileName, (HFE.size() ? "." : "") + HFE); - Optional File = + OptionalFileEntryRef File = PP->LookupFile(DiagLoc, GuessedFileName, IsAngled, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (File) { diff --git a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp index f701bd1..5cf40644 100644 --- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp @@ -28,7 +28,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; @@ -82,7 +82,7 @@ static int getPriority(StringRef Filename, bool IsAngled, bool IsMainModule) { void IncludeOrderPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { // We recognize the first include as a special main module header and want diff --git a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp index 62379f1..4bbbc57 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp @@ -34,7 +34,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -46,7 +46,7 @@ private: void RestrictedIncludesPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { // Compiler provided headers are allowed (e.g stddef.h). diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp index 64e70ad..2498ec9 100644 --- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp @@ -33,7 +33,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -179,7 +179,7 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks( void IncludeModernizePPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { diff --git a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp index 1c196a9..a3f5f2d 100644 --- a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp @@ -119,7 +119,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { clearCurrentEnum(HashLoc); diff --git a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp index 7faf7cc..3509cd4 100644 --- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp @@ -22,7 +22,7 @@ namespace portability { void RestrictedIncludesPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!Check.contains(FileName) && SrcMgr::isSystem(FileType)) { diff --git a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h index 2919b06..81489bf 100644 --- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h @@ -51,7 +51,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; diff --git a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp index 22a4e4e..8c69417 100644 --- a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp @@ -48,7 +48,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -77,7 +77,7 @@ void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc, void DuplicateIncludeCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (llvm::is_contained(Files.back(), FileName)) { diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp index 08bbe9d..f4ca2d9 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp @@ -24,7 +24,7 @@ public: void InclusionDirective(SourceLocation HashLocation, const Token &IncludeToken, StringRef FileNameRef, bool IsAngled, CharSourceRange FileNameRange, - Optional /*IncludedFile*/, + OptionalFileEntryRef /*IncludedFile*/, StringRef /*SearchPath*/, StringRef /*RelativePath*/, const Module * /*ImportedModule*/, SrcMgr::CharacteristicKind /*FileType*/) override { diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp index 8424340..2291e5f 100644 --- a/clang-tools-extra/clangd/ConfigCompile.cpp +++ b/clang-tools-extra/clangd/ConfigCompile.cpp @@ -112,7 +112,7 @@ struct FragmentCompiler { diag(Error, "Invalid regex " + Anchored + ": " + RegexError, Text.Range); return std::nullopt; } - return Result; + return std::move(Result); } std::optional makeAbsolute(Located Path, diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp index 4314ef1..b22589a 100644 --- a/clang-tools-extra/clangd/Headers.cpp +++ b/clang-tools-extra/clangd/Headers.cpp @@ -35,7 +35,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange /*FilenameRange*/, - Optional File, + OptionalFileEntryRef File, llvm::StringRef /*SearchPath*/, llvm::StringRef /*RelativePath*/, const clang::Module * /*Imported*/, diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp index 4e99365..aa84ce3 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -171,7 +171,7 @@ private: void replay() { for (const auto &Inc : Includes) { - llvm::Optional File; + OptionalFileEntryRef File; if (Inc.Resolved != "") File = expectedToOptional(SM.getFileManager().getFileRef(Inc.Resolved)); @@ -679,7 +679,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs, make_move_iterator(UnusedHeadersDiags.begin()), make_move_iterator(UnusedHeadersDiags.end())); } - return Result; + return std::move(Result); } ParsedAST::ParsedAST(ParsedAST &&Other) = default; diff --git a/clang-tools-extra/clangd/index/IndexAction.cpp b/clang-tools-extra/clangd/index/IndexAction.cpp index aaba2c9..a5f8f6b 100644 --- a/clang-tools-extra/clangd/index/IndexAction.cpp +++ b/clang-tools-extra/clangd/index/IndexAction.cpp @@ -28,7 +28,7 @@ namespace clang { namespace clangd { namespace { -llvm::Optional toURI(Optional File) { +llvm::Optional toURI(OptionalFileEntryRef File) { if (!File) return std::nullopt; auto AbsolutePath = File->getFileEntry().tryGetRealPathName(); @@ -85,8 +85,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, - llvm::StringRef SearchPath, + OptionalFileEntryRef File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { auto IncludeURI = toURI(File); diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp index 4051478..3493813 100644 --- a/clang-tools-extra/clangd/unittests/HoverTests.cpp +++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp @@ -898,9 +898,7 @@ class Foo final {})cpp"; HI.CalleeArgInfo.emplace(); HI.CalleeArgInfo->Name = "arg_b"; HI.CalleeArgInfo->Type = "int &"; - HI.CallPassType.emplace(); - HI.CallPassType->PassBy = PassMode::Ref; - HI.CallPassType->Converted = false; + HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false}; }}, {// Extra info for method call. R"cpp( @@ -926,9 +924,7 @@ class Foo final {})cpp"; HI.CalleeArgInfo->Name = "arg_a"; HI.CalleeArgInfo->Type = "int"; HI.CalleeArgInfo->Default = "3"; - HI.CallPassType.emplace(); - HI.CallPassType->PassBy = PassMode::Value; - HI.CallPassType->Converted = false; + HI.CallPassType = HoverInfo::PassType{PassMode::Value, false}; }}, {// Dont crash on invalid decl R"cpp( @@ -3037,9 +3033,7 @@ private: union foo {})", HI.CalleeArgInfo->Name = "arg_a"; HI.CalleeArgInfo->Type = "int"; HI.CalleeArgInfo->Default = "7"; - HI.CallPassType.emplace(); - HI.CallPassType->PassBy = PassMode::Value; - HI.CallPassType->Converted = false; + HI.CallPassType = HoverInfo::PassType{PassMode::Value, false}; }, R"(variable foo @@ -3062,9 +3056,7 @@ int foo = 3)", HI.CalleeArgInfo->Name = "arg_a"; HI.CalleeArgInfo->Type = "int"; HI.CalleeArgInfo->Default = "7"; - HI.CallPassType.emplace(); - HI.CallPassType->PassBy = PassMode::Ref; - HI.CallPassType->Converted = false; + HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false}; }, R"(variable foo @@ -3087,9 +3079,7 @@ int foo = 3)", HI.CalleeArgInfo->Name = "arg_a"; HI.CalleeArgInfo->Type = {"alias_int", "int"}; HI.CalleeArgInfo->Default = "7"; - HI.CallPassType.emplace(); - HI.CallPassType->PassBy = PassMode::Value; - HI.CallPassType->Converted = true; + HI.CallPassType = HoverInfo::PassType{PassMode::Value, true}; }, R"(variable foo @@ -3127,9 +3117,7 @@ int foo = 3)", HI.CalleeArgInfo->Name = "arg_a"; HI.CalleeArgInfo->Type = "int"; HI.CalleeArgInfo->Default = "7"; - HI.CallPassType.emplace(); - HI.CallPassType->PassBy = PassMode::ConstRef; - HI.CallPassType->Converted = true; + HI.CallPassType = HoverInfo::PassType{PassMode::ConstRef, true}; }, R"(variable foo diff --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp index 8167413..5792359 100644 --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp @@ -380,9 +380,8 @@ TEST(ParsedASTTest, ReplayPreambleForTidyCheckers) { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, - CharSourceRange FilenameRange, - Optional, StringRef, StringRef, - const clang::Module *, + CharSourceRange FilenameRange, OptionalFileEntryRef, + StringRef, StringRef, const clang::Module *, SrcMgr::CharacteristicKind) override { Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled, FilenameRange); diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp b/clang-tools-extra/include-cleaner/lib/Record.cpp index e16be12..ab5a241 100644 --- a/clang-tools-extra/include-cleaner/lib/Record.cpp +++ b/clang-tools-extra/include-cleaner/lib/Record.cpp @@ -35,9 +35,9 @@ public: void InclusionDirective(SourceLocation Hash, const Token &IncludeTok, StringRef SpelledFilename, bool IsAngled, CharSourceRange FilenameRange, - llvm::Optional File, - StringRef SearchPath, StringRef RelativePath, - const Module *, SrcMgr::CharacteristicKind) override { + OptionalFileEntryRef File, StringRef SearchPath, + StringRef RelativePath, const Module *, + SrcMgr::CharacteristicKind) override { if (!Active) return; @@ -180,7 +180,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange /*FilenameRange*/, - Optional File, + OptionalFileEntryRef File, llvm::StringRef /*SearchPath*/, llvm::StringRef /*RelativePath*/, const clang::Module * /*Imported*/, diff --git a/clang-tools-extra/modularize/CoverageChecker.cpp b/clang-tools-extra/modularize/CoverageChecker.cpp index 610fb59..80e5749 100644 --- a/clang-tools-extra/modularize/CoverageChecker.cpp +++ b/clang-tools-extra/modularize/CoverageChecker.cpp @@ -89,7 +89,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { Checker.collectUmbrellaHeaderHeader(File->getName()); diff --git a/clang-tools-extra/modularize/PreprocessorTracker.cpp b/clang-tools-extra/modularize/PreprocessorTracker.cpp index 171a938..b80bff9 100644 --- a/clang-tools-extra/modularize/PreprocessorTracker.cpp +++ b/clang-tools-extra/modularize/PreprocessorTracker.cpp @@ -734,7 +734,7 @@ public: const clang::Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, - llvm::Optional File, + clang::OptionalFileEntryRef File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const clang::Module *Imported, @@ -1277,10 +1277,9 @@ PreprocessorTracker *PreprocessorTracker::create( void PreprocessorCallbacks::InclusionDirective( clang::SourceLocation HashLoc, const clang::Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, - clang::CharSourceRange FilenameRange, - llvm::Optional File, llvm::StringRef SearchPath, - llvm::StringRef RelativePath, const clang::Module *Imported, - clang::SrcMgr::CharacteristicKind FileType) { + clang::CharSourceRange FilenameRange, clang::OptionalFileEntryRef File, + llvm::StringRef SearchPath, llvm::StringRef RelativePath, + const clang::Module *Imported, clang::SrcMgr::CharacteristicKind FileType) { int DirectiveLine, DirectiveColumn; std::string HeaderPath = getSourceLocationFile(PP, HashLoc); getSourceLocationLineAndColumn(PP, HashLoc, DirectiveLine, DirectiveColumn); diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp index c143455..a402c54 100644 --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp @@ -133,7 +133,7 @@ void PPCallbacksTracker::FileSkipped(const FileEntryRef &SkippedFile, // of whether the inclusion will actually result in an inclusion. void PPCallbacksTracker::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, + bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { beginCallback("InclusionDirective"); @@ -486,7 +486,7 @@ void PPCallbacksTracker::appendArgument(const char *Name, FileID Value) { // Append a FileEntry argument to the top trace item. void PPCallbacksTracker::appendArgument(const char *Name, - Optional Value) { + OptionalFileEntryRef Value) { if (!Value) { appendArgument(Name, "(null)"); return; diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.h b/clang-tools-extra/pp-trace/PPCallbacksTracker.h index 8640146..c195a72 100644 --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.h +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.h @@ -94,8 +94,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, - llvm::StringRef SearchPath, + OptionalFileEntryRef File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, @@ -179,7 +178,7 @@ public: void appendArgument(const char *Name, FileID Value); /// Append a FileEntryRef argument to the top trace item. - void appendArgument(const char *Name, Optional Value); + void appendArgument(const char *Name, OptionalFileEntryRef Value); void appendArgument(const char *Name, FileEntryRef Value); /// Append a SourceLocation argument to the top trace item. diff --git a/clang/include/clang/Basic/CustomizableOptional.h b/clang/include/clang/Basic/CustomizableOptional.h new file mode 100644 index 0000000..52e761d --- /dev/null +++ b/clang/include/clang/Basic/CustomizableOptional.h @@ -0,0 +1,280 @@ +//===- CustomizableOptional.h - Optional with custom storage ----*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H +#define CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H + +#include "llvm/ADT/Hashing.h" +#include "llvm/ADT/Optional.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/type_traits.h" +#include +#include +#include + +namespace clang { + +namespace optional_detail { +template class OptionalStorage; +} // namespace optional_detail + +// Optional type which internal storage can be specialized by providing +// OptionalStorage. The interface follows std::optional. +template class CustomizableOptional { + optional_detail::OptionalStorage Storage; + +public: + using value_type = T; + + constexpr CustomizableOptional() = default; + constexpr CustomizableOptional(std::nullopt_t) {} + + constexpr CustomizableOptional(const T &y) : Storage(std::in_place, y) {} + constexpr CustomizableOptional(const CustomizableOptional &O) = default; + + constexpr CustomizableOptional(T &&y) + : Storage(std::in_place, std::move(y)) {} + constexpr CustomizableOptional(CustomizableOptional &&O) = default; + + template + constexpr CustomizableOptional(std::in_place_t, ArgTypes &&...Args) + : Storage(std::in_place, std::forward(Args)...) {} + + // Allow conversion from Optional. + constexpr CustomizableOptional(const llvm::Optional &y) + : CustomizableOptional(y ? *y : CustomizableOptional()) {} + constexpr CustomizableOptional(llvm::Optional &&y) + : CustomizableOptional(y ? std::move(*y) : CustomizableOptional()) {} + + CustomizableOptional &operator=(T &&y) { + Storage = std::move(y); + return *this; + } + CustomizableOptional &operator=(CustomizableOptional &&O) = default; + + /// Create a new object by constructing it in place with the given arguments. + template void emplace(ArgTypes &&...Args) { + Storage.emplace(std::forward(Args)...); + } + + CustomizableOptional &operator=(const T &y) { + Storage = y; + return *this; + } + CustomizableOptional &operator=(const CustomizableOptional &O) = default; + + void reset() { Storage.reset(); } + + LLVM_DEPRECATED("Use &*X instead.", "&*X") + constexpr const T *getPointer() const { return &Storage.value(); } + LLVM_DEPRECATED("Use &*X instead.", "&*X") + T *getPointer() { return &Storage.value(); } + LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X") + constexpr const T &value() const & { return Storage.value(); } + LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X") + T &value() & { return Storage.value(); } + + constexpr explicit operator bool() const { return has_value(); } + constexpr bool has_value() const { return Storage.has_value(); } + constexpr const T *operator->() const { return &Storage.value(); } + T *operator->() { return &Storage.value(); } + constexpr const T &operator*() const & { return Storage.value(); } + T &operator*() & { return Storage.value(); } + + template constexpr T value_or(U &&alt) const & { + return has_value() ? operator*() : std::forward(alt); + } + + LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X") + T &&value() && { return std::move(Storage.value()); } + T &&operator*() && { return std::move(Storage.value()); } + + template T value_or(U &&alt) && { + return has_value() ? std::move(operator*()) : std::forward(alt); + } + + // Allow conversion to Optional. + explicit operator llvm::Optional &() const & { + return *this ? **this : llvm::Optional(); + } + explicit operator llvm::Optional &&() const && { + return *this ? std::move(**this) : llvm::Optional(); + } +}; + +template +CustomizableOptional(const T &) -> CustomizableOptional; + +template +llvm::hash_code hash_value(const CustomizableOptional &O) { + return O ? llvm::hash_combine(true, *O) : llvm::hash_value(false); +} + +template +constexpr bool operator==(const CustomizableOptional &X, + const CustomizableOptional &Y) { + if (X && Y) + return *X == *Y; + return X.has_value() == Y.has_value(); +} + +template +constexpr bool operator!=(const CustomizableOptional &X, + const CustomizableOptional &Y) { + return !(X == Y); +} + +template +constexpr bool operator<(const CustomizableOptional &X, + const CustomizableOptional &Y) { + if (X && Y) + return *X < *Y; + return X.has_value() < Y.has_value(); +} + +template +constexpr bool operator<=(const CustomizableOptional &X, + const CustomizableOptional &Y) { + return !(Y < X); +} + +template +constexpr bool operator>(const CustomizableOptional &X, + const CustomizableOptional &Y) { + return Y < X; +} + +template +constexpr bool operator>=(const CustomizableOptional &X, + const CustomizableOptional &Y) { + return !(X < Y); +} + +template +constexpr bool operator==(const CustomizableOptional &X, std::nullopt_t) { + return !X; +} + +template +constexpr bool operator==(std::nullopt_t, const CustomizableOptional &X) { + return X == std::nullopt; +} + +template +constexpr bool operator!=(const CustomizableOptional &X, std::nullopt_t) { + return !(X == std::nullopt); +} + +template +constexpr bool operator!=(std::nullopt_t, const CustomizableOptional &X) { + return X != std::nullopt; +} + +template +constexpr bool operator<(const CustomizableOptional &, std::nullopt_t) { + return false; +} + +template +constexpr bool operator<(std::nullopt_t, const CustomizableOptional &X) { + return X.has_value(); +} + +template +constexpr bool operator<=(const CustomizableOptional &X, std::nullopt_t) { + return !(std::nullopt < X); +} + +template +constexpr bool operator<=(std::nullopt_t, const CustomizableOptional &X) { + return !(X < std::nullopt); +} + +template +constexpr bool operator>(const CustomizableOptional &X, std::nullopt_t) { + return std::nullopt < X; +} + +template +constexpr bool operator>(std::nullopt_t, const CustomizableOptional &X) { + return X < std::nullopt; +} + +template +constexpr bool operator>=(const CustomizableOptional &X, std::nullopt_t) { + return std::nullopt <= X; +} + +template +constexpr bool operator>=(std::nullopt_t, const CustomizableOptional &X) { + return X <= std::nullopt; +} + +template +constexpr bool operator==(const CustomizableOptional &X, const T &Y) { + return X && *X == Y; +} + +template +constexpr bool operator==(const T &X, const CustomizableOptional &Y) { + return Y && X == *Y; +} + +template +constexpr bool operator!=(const CustomizableOptional &X, const T &Y) { + return !(X == Y); +} + +template +constexpr bool operator!=(const T &X, const CustomizableOptional &Y) { + return !(X == Y); +} + +template +constexpr bool operator<(const CustomizableOptional &X, const T &Y) { + return !X || *X < Y; +} + +template +constexpr bool operator<(const T &X, const CustomizableOptional &Y) { + return Y && X < *Y; +} + +template +constexpr bool operator<=(const CustomizableOptional &X, const T &Y) { + return !(Y < X); +} + +template +constexpr bool operator<=(const T &X, const CustomizableOptional &Y) { + return !(Y < X); +} + +template +constexpr bool operator>(const CustomizableOptional &X, const T &Y) { + return Y < X; +} + +template +constexpr bool operator>(const T &X, const CustomizableOptional &Y) { + return Y < X; +} + +template +constexpr bool operator>=(const CustomizableOptional &X, const T &Y) { + return !(X < Y); +} + +template +constexpr bool operator>=(const T &X, const CustomizableOptional &Y) { + return !(X < Y); +} + +} // namespace clang + +#endif // CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h index 120e3f5..1aff5b4 100644 --- a/clang/include/clang/Basic/Diagnostic.h +++ b/clang/include/clang/Basic/Diagnostic.h @@ -1472,6 +1472,12 @@ operator<<(const StreamingDiagnostic &DB, T *DC) { } inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, + SourceLocation L) { + DB.AddSourceRange(CharSourceRange::getTokenRange(L)); + return DB; +} + +inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB, SourceRange R) { DB.AddSourceRange(CharSourceRange::getTokenRange(R)); return DB; diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h index 1a31826..dca68ef 100644 --- a/clang/include/clang/Basic/DirectoryEntry.h +++ b/clang/include/clang/Basic/DirectoryEntry.h @@ -14,12 +14,13 @@ #ifndef LLVM_CLANG_BASIC_DIRECTORYENTRY_H #define LLVM_CLANG_BASIC_DIRECTORYENTRY_H +#include "clang/Basic/CustomizableOptional.h" #include "clang/Basic/LLVM.h" #include "llvm/ADT/DenseMapInfo.h" #include "llvm/ADT/Hashing.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/Support/ErrorOr.h" #include @@ -115,6 +116,8 @@ private: const MapEntry *ME; }; +using OptionalDirectoryEntryRef = CustomizableOptional; + namespace FileMgr { /// Customized storage for refs derived from map entires in FileManager, using @@ -158,9 +161,7 @@ public: }; } // end namespace FileMgr -} // end namespace clang -namespace llvm { namespace optional_detail { /// Customize OptionalStorage to use DirectoryEntryRef and @@ -184,16 +185,16 @@ public: } }; -static_assert(sizeof(Optional) == - sizeof(clang::DirectoryEntryRef), - "Optional must avoid size overhead"); +static_assert(sizeof(OptionalDirectoryEntryRef) == sizeof(DirectoryEntryRef), + "OptionalDirectoryEntryRef must avoid size overhead"); -static_assert( - std::is_trivially_copyable>::value, - "Optional should be trivially copyable"); +static_assert(std::is_trivially_copyable::value, + "OptionalDirectoryEntryRef should be trivially copyable"); } // end namespace optional_detail +} // namespace clang +namespace llvm { /// Specialisation of DenseMapInfo for DirectoryEntryRef. template <> struct DenseMapInfo { static inline clang::DirectoryEntryRef getEmptyKey() { @@ -229,19 +230,19 @@ template <> struct DenseMapInfo { namespace clang { -/// Wrapper around Optional that degrades to 'const +/// Wrapper around OptionalDirectoryEntryRef that degrades to 'const /// DirectoryEntry*', facilitating incremental patches to propagate /// DirectoryEntryRef. /// /// This class can be used as return value or field where it's convenient for -/// an Optional to degrade to a 'const DirectoryEntry*'. The +/// an OptionalDirectoryEntryRef to degrade to a 'const DirectoryEntry*'. The /// purpose is to avoid code churn due to dances like the following: /// \code /// // Old code. /// lvalue = rvalue; /// /// // Temporary code from an incremental patch. -/// Optional MaybeF = rvalue; +/// OptionalDirectoryEntryRef MaybeF = rvalue; /// lvalue = MaybeF ? &MaybeF.getDirectoryEntry() : nullptr; /// /// // Final code. @@ -250,9 +251,9 @@ namespace clang { /// /// FIXME: Once DirectoryEntryRef is "everywhere" and DirectoryEntry::LastRef /// and DirectoryEntry::getName have been deleted, delete this class and -/// replace instances with Optional. +/// replace instances with OptionalDirectoryEntryRef. class OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr - : public Optional { + : public OptionalDirectoryEntryRef { public: OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr() = default; OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr( @@ -266,28 +267,29 @@ public: OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(std::nullopt_t) {} OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(DirectoryEntryRef Ref) - : Optional(Ref) {} - OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(Optional MaybeRef) - : Optional(MaybeRef) {} + : OptionalDirectoryEntryRef(Ref) {} + OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr( + OptionalDirectoryEntryRef MaybeRef) + : OptionalDirectoryEntryRef(MaybeRef) {} OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr & operator=(std::nullopt_t) { - Optional::operator=(std::nullopt); + OptionalDirectoryEntryRef::operator=(std::nullopt); return *this; } OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(DirectoryEntryRef Ref) { - Optional::operator=(Ref); + OptionalDirectoryEntryRef::operator=(Ref); return *this; } OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr & - operator=(Optional MaybeRef) { - Optional::operator=(MaybeRef); + operator=(OptionalDirectoryEntryRef MaybeRef) { + OptionalDirectoryEntryRef::operator=(MaybeRef); return *this; } /// Degrade to 'const DirectoryEntry *' to allow DirectoryEntry::LastRef and /// DirectoryEntry::getName have been deleted, delete this class and replace - /// instances with Optional + /// instances with OptionalDirectoryEntryRef operator const DirectoryEntry *() const { return has_value() ? &(*this)->getDirEntry() : nullptr; } diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 9f00cfa..6ff9c19a 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -14,6 +14,7 @@ #ifndef LLVM_CLANG_BASIC_FILEENTRY_H #define LLVM_CLANG_BASIC_FILEENTRY_H +#include "clang/Basic/CustomizableOptional.h" #include "clang/Basic/DirectoryEntry.h" #include "clang/Basic/LLVM.h" #include "llvm/ADT/DenseMapInfo.h" @@ -41,19 +42,12 @@ namespace clang { class FileEntryRef; -} // namespace clang - -namespace llvm { namespace optional_detail { /// Forward declare a template specialization for OptionalStorage. -template <> -class OptionalStorage; +template <> class OptionalStorage; } // namespace optional_detail -} // namespace llvm - -namespace clang { class FileEntry; @@ -129,7 +123,7 @@ public: llvm::PointerUnion V; /// Directory the file was found in. Set if and only if V is a FileEntry. - Optional Dir; + OptionalDirectoryEntryRef Dir; MapValue() = delete; MapValue(FileEntry &FE, DirectoryEntryRef Dir) : V(&FE), Dir(Dir) {} @@ -207,9 +201,8 @@ static_assert(sizeof(FileEntryRef) == sizeof(const FileEntry *), static_assert(std::is_trivially_copyable::value, "FileEntryRef must be trivially copyable"); -} // end namespace clang +using OptionalFileEntryRef = CustomizableOptional; -namespace llvm { namespace optional_detail { /// Customize OptionalStorage to use FileEntryRef and its @@ -233,15 +226,16 @@ public: } }; -static_assert(sizeof(Optional) == - sizeof(clang::FileEntryRef), - "Optional must avoid size overhead"); +static_assert(sizeof(OptionalFileEntryRef) == sizeof(FileEntryRef), + "OptionalFileEntryRef must avoid size overhead"); -static_assert(std::is_trivially_copyable>::value, - "Optional should be trivially copyable"); +static_assert(std::is_trivially_copyable::value, + "OptionalFileEntryRef should be trivially copyable"); } // end namespace optional_detail +} // namespace clang +namespace llvm { /// Specialisation of DenseMapInfo for FileEntryRef. template <> struct DenseMapInfo { static inline clang::FileEntryRef getEmptyKey() { @@ -274,18 +268,18 @@ template <> struct DenseMapInfo { namespace clang { -/// Wrapper around Optional that degrades to 'const FileEntry*', +/// Wrapper around OptionalFileEntryRef that degrades to 'const FileEntry*', /// facilitating incremental patches to propagate FileEntryRef. /// /// This class can be used as return value or field where it's convenient for -/// an Optional to degrade to a 'const FileEntry*'. The purpose +/// an OptionalFileEntryRef to degrade to a 'const FileEntry*'. The purpose /// is to avoid code churn due to dances like the following: /// \code /// // Old code. /// lvalue = rvalue; /// /// // Temporary code from an incremental patch. -/// Optional MaybeF = rvalue; +/// OptionalFileEntryRef MaybeF = rvalue; /// lvalue = MaybeF ? &MaybeF.getFileEntry() : nullptr; /// /// // Final code. @@ -294,9 +288,8 @@ namespace clang { /// /// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and /// FileEntry::getName have been deleted, delete this class and replace -/// instances with Optional. -class OptionalFileEntryRefDegradesToFileEntryPtr - : public Optional { +/// instances with OptionalFileEntryRef. +class OptionalFileEntryRefDegradesToFileEntryPtr : public OptionalFileEntryRef { public: OptionalFileEntryRefDegradesToFileEntryPtr() = default; OptionalFileEntryRefDegradesToFileEntryPtr( @@ -310,27 +303,27 @@ public: OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {} OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref) - : Optional(Ref) {} - OptionalFileEntryRefDegradesToFileEntryPtr(Optional MaybeRef) - : Optional(MaybeRef) {} + : OptionalFileEntryRef(Ref) {} + OptionalFileEntryRefDegradesToFileEntryPtr(OptionalFileEntryRef MaybeRef) + : OptionalFileEntryRef(MaybeRef) {} OptionalFileEntryRefDegradesToFileEntryPtr &operator=(std::nullopt_t) { - Optional::operator=(std::nullopt); + OptionalFileEntryRef::operator=(std::nullopt); return *this; } OptionalFileEntryRefDegradesToFileEntryPtr &operator=(FileEntryRef Ref) { - Optional::operator=(Ref); + OptionalFileEntryRef::operator=(Ref); return *this; } OptionalFileEntryRefDegradesToFileEntryPtr & - operator=(Optional MaybeRef) { - Optional::operator=(MaybeRef); + operator=(OptionalFileEntryRef MaybeRef) { + OptionalFileEntryRef::operator=(MaybeRef); return *this; } /// Degrade to 'const FileEntry *' to allow FileEntry::LastRef and /// FileEntry::getName have been deleted, delete this class and replace - /// instances with Optional + /// instances with OptionalFileEntryRef operator const FileEntry *() const { return has_value() ? &(*this)->getFileEntry() : nullptr; } @@ -341,20 +334,16 @@ static_assert( OptionalFileEntryRefDegradesToFileEntryPtr>::value, "OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable"); -inline bool operator==(const FileEntry *LHS, - const Optional &RHS) { +inline bool operator==(const FileEntry *LHS, const OptionalFileEntryRef &RHS) { return LHS == (RHS ? &RHS->getFileEntry() : nullptr); } -inline bool operator==(const Optional &LHS, - const FileEntry *RHS) { +inline bool operator==(const OptionalFileEntryRef &LHS, const FileEntry *RHS) { return (LHS ? &LHS->getFileEntry() : nullptr) == RHS; } -inline bool operator!=(const FileEntry *LHS, - const Optional &RHS) { +inline bool operator!=(const FileEntry *LHS, const OptionalFileEntryRef &RHS) { return !(LHS == RHS); } -inline bool operator!=(const Optional &LHS, - const FileEntry *RHS) { +inline bool operator!=(const OptionalFileEntryRef &LHS, const FileEntry *RHS) { return !(LHS == RHS); } @@ -390,7 +379,7 @@ class FileEntry { // default constructor). It should always have a value in practice. // // TODO: remove this once everyone that needs a name uses FileEntryRef. - Optional LastRef; + OptionalFileEntryRef LastRef; public: ~FileEntry(); diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ec62e00..84d5693 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -102,7 +102,7 @@ class FileManager : public RefCountedBase { SeenBypassFileEntries; /// The file entry for stdin, if it has been accessed through the FileManager. - Optional STDIN; + OptionalFileEntryRef STDIN; /// The canonical names of files and directories . llvm::DenseMap CanonicalNames; @@ -166,8 +166,8 @@ public: bool CacheFailure = true); /// Get a \c DirectoryEntryRef if it exists, without doing anything on error. - llvm::Optional - getOptionalDirectoryRef(StringRef DirName, bool CacheFailure = true) { + OptionalDirectoryEntryRef getOptionalDirectoryRef(StringRef DirName, + bool CacheFailure = true) { return llvm::expectedToOptional(getDirectoryRef(DirName, CacheFailure)); } @@ -231,9 +231,9 @@ public: llvm::Expected getSTDIN(); /// Get a FileEntryRef if it exists, without doing anything on error. - llvm::Optional getOptionalFileRef(StringRef Filename, - bool OpenFile = false, - bool CacheFailure = true) { + OptionalFileEntryRef getOptionalFileRef(StringRef Filename, + bool OpenFile = false, + bool CacheFailure = true) { return llvm::expectedToOptional( getFileRef(Filename, OpenFile, CacheFailure)); } @@ -270,7 +270,7 @@ public: /// bypasses all mapping and uniquing, blindly creating a new FileEntry. /// There is no attempt to deduplicate these; if you bypass the same file /// twice, you get two new file entries. - llvm::Optional getBypassFile(FileEntryRef VFE); + OptionalFileEntryRef getBypassFile(FileEntryRef VFE); /// Open the specified file as a MemoryBuffer, returning a new /// MemoryBuffer if successful, otherwise returning null. diff --git a/clang/include/clang/Basic/LLVM.h b/clang/include/clang/Basic/LLVM.h index 6375bd0..5d4d726 100644 --- a/clang/include/clang/Basic/LLVM.h +++ b/clang/include/clang/Basic/LLVM.h @@ -37,7 +37,7 @@ namespace llvm { template class SmallString; template class SmallVector; template class SmallVectorImpl; - template class Optional; + template class Optional; template class Expected; template diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index c41ae41..11c021e 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -185,7 +185,7 @@ private: /// The AST file if this is a top-level module which has a /// corresponding serialized AST file, or null otherwise. - Optional ASTFile; + OptionalFileEntryRef ASTFile; /// The top-level headers associated with this module. llvm::SmallSetVector TopHeaders; @@ -610,7 +610,7 @@ public: } /// Set the serialized AST file for the top-level module of this module. - void setASTFile(Optional File) { + void setASTFile(OptionalFileEntryRef File) { assert((!getASTFile() || getASTFile() == File) && "file path changed"); getTopLevelModule()->ASTFile = File; } diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 20f2415..d7f8125 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -1003,7 +1003,7 @@ public: /// is no such file in the filesystem. /// /// This should be called before parsing has begun. - Optional bypassFileContentsOverride(FileEntryRef File); + OptionalFileEntryRef bypassFileContentsOverride(FileEntryRef File); /// Specify that a file is transient. void setFileIsTransient(const FileEntry *SourceFile); @@ -1049,7 +1049,7 @@ public: } /// Returns the FileEntryRef for the provided FileID. - Optional getFileEntryRefForID(FileID FID) const { + OptionalFileEntryRef getFileEntryRefForID(FileID FID) const { if (auto *Entry = getSLocEntryForFile(FID)) return Entry->getFile().getContentCache().OrigEntry; return std::nullopt; diff --git a/clang/include/clang/Lex/DirectoryLookup.h b/clang/include/clang/Lex/DirectoryLookup.h index 375e525..99f7c50 100644 --- a/clang/include/clang/Lex/DirectoryLookup.h +++ b/clang/include/clang/Lex/DirectoryLookup.h @@ -91,8 +91,8 @@ public: return isNormalDir() ? &u.Dir.getDirEntry() : nullptr; } - Optional getDirRef() const { - return isNormalDir() ? Optional(u.Dir) : std::nullopt; + OptionalDirectoryEntryRef getDirRef() const { + return isNormalDir() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt; } /// getFrameworkDir - Return the directory that this framework refers to. @@ -101,8 +101,8 @@ public: return isFramework() ? &u.Dir.getDirEntry() : nullptr; } - Optional getFrameworkDirRef() const { - return isFramework() ? Optional(u.Dir) : std::nullopt; + OptionalDirectoryEntryRef getFrameworkDirRef() const { + return isFramework() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt; } /// getHeaderMap - Return the directory that this entry refers to. @@ -180,7 +180,7 @@ public: /// \param [out] MappedName if this is a headermap which maps the filename to /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this /// vector and point Filename to it. - Optional + OptionalFileEntryRef LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, @@ -190,7 +190,7 @@ public: bool OpenFile = true) const; private: - Optional DoFrameworkLookup( + OptionalFileEntryRef DoFrameworkLookup( StringRef Filename, HeaderSearch &HS, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 4684f55..76e3e78 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -145,7 +145,7 @@ public: /// This structure is used to record entries in our framework cache. struct FrameworkCacheEntry { /// The directory entry which should be used for the cached framework. - Optional Directory; + OptionalDirectoryEntryRef Directory; /// Whether this framework has been "user-specified" to be treated as if it /// were a system framework (even if it was found outside a system framework @@ -479,7 +479,7 @@ public: /// found in any of searched SearchDirs. Will be set to false if a framework /// is found only through header maps. Doesn't guarantee the requested file is /// found. - Optional LookupFile( + OptionalFileEntryRef LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir, ArrayRef> Includers, @@ -495,7 +495,7 @@ public: /// 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 LookupSubframeworkHeader( + OptionalFileEntryRef LookupSubframeworkHeader( StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule); @@ -769,7 +769,7 @@ private: /// Look up the file with the specified name and determine its owning /// module. - Optional + OptionalFileEntryRef getFileAndSuggestModule(StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir, bool IsSystemHeaderDir, Module *RequestingModule, diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h index 8c8fa4d..ba7b681 100644 --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -333,7 +333,7 @@ private: /// \param NeedsFramework If M is not a framework but a missing header would /// be found in case M was, set it to true. False otherwise. /// \return The resolved file, if any. - Optional + OptionalFileEntryRef findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header, SmallVectorImpl &RelativePathName, bool &NeedsFramework); @@ -606,7 +606,7 @@ public: /// /// \returns The file entry for the module map file containing the given /// module, or nullptr if the module definition was inferred. - Optional getContainingModuleMapFile(const Module *Module) const; + OptionalFileEntryRef getContainingModuleMapFile(const Module *Module) const; /// Get the module map file that (along with the module name) uniquely /// identifies this module. @@ -617,7 +617,7 @@ public: /// of inferred modules, returns the module map that allowed the inference /// (e.g. contained 'module *'). Otherwise, returns /// getContainingModuleMapFile(). - Optional getModuleMapFileForUniquing(const Module *M) const; + OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const; void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap); diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h index 045df87..2e99fd9 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -125,16 +125,12 @@ public: /// implicitly 'extern "C"' in C++ mode. /// virtual void InclusionDirective(SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional File, - StringRef SearchPath, - StringRef RelativePath, + const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, + OptionalFileEntryRef File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { - } + SrcMgr::CharacteristicKind FileType) {} /// Callback invoked whenever a submodule was entered. /// @@ -327,7 +323,7 @@ public: /// Hook called when a '__has_include' or '__has_include_next' directive is /// read. virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, - Optional File, + OptionalFileEntryRef File, SrcMgr::CharacteristicKind FileType); /// Hook called when a source range is skipped. @@ -458,7 +454,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, @@ -548,7 +544,7 @@ public: } void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, - Optional File, + OptionalFileEntryRef File, SrcMgr::CharacteristicKind FileType) override; void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, diff --git a/clang/include/clang/Lex/PreprocessingRecord.h b/clang/include/clang/Lex/PreprocessingRecord.h index ee22f1e..c385bc6 100644 --- a/clang/include/clang/Lex/PreprocessingRecord.h +++ b/clang/include/clang/Lex/PreprocessingRecord.h @@ -240,12 +240,12 @@ class Token; unsigned ImportedModule : 1; /// The file that was included. - Optional File; + OptionalFileEntryRef File; public: InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, - Optional File, SourceRange Range); + OptionalFileEntryRef File, SourceRange Range); /// Determine what kind of inclusion directive this is. InclusionKind getKind() const { return static_cast(Kind); } @@ -263,7 +263,7 @@ class Token; /// Retrieve the file entry for the actual file that was included /// by this directive. - Optional getFile() const { return File; } + OptionalFileEntryRef getFile() const { return File; } // Implement isa/cast/dyncast/etc. static bool classof(const PreprocessedEntity *PE) { @@ -528,7 +528,7 @@ class Token; void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void Ifdef(SourceLocation Loc, const Token &MacroNameTok, diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 05e05e8..b39eca9 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2243,7 +2243,7 @@ public: /// /// Returns std::nullopt on failure. \p isAngled indicates whether the file /// reference is for system \#include's or not (i.e. using <> instead of ""). - Optional + OptionalFileEntryRef LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDir, SmallVectorImpl *SearchPath, @@ -2510,7 +2510,7 @@ private: } }; - Optional LookupHeaderIncludeOrImport( + OptionalFileEntryRef LookupHeaderIncludeOrImport( ConstSearchDirIterator *CurDir, StringRef &Filename, SourceLocation FilenameLoc, CharSourceRange FilenameRange, const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl, diff --git a/clang/include/clang/Serialization/ModuleManager.h b/clang/include/clang/Serialization/ModuleManager.h index 5f453c3..3bd379a 100644 --- a/clang/include/clang/Serialization/ModuleManager.h +++ b/clang/include/clang/Serialization/ModuleManager.h @@ -302,7 +302,7 @@ public: /// modification time criteria, false if the file is either available and /// suitable, or is missing. bool lookupModuleFile(StringRef FileName, off_t ExpectedSize, - time_t ExpectedModTime, Optional &File); + time_t ExpectedModTime, OptionalFileEntryRef &File); /// View the graphviz representation of the module graph. void viewGraph(); diff --git a/clang/include/clang/Tooling/Core/Replacement.h b/clang/include/clang/Tooling/Core/Replacement.h index 25d8cc6..2c4fb8f 100644 --- a/clang/include/clang/Tooling/Core/Replacement.h +++ b/clang/include/clang/Tooling/Core/Replacement.h @@ -202,6 +202,9 @@ bool operator<(const Replacement &LHS, const Replacement &RHS); /// Equal-to operator between two Replacements. bool operator==(const Replacement &LHS, const Replacement &RHS); +inline bool operator!=(const Replacement &LHS, const Replacement &RHS) { + return !(LHS == RHS); +} /// Maintains a set of replacements that are conflict-free. /// Two replacements are considered conflicts if they overlap or have the same diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h index 1cc6208..8577e14 100644 --- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h +++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h @@ -134,7 +134,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, diff --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h index 5c657b4..beb2f49 100644 --- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h +++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h @@ -16,6 +16,7 @@ #define LLVM_CLANG_TOOLING_INCLUSIONS_STANDARDLIBRARY_H #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/Hashing.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" #include 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 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 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 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 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 +OptionalFileEntryRef SourceManager::bypassFileContentsOverride(FileEntryRef File) { assert(isFileOverridden(&File.getFileEntry())); - llvm::Optional 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(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 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 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 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 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 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 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 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 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 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 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 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 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 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, 1> CWD; CWD.push_back({nullptr, Dir}); - Optional 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 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 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 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 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 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 /*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 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 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 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 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 HeaderSearch::getFileAndSuggestModule( /// LookupFile - Lookup the specified file in this search path, returning it /// if it exists or returning null if not. -Optional DirectoryLookup::LookupFile( +OptionalFileEntryRef DirectoryLookup::LookupFile( StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, @@ -532,7 +532,7 @@ Optional 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 +static OptionalDirectoryEntryRef getTopFrameworkDir(FileManager &FileMgr, StringRef DirName, SmallVectorImpl &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 DirectoryLookup::DoFrameworkLookup( +OptionalFileEntryRef DirectoryLookup::DoFrameworkLookup( StringRef Filename, HeaderSearch &HS, SmallVectorImpl *SearchPath, SmallVectorImpl *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 HeaderSearch::LookupFile( +OptionalFileEntryRef HeaderSearch::LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg, ArrayRef> Includers, @@ -898,7 +898,7 @@ Optional HeaderSearch::LookupFile( // This is the header that MSVC's header search would have found. ModuleMap::KnownHeader MSSuggestedModule; - Optional 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 HeaderSearch::LookupFile( bool IncluderIsSystemHeader = Includer ? getFileInfo(Includer).DirInfo != SrcMgr::C_User : BuildSystemModule; - if (Optional FE = getFileAndSuggestModule( + if (OptionalFileEntryRef FE = getFileAndSuggestModule( TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader, RequestingModule, SuggestedModule)) { if (!Includer) { @@ -1043,7 +1043,7 @@ Optional HeaderSearch::LookupFile( bool InUserSpecifiedSystemFramework = false; bool IsInHeaderMap = false; bool IsFrameworkFoundInDir = false; - Optional File = It->LookupFile( + OptionalFileEntryRef File = It->LookupFile( Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule, SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir, IsInHeaderMap, MappedName, OpenFile); @@ -1138,7 +1138,7 @@ Optional HeaderSearch::LookupFile( ScratchFilename += '/'; ScratchFilename += Filename; - Optional 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 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 HeaderSearch::LookupSubframeworkHeader( +OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader( StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl *SearchPath, SmallVectorImpl *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 SubmodulePath; - Optional 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 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 ModuleMap::findHeader( +OptionalFileEntryRef ModuleMap::findHeader( Module *M, const Module::UnresolvedHeaderDirective &Header, SmallVectorImpl &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 { + 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 ModuleMap::findHeader( return *File; }; - auto GetFrameworkFile = [&]() -> Optional { + 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 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 +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 +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 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 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 Preprocessor::LookupFile( +OptionalFileEntryRef Preprocessor::LookupFile( SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDirArg, SmallVectorImpl *SearchPath, @@ -1012,7 +1012,7 @@ Optional Preprocessor::LookupFile( // the include path until we find that file or run out of files. ConstSearchDirIterator TmpCurDir = CurDir; ConstSearchDirIterator TmpFromDir = nullptr; - while (Optional 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 Preprocessor::LookupFile( } // Do a standard file entry lookup. - Optional 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 Preprocessor::LookupFile( // headers on the #include stack and pass them to HeaderInfo. if (IsFileLexer()) { if ((CurFileEnt = CurPPLexer->getFileEntry())) { - if (Optional FE = HeaderInfo.LookupSubframeworkHeader( + if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader( Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule, SuggestedModule)) { if (SuggestedModule && !LangOpts.AsmPreprocessor) @@ -1063,7 +1063,7 @@ Optional Preprocessor::LookupFile( for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) { if (IsFileLexer(ISEntry)) { if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) { - if (Optional 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 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 Preprocessor::LookupHeaderIncludeOrImport( const FileEntry *LookupFromFile, StringRef &LookupFilename, SmallVectorImpl &RelativePath, SmallVectorImpl &SearchPath, ModuleMap::KnownHeader &SuggestedModule, bool isAngled) { - Optional 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 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 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 Preprocessor::LookupHeaderIncludeOrImport( StringRef TypoCorrectionName = CorrectTypoFilename(Filename); StringRef TypoCorrectionLookupName = CorrectTypoFilename(LookupFilename); - Optional 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 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 File = SourceMgr.getFileEntryRefForID(FID)) { + if (OptionalFileEntryRef File = SourceMgr.getFileEntryRefForID(FID)) { if (Optional> 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 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 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 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 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 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 bb04576..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 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 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 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 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 Visitor, bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize, time_t ExpectedModTime, - Optional &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 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 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 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 ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M); + OptionalFileEntryRef ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M); if (ModuleMap) { SmallString<128> Path = ModuleMap->getNameAsRequested(); diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 5a36679..06fc651 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -8531,7 +8531,7 @@ CXFile clang_getIncludedFile(CXCursor cursor) { return nullptr; const InclusionDirective *ID = getCursorInclusionDirective(cursor); - Optional File = ID->getFile(); + OptionalFileEntryRef File = ID->getFile(); return const_cast(File ? &File->getFileEntry() : nullptr); } diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp index 979acae..da58a48 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.cpp +++ b/clang/tools/libclang/CXIndexDataConsumer.cpp @@ -463,10 +463,10 @@ void CXIndexDataConsumer::enteredMainFile(const FileEntry *File) { } void CXIndexDataConsumer::ppIncludedFile(SourceLocation hashLoc, - StringRef filename, - Optional File, - bool isImport, bool isAngled, - bool isModuleImport) { + StringRef filename, + OptionalFileEntryRef File, + bool isImport, bool isAngled, + bool isModuleImport) { if (!CB.ppIncludedFile) return; diff --git a/clang/tools/libclang/CXIndexDataConsumer.h b/clang/tools/libclang/CXIndexDataConsumer.h index 04c64ca..b78ef36 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.h +++ b/clang/tools/libclang/CXIndexDataConsumer.h @@ -363,7 +363,7 @@ public: void enteredMainFile(const FileEntry *File); void ppIncludedFile(SourceLocation hashLoc, StringRef filename, - Optional File, bool isImport, bool isAngled, + OptionalFileEntryRef File, bool isImport, bool isAngled, bool isModuleImport); void importedModule(const ImportDecl *ImportD); diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index 206dd48..1be313d 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -262,7 +262,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { bool isImport = (IncludeTok.is(tok::identifier) && diff --git a/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp index df179dd..d546559 100644 --- a/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp @@ -102,10 +102,10 @@ TEST(TransferBranchTest, IfElse) { ASSERT_THAT(Results.keys(), UnorderedElementsAre("p", "q")); const TestLattice &LP = getLatticeAtAnnotation(Results, "p"); - EXPECT_THAT(LP.Branch, Optional(true)); + EXPECT_THAT(LP.Branch, std::make_optional(true)); const TestLattice &LQ = getLatticeAtAnnotation(Results, "q"); - EXPECT_THAT(LQ.Branch, Optional(false)); + EXPECT_THAT(LQ.Branch, std::make_optional(false)); }, LangStandard::lang_cxx17); } diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index 6fe4a3d..146a609 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -534,7 +534,7 @@ TEST_F(FileManagerTest, getBypassFile) { // Calling a second time should not affect the UID or size. unsigned VirtualUID = FE.getUID(); - llvm::Optional SearchRef; + OptionalFileEntryRef SearchRef; ASSERT_THAT_ERROR(Manager.getFileRef("/tmp/test").moveInto(SearchRef), Succeeded()); EXPECT_EQ(&FE, &SearchRef->getFileEntry()); @@ -542,8 +542,7 @@ TEST_F(FileManagerTest, getBypassFile) { EXPECT_EQ(FE.getSize(), 10); // Bypass the file. - llvm::Optional BypassRef = - Manager.getBypassFile(File->getLastRef()); + OptionalFileEntryRef BypassRef = Manager.getBypassFile(File->getLastRef()); ASSERT_TRUE(BypassRef); EXPECT_EQ("/tmp/test", BypassRef->getName()); diff --git a/clang/unittests/Lex/PPCallbacksTest.cpp b/clang/unittests/Lex/PPCallbacksTest.cpp index 43f7b4a..ec71938 100644 --- a/clang/unittests/Lex/PPCallbacksTest.cpp +++ b/clang/unittests/Lex/PPCallbacksTest.cpp @@ -36,7 +36,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, + OptionalFileEntryRef File, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { this->HashLoc = HashLoc; @@ -56,7 +56,7 @@ public: SmallString<16> FileName; bool IsAngled; CharSourceRange FilenameRange; - Optional File; + OptionalFileEntryRef File; SmallString<16> SearchPath; SmallString<16> RelativePath; const Module* Imported; diff --git a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp index b7d7431..b41d965 100644 --- a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp +++ b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp @@ -92,7 +92,7 @@ TEST_F(PPDependencyDirectivesTest, MacroGuard) { "#include \"head3.h\"\n#include \"head3.h\"\n")); FileMgr.setVirtualFileSystem(VFS); - Optional FE; + OptionalFileEntryRef FE; ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE), llvm::Succeeded()); SourceMgr.setMainFileID( -- 2.7.4