diff options
author | Krzysztof Parzyszek <kparzysz@quicinc.com> | 2022-12-18 11:19:40 -0800 |
---|---|---|
committer | Krzysztof Parzyszek <kparzysz@quicinc.com> | 2022-12-18 11:23:54 -0800 |
commit | 205c0589f918f95d2f2c586a01bea2716d73d603 (patch) | |
tree | 38b2227ab6d17d7d189f32a23e5498404d45b634 | |
parent | a538f7cfb1d71cd1a71b5b6d9fe8672a8b6d973e (diff) | |
download | llvm-205c0589f918f95d2f2c586a01bea2716d73d603.zip llvm-205c0589f918f95d2f2c586a01bea2716d73d603.tar.gz llvm-205c0589f918f95d2f2c586a01bea2716d73d603.tar.bz2 |
Revert "[clang] Convert OptionalFileEntryRefDegradesToFileEntryPtr to std::optional"
This reverts commit 8f0df9f3bbc6d7f3d5cbfd955c5ee4404c53a75d.
The Optional*RefDegradesTo*EntryPtr types want to keep the same size as
the underlying type, which std::optional doesn't guarantee. For use with
llvm::Optional, they define their own storage class, and there is no way
to do that in std::optional.
On top of that, that commit broke builds with older GCCs, where
std::optional was not trivially copyable (static_assert in the clang
sources was failing).
70 files changed, 250 insertions, 355 deletions
diff --git a/clang-tools-extra/clang-move/Move.cpp b/clang-tools-extra/clang-move/Move.cpp index 8fe1a99..9e44fe1 100644 --- a/clang-tools-extra/clang-move/Move.cpp +++ b/clang-tools-extra/clang-move/Move.cpp @@ -18,7 +18,6 @@ #include "clang/Tooling/Core/Replacement.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Path.h" -#include <optional> #define DEBUG_TYPE "clang-move" @@ -132,8 +131,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token & /*IncludeTok*/, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> /*File*/, - StringRef SearchPath, StringRef /*RelativePath*/, + Optional<FileEntryRef> /*File*/, StringRef SearchPath, + StringRef /*RelativePath*/, const Module * /*Imported*/, SrcMgr::CharacteristicKind /*FileType*/) override { if (const auto *FileEntry = SM.getFileEntryForID(SM.getFileID(HashLoc))) diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp index 62a1700..f88e24c 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -12,7 +12,6 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Serialization/ASTReader.h" -#include <optional> #define DEBUG_TYPE "clang-tidy" @@ -163,7 +162,7 @@ void ExpandModularHeadersPPCallbacks::FileChanged( void ExpandModularHeadersPPCallbacks::InclusionDirective( SourceLocation DirectiveLoc, const Token &IncludeToken, StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> IncludedFile, StringRef SearchPath, + Optional<FileEntryRef> IncludedFile, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (Imported) { @@ -225,8 +224,7 @@ void ExpandModularHeadersPPCallbacks::PragmaDiagnostic(SourceLocation Loc, parseToLocation(Loc); } void ExpandModularHeadersPPCallbacks::HasInclude(SourceLocation Loc, StringRef, - bool, - std::optional<FileEntryRef>, + bool, Optional<FileEntryRef>, SrcMgr::CharacteristicKind) { parseToLocation(Loc); } diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h index 7e616dc..29f0605 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h @@ -12,7 +12,6 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/DenseSet.h" -#include <optional> namespace llvm { namespace vfs { @@ -70,7 +69,7 @@ private: void InclusionDirective(SourceLocation DirectiveLoc, const Token &IncludeToken, StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> IncludedFile, + Optional<FileEntryRef> IncludedFile, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -92,8 +91,7 @@ private: void PragmaDiagnosticPop(SourceLocation Loc, StringRef) override; void PragmaDiagnostic(SourceLocation Loc, StringRef, diag::Severity, StringRef) override; - void HasInclude(SourceLocation Loc, StringRef, bool, - std::optional<FileEntryRef>, + void HasInclude(SourceLocation Loc, StringRef, bool, Optional<FileEntryRef> , 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 6a8214c..c51fd53 100644 --- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp @@ -10,7 +10,6 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" -#include <optional> #include <string> #include <vector> @@ -31,9 +30,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FileNameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; @@ -64,7 +62,7 @@ void KernelNameRestrictionCheck::registerPPCallbacks(const SourceManager &SM, void KernelNameRestrictionPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &, StringRef FileName, bool, - CharSourceRange, std::optional<FileEntryRef>, StringRef, StringRef, + CharSourceRange, Optional<FileEntryRef>, 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 08d2cf1..b8fbc6e 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp @@ -9,7 +9,6 @@ #include "SuspiciousIncludeCheck.h" #include "clang/AST/ASTContext.h" #include "clang/Lex/Preprocessor.h" -#include <optional> namespace clang { namespace tidy { @@ -26,9 +25,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; private: @@ -74,9 +72,8 @@ void SuspiciousIncludeCheck::registerPPCallbacks( void SuspiciousIncludePPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import) return; @@ -96,7 +93,7 @@ void SuspiciousIncludePPCallbacks::InclusionDirective( llvm::sys::path::replace_extension(GuessedFileName, (HFE.size() ? "." : "") + HFE); - std::optional<FileEntryRef> File = + Optional<FileEntryRef> 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 617dfb6..f701bd1 100644 --- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp @@ -13,7 +13,6 @@ #include "llvm/ADT/STLExtras.h" #include <map> -#include <optional> namespace clang { namespace tidy { @@ -29,9 +28,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; @@ -84,9 +82,8 @@ static int getPriority(StringRef Filename, bool IsAngled, bool IsMainModule) { void IncludeOrderPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { // We recognize the first include as a special main module header and want // to leave it in the top position. diff --git a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp index 97b5bae..62379f1 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp @@ -12,7 +12,6 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/Preprocessor.h" -#include <optional> // FixItHint - Hint to check documentation script to mark this check as // providing a FixIt. @@ -35,9 +34,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; private: @@ -48,9 +46,8 @@ private: void RestrictedIncludesPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { // Compiler provided headers are allowed (e.g stddef.h). if (SrcMgr::isSystem(FileType) && SearchPath == CompilerIncudeDir) diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp index ea3e84d..64e70ad 100644 --- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp @@ -15,7 +15,6 @@ #include "llvm/ADT/StringSet.h" #include <algorithm> -#include <optional> #include <vector> using IncludeMarker = @@ -34,9 +33,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; private: @@ -181,9 +179,8 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks( void IncludeModernizePPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { // If we don't want to warn for non-main file reports and this is one, skip diff --git a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp index 32489e0..1c196a9 100644 --- a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp @@ -16,7 +16,6 @@ #include <algorithm> #include <cassert> #include <cctype> -#include <optional> #include <string> namespace clang { @@ -120,9 +119,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> 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 c914d9c..7faf7cc 100644 --- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp @@ -15,7 +15,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Path.h" #include <cstring> -#include <optional> namespace clang { namespace tidy { @@ -23,9 +22,8 @@ namespace portability { void RestrictedIncludesPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!Check.contains(FileName) && SrcMgr::isSystem(FileType)) { SmallString<256> FullPath; diff --git a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h index 165aadb..2919b06 100644 --- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h @@ -12,7 +12,6 @@ #include "../ClangTidyCheck.h" #include "../GlobList.h" #include "clang/Lex/PPCallbacks.h" -#include <optional> namespace clang { namespace tidy { @@ -52,9 +51,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> 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 84b97d1..22a4e4e 100644 --- a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp @@ -12,7 +12,6 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include <memory> -#include <optional> namespace clang { namespace tidy { @@ -49,9 +48,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void MacroDefined(const Token &MacroNameTok, @@ -79,9 +77,8 @@ void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc, void DuplicateIncludeCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (llvm::is_contained(Files.back(), FileName)) { // We want to delete the entire line, so make sure that [Start,End] covers diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp index f497f79..08bbe9d 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp @@ -10,7 +10,6 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/Token.h" -#include <optional> namespace clang { namespace tidy { @@ -25,7 +24,7 @@ public: void InclusionDirective(SourceLocation HashLocation, const Token &IncludeToken, StringRef FileNameRef, bool IsAngled, CharSourceRange FileNameRange, - std::optional<FileEntryRef> /*IncludedFile*/, + Optional<FileEntryRef> /*IncludedFile*/, StringRef /*SearchPath*/, StringRef /*RelativePath*/, const Module * /*ImportedModule*/, SrcMgr::CharacteristicKind /*FileType*/) override { diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp index a4647b3..4314ef1 100644 --- a/clang-tools-extra/clangd/Headers.cpp +++ b/clang-tools-extra/clangd/Headers.cpp @@ -19,7 +19,6 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Path.h" #include <cstring> -#include <optional> namespace clang { namespace clangd { @@ -36,7 +35,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange /*FilenameRange*/, - std::optional<FileEntryRef> File, + Optional<FileEntryRef> 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 edb46cf..4e99365 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -50,7 +50,6 @@ #include "llvm/ADT/StringRef.h" #include <algorithm> #include <memory> -#include <optional> #include <vector> // Force the linker to link in Clang-tidy modules. @@ -172,10 +171,9 @@ private: void replay() { for (const auto &Inc : Includes) { - std::optional<FileEntryRef> File; + llvm::Optional<FileEntryRef> File; if (Inc.Resolved != "") - File = - expectedToStdOptional(SM.getFileManager().getFileRef(Inc.Resolved)); + File = expectedToOptional(SM.getFileManager().getFileRef(Inc.Resolved)); // Re-lex the #include directive to find its interesting parts. auto HashLoc = SM.getComposedLoc(SM.getMainFileID(), Inc.HashOffset); diff --git a/clang-tools-extra/clangd/index/IndexAction.cpp b/clang-tools-extra/clangd/index/IndexAction.cpp index 9041c79..aaba2c9 100644 --- a/clang-tools-extra/clangd/index/IndexAction.cpp +++ b/clang-tools-extra/clangd/index/IndexAction.cpp @@ -22,14 +22,13 @@ #include <cstddef> #include <functional> #include <memory> -#include <optional> #include <utility> namespace clang { namespace clangd { namespace { -std::optional<std::string> toURI(std::optional<FileEntryRef> File) { +llvm::Optional<std::string> toURI(Optional<FileEntryRef> File) { if (!File) return std::nullopt; auto AbsolutePath = File->getFileEntry().tryGetRealPathName(); @@ -86,7 +85,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, + Optional<FileEntryRef> File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { diff --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp index 52f7ded..8167413 100644 --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp @@ -37,7 +37,6 @@ #include "gmock/gmock-matchers.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include <optional> namespace clang { namespace clangd { @@ -382,7 +381,7 @@ TEST(ParsedASTTest, ReplayPreambleForTidyCheckers) { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef>, StringRef, StringRef, + Optional<FileEntryRef>, StringRef, StringRef, const clang::Module *, SrcMgr::CharacteristicKind) override { Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled, diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp b/clang-tools-extra/include-cleaner/lib/Record.cpp index efdacc7..e16be12 100644 --- a/clang-tools-extra/include-cleaner/lib/Record.cpp +++ b/clang-tools-extra/include-cleaner/lib/Record.cpp @@ -17,7 +17,6 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "clang/Tooling/Inclusions/HeaderAnalysis.h" -#include <optional> namespace clang::include_cleaner { namespace { @@ -36,7 +35,7 @@ public: void InclusionDirective(SourceLocation Hash, const Token &IncludeTok, StringRef SpelledFilename, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, + llvm::Optional<FileEntryRef> File, StringRef SearchPath, StringRef RelativePath, const Module *, SrcMgr::CharacteristicKind) override { if (!Active) @@ -181,7 +180,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange /*FilenameRange*/, - std::optional<FileEntryRef> File, + Optional<FileEntryRef> 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 d1c0cf8..610fb59 100644 --- a/clang-tools-extra/modularize/CoverageChecker.cpp +++ b/clang-tools-extra/modularize/CoverageChecker.cpp @@ -50,9 +50,9 @@ // //===----------------------------------------------------------------------===// -#include "CoverageChecker.h" #include "ModularizeUtilities.h" #include "clang/AST/ASTConsumer.h" +#include "CoverageChecker.h" #include "clang/AST/ASTContext.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Basic/SourceManager.h" @@ -69,7 +69,6 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include <optional> using namespace Modularize; using namespace clang; @@ -90,9 +89,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> 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 f697288..171a938 100644 --- a/clang-tools-extra/modularize/PreprocessorTracker.cpp +++ b/clang-tools-extra/modularize/PreprocessorTracker.cpp @@ -251,7 +251,6 @@ #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/raw_ostream.h" -#include <optional> namespace Modularize { @@ -735,7 +734,7 @@ public: const clang::Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, - std::optional<clang::FileEntryRef> File, + llvm::Optional<clang::FileEntryRef> File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const clang::Module *Imported, @@ -1279,7 +1278,7 @@ void PreprocessorCallbacks::InclusionDirective( clang::SourceLocation HashLoc, const clang::Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, - std::optional<clang::FileEntryRef> File, llvm::StringRef SearchPath, + llvm::Optional<clang::FileEntryRef> File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const clang::Module *Imported, clang::SrcMgr::CharacteristicKind FileType) { int DirectiveLine, DirectiveColumn; diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp index 1f2eeda..c143455 100644 --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp @@ -17,7 +17,6 @@ #include "clang/Basic/FileManager.h" #include "clang/Lex/MacroArgs.h" #include "llvm/Support/raw_ostream.h" -#include <optional> namespace clang { namespace pp_trace { @@ -134,10 +133,9 @@ 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, - std::optional<FileEntryRef> File, llvm::StringRef SearchPath, - llvm::StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { + bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + llvm::StringRef SearchPath, llvm::StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) { beginCallback("InclusionDirective"); appendArgument("HashLoc", HashLoc); appendArgument("IncludeTok", IncludeTok); @@ -488,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, - std::optional<FileEntryRef> Value) { + Optional<FileEntryRef> 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 c494556..8640146 100644 --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.h +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.h @@ -21,15 +21,14 @@ #ifndef PPTRACE_PPCALLBACKSTRACKER_H #define PPTRACE_PPCALLBACKSTRACKER_H -#include "clang/Basic/SourceManager.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" +#include "clang/Basic/SourceManager.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringMap.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/GlobPattern.h" -#include <optional> #include <string> #include <vector> @@ -95,7 +94,7 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, + Optional<FileEntryRef> File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -180,7 +179,7 @@ public: void appendArgument(const char *Name, FileID Value); /// Append a FileEntryRef argument to the top trace item. - void appendArgument(const char *Name, std::optional<FileEntryRef> Value); + void appendArgument(const char *Name, Optional<FileEntryRef> Value); void appendArgument(const char *Name, FileEntryRef Value); /// Append a SourceLocation argument to the top trace item. diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 3a22bba..9f00cfa 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -24,7 +24,6 @@ #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem/UniqueID.h" -#include <optional> #include <utility> namespace llvm { @@ -295,9 +294,9 @@ namespace clang { /// /// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and /// FileEntry::getName have been deleted, delete this class and replace -/// instances with std::optional<FileEntryRef>. +/// instances with Optional<FileEntryRef>. class OptionalFileEntryRefDegradesToFileEntryPtr - : public std::optional<FileEntryRef> { + : public Optional<FileEntryRef> { public: OptionalFileEntryRefDegradesToFileEntryPtr() = default; OptionalFileEntryRefDegradesToFileEntryPtr( @@ -311,74 +310,50 @@ public: OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {} OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref) - : std::optional<FileEntryRef>(Ref) {} - OptionalFileEntryRefDegradesToFileEntryPtr( - std::optional<FileEntryRef> MaybeRef) - : std::optional<FileEntryRef>(MaybeRef) {} + : Optional<FileEntryRef>(Ref) {} + OptionalFileEntryRefDegradesToFileEntryPtr(Optional<FileEntryRef> MaybeRef) + : Optional<FileEntryRef>(MaybeRef) {} OptionalFileEntryRefDegradesToFileEntryPtr &operator=(std::nullopt_t) { - std::optional<FileEntryRef>::operator=(std::nullopt); + Optional<FileEntryRef>::operator=(std::nullopt); return *this; } OptionalFileEntryRefDegradesToFileEntryPtr &operator=(FileEntryRef Ref) { - std::optional<FileEntryRef>::operator=(Ref); + Optional<FileEntryRef>::operator=(Ref); return *this; } OptionalFileEntryRefDegradesToFileEntryPtr & - operator=(std::optional<FileEntryRef> MaybeRef) { - std::optional<FileEntryRef>::operator=(MaybeRef); + operator=(Optional<FileEntryRef> MaybeRef) { + Optional<FileEntryRef>::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 std::optional<FileEntryRef> + /// instances with Optional<FileEntryRef> operator const FileEntry *() const { return has_value() ? &(*this)->getFileEntry() : nullptr; } }; -// Add these operators to resolve ambiguities appearing after replacing -// llvm::Optional with std::optional. -constexpr bool operator==(const std::optional<FileEntryRef> &X, - const std::optional<FileEntryRef> &Y) { - // Copied from llvm::Optional. - if (X && Y) - return *X == *Y; - return X.has_value() == Y.has_value(); -} -constexpr bool operator==(const OptionalFileEntryRefDegradesToFileEntryPtr &X, - const OptionalFileEntryRefDegradesToFileEntryPtr &Y) { - return static_cast<const std::optional<FileEntryRef> &>(X) == - static_cast<const std::optional<FileEntryRef> &>(Y); -} -constexpr bool operator==(const OptionalFileEntryRefDegradesToFileEntryPtr &X, - const std::optional<FileEntryRef> &Y) { - return static_cast<const std::optional<FileEntryRef> &>(X) == Y; -} -constexpr bool operator==(const std::optional<FileEntryRef> &X, - const OptionalFileEntryRefDegradesToFileEntryPtr &Y) { - return X == static_cast<const std::optional<FileEntryRef> &>(Y); -} - static_assert( std::is_trivially_copyable< OptionalFileEntryRefDegradesToFileEntryPtr>::value, "OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable"); inline bool operator==(const FileEntry *LHS, - const std::optional<FileEntryRef> &RHS) { + const Optional<FileEntryRef> &RHS) { return LHS == (RHS ? &RHS->getFileEntry() : nullptr); } -inline bool operator==(const std::optional<FileEntryRef> &LHS, +inline bool operator==(const Optional<FileEntryRef> &LHS, const FileEntry *RHS) { return (LHS ? &LHS->getFileEntry() : nullptr) == RHS; } inline bool operator!=(const FileEntry *LHS, - const std::optional<FileEntryRef> &RHS) { + const Optional<FileEntryRef> &RHS) { return !(LHS == RHS); } -inline bool operator!=(const std::optional<FileEntryRef> &LHS, +inline bool operator!=(const Optional<FileEntryRef> &LHS, const FileEntry *RHS) { return !(LHS == RHS); } diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index 43cda9d..ec62e00 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -31,7 +31,6 @@ #include <ctime> #include <map> #include <memory> -#include <optional> #include <string> namespace llvm { @@ -232,10 +231,10 @@ public: llvm::Expected<FileEntryRef> getSTDIN(); /// Get a FileEntryRef if it exists, without doing anything on error. - std::optional<FileEntryRef> getOptionalFileRef(StringRef Filename, - bool OpenFile = false, - bool CacheFailure = true) { - return llvm::expectedToStdOptional( + llvm::Optional<FileEntryRef> getOptionalFileRef(StringRef Filename, + bool OpenFile = false, + bool CacheFailure = true) { + return llvm::expectedToOptional( getFileRef(Filename, OpenFile, CacheFailure)); } @@ -271,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. - std::optional<FileEntryRef> getBypassFile(FileEntryRef VFE); + llvm::Optional<FileEntryRef> 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/Module.h b/clang/include/clang/Basic/Module.h index 02312cd..c41ae41 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -33,7 +33,6 @@ #include <cstdint> #include <ctime> #include <iterator> -#include <optional> #include <string> #include <utility> #include <vector> @@ -186,7 +185,7 @@ private: /// The AST file if this is a top-level module which has a /// corresponding serialized AST file, or null otherwise. - std::optional<FileEntryRef> ASTFile; + Optional<FileEntryRef> ASTFile; /// The top-level headers associated with this module. llvm::SmallSetVector<const FileEntry *, 2> TopHeaders; @@ -611,7 +610,7 @@ public: } /// Set the serialized AST file for the top-level module of this module. - void setASTFile(std::optional<FileEntryRef> File) { + void setASTFile(Optional<FileEntryRef> 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 8b16ab5..20f2415 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -53,7 +53,6 @@ #include <cstddef> #include <map> #include <memory> -#include <optional> #include <string> #include <utility> #include <vector> @@ -1004,7 +1003,7 @@ public: /// is no such file in the filesystem. /// /// This should be called before parsing has begun. - std::optional<FileEntryRef> bypassFileContentsOverride(FileEntryRef File); + Optional<FileEntryRef> bypassFileContentsOverride(FileEntryRef File); /// Specify that a file is transient. void setFileIsTransient(const FileEntry *SourceFile); @@ -1050,7 +1049,7 @@ public: } /// Returns the FileEntryRef for the provided FileID. - std::optional<FileEntryRef> getFileEntryRefForID(FileID FID) const { + Optional<FileEntryRef> 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 ed54fba..375e525 100644 --- a/clang/include/clang/Lex/DirectoryLookup.h +++ b/clang/include/clang/Lex/DirectoryLookup.h @@ -13,11 +13,10 @@ #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H -#include "clang/Basic/FileManager.h" #include "clang/Basic/LLVM.h" +#include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/ModuleMap.h" -#include <optional> namespace clang { class HeaderMap; @@ -181,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. - std::optional<FileEntryRef> + Optional<FileEntryRef> LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, @@ -191,7 +190,7 @@ public: bool OpenFile = true) const; private: - std::optional<FileEntryRef> DoFrameworkLookup( + Optional<FileEntryRef> DoFrameworkLookup( StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 637a24c..4684f55 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -28,7 +28,6 @@ #include <cassert> #include <cstddef> #include <memory> -#include <optional> #include <string> #include <utility> #include <vector> @@ -480,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. - std::optional<FileEntryRef> LookupFile( + Optional<FileEntryRef> LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir, ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers, @@ -496,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. - std::optional<FileEntryRef> LookupSubframeworkHeader( + Optional<FileEntryRef> LookupSubframeworkHeader( StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule); @@ -770,7 +769,7 @@ private: /// Look up the file with the specified name and determine its owning /// module. - std::optional<FileEntryRef> + Optional<FileEntryRef> 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 1b83321..8c8fa4d 100644 --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -30,7 +30,6 @@ #include "llvm/ADT/Twine.h" #include <ctime> #include <memory> -#include <optional> #include <string> #include <utility> @@ -607,8 +606,7 @@ public: /// /// \returns The file entry for the module map file containing the given /// module, or nullptr if the module definition was inferred. - std::optional<FileEntryRef> - getContainingModuleMapFile(const Module *Module) const; + Optional<FileEntryRef> getContainingModuleMapFile(const Module *Module) const; /// Get the module map file that (along with the module name) uniquely /// identifies this module. @@ -619,8 +617,7 @@ public: /// of inferred modules, returns the module map that allowed the inference /// (e.g. contained 'module *'). Otherwise, returns /// getContainingModuleMapFile(). - std::optional<FileEntryRef> - getModuleMapFileForUniquing(const Module *M) const; + Optional<FileEntryRef> 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 744da1a..045df87 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -20,7 +20,6 @@ #include "clang/Lex/ModuleLoader.h" #include "clang/Lex/Pragma.h" #include "llvm/ADT/StringRef.h" -#include <optional> namespace clang { class Token; @@ -126,12 +125,16 @@ public: /// implicitly 'extern "C"' in C++ mode. /// virtual void InclusionDirective(SourceLocation HashLoc, - const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, + const Token &IncludeTok, + StringRef FileName, + bool IsAngled, + CharSourceRange FilenameRange, + Optional<FileEntryRef> File, + StringRef SearchPath, + StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) {} + SrcMgr::CharacteristicKind FileType) { + } /// Callback invoked whenever a submodule was entered. /// @@ -324,7 +327,7 @@ public: /// Hook called when a '__has_include' or '__has_include_next' directive is /// read. virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, - std::optional<FileEntryRef> File, + Optional<FileEntryRef> File, SrcMgr::CharacteristicKind FileType); /// Hook called when a source range is skipped. @@ -455,9 +458,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath, RelativePath, @@ -546,7 +548,7 @@ public: } void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, - std::optional<FileEntryRef> File, + Optional<FileEntryRef> 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 66ca5d3..ee22f1e 100644 --- a/clang/include/clang/Lex/PreprocessingRecord.h +++ b/clang/include/clang/Lex/PreprocessingRecord.h @@ -29,7 +29,6 @@ #include <cassert> #include <cstddef> #include <iterator> -#include <optional> #include <utility> #include <vector> @@ -241,12 +240,12 @@ class Token; unsigned ImportedModule : 1; /// The file that was included. - std::optional<FileEntryRef> File; + Optional<FileEntryRef> File; public: InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, - std::optional<FileEntryRef> File, SourceRange Range); + Optional<FileEntryRef> File, SourceRange Range); /// Determine what kind of inclusion directive this is. InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); } @@ -264,7 +263,7 @@ class Token; /// Retrieve the file entry for the actual file that was included /// by this directive. - std::optional<FileEntryRef> getFile() const { return File; } + Optional<FileEntryRef> getFile() const { return File; } // Implement isa/cast/dyncast/etc. static bool classof(const PreprocessedEntity *PE) { @@ -529,9 +528,8 @@ class Token; void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override; diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index ab481c5..05e05e8 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -51,7 +51,6 @@ #include <cstdint> #include <map> #include <memory> -#include <optional> #include <string> #include <utility> #include <vector> @@ -2244,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 ""). - std::optional<FileEntryRef> + Optional<FileEntryRef> LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDir, SmallVectorImpl<char> *SearchPath, @@ -2511,7 +2510,7 @@ private: } }; - std::optional<FileEntryRef> LookupHeaderIncludeOrImport( + Optional<FileEntryRef> 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 1db9e96..5f453c3 100644 --- a/clang/include/clang/Serialization/ModuleManager.h +++ b/clang/include/clang/Serialization/ModuleManager.h @@ -29,7 +29,6 @@ #include <cstdint> #include <ctime> #include <memory> -#include <optional> #include <string> #include <utility> @@ -303,8 +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, - std::optional<FileEntryRef> &File); + time_t ExpectedModTime, Optional<FileEntryRef> &File); /// View the graphviz representation of the module graph. void viewGraph(); diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h index cfa0135..1cc6208 100644 --- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h +++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h @@ -19,7 +19,6 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/raw_ostream.h" -#include <optional> #include <string> #include <unordered_map> @@ -135,9 +134,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override; diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index e96771f..d690d4c 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "Transforms.h" +#include "clang/Analysis/RetainSummaryManager.h" #include "clang/ARCMigrate/ARCMT.h" #include "clang/ARCMigrate/ARCMTActions.h" #include "clang/AST/ASTConsumer.h" @@ -16,7 +17,6 @@ #include "clang/AST/ParentMap.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Analysis/DomainSpecific/CocoaConventions.h" -#include "clang/Analysis/RetainSummaryManager.h" #include "clang/Basic/FileManager.h" #include "clang/Edit/Commit.h" #include "clang/Edit/EditedSource.h" @@ -32,7 +32,6 @@ #include "llvm/Support/Path.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLParser.h" -#include <optional> using namespace clang; using namespace arcmt; @@ -157,7 +156,7 @@ protected: return AllowListFilenames.find(llvm::sys::path::filename(Path)) != AllowListFilenames.end(); } - bool canModifyFile(std::optional<FileEntryRef> FE) { + bool canModifyFile(Optional<FileEntryRef> FE) { if (!FE) return false; return canModifyFile(FE->getName()); @@ -1959,8 +1958,7 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { FileID FID = I->first; RewriteBuffer &buf = I->second; - std::optional<FileEntryRef> file = - Ctx.getSourceManager().getFileEntryRefForID(FID); + Optional<FileEntryRef> file = Ctx.getSourceManager().getFileEntryRefForID(FID); assert(file); SmallString<512> newText; llvm::raw_svector_ostream vecOS(newText); @@ -2030,7 +2028,7 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { namespace { struct EditEntry { - std::optional<FileEntryRef> File; + Optional<FileEntryRef> 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 1d96093..4fefbaa 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); } -std::optional<FileEntryRef> FileManager::getBypassFile(FileEntryRef VF) { +llvm::Optional<FileEntryRef> 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 c9312c6..8eca151 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -38,7 +38,6 @@ #include <cstddef> #include <cstdint> #include <memory> -#include <optional> #include <tuple> #include <utility> #include <vector> @@ -713,10 +712,10 @@ void SourceManager::overrideFileContents(const FileEntry *SourceFile, Pair.first->second = NewFile; } -std::optional<FileEntryRef> +Optional<FileEntryRef> SourceManager::bypassFileContentsOverride(FileEntryRef File) { assert(isFileOverridden(&File.getFileEntry())); - std::optional<FileEntryRef> BypassFile = FileMgr.getBypassFile(File); + llvm::Optional<FileEntryRef> BypassFile = FileMgr.getBypassFile(File); // If the file can't be found in the FS, give up. if (!BypassFile) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 2bd7faa..382b7f3 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 (std::optional<FileEntryRef> MainFile = + if (Optional<FileEntryRef> 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 f7cb2d0..563d540 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -36,7 +36,6 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/ConvertUTF.h" #include <cctype> -#include <optional> using namespace clang; using namespace CodeGen; @@ -3865,7 +3864,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() { // The path to the source file where this module was declared SourceManager &SM = CGM.getContext().getSourceManager(); - std::optional<FileEntryRef> mainFile = + Optional<FileEntryRef> mainFile = SM.getFileEntryRefForID(SM.getMainFileID()); std::string path = (mainFile->getDir().getName() + "/" + mainFile->getName()).str(); diff --git a/clang/lib/CodeGen/MacroPPCallbacks.cpp b/clang/lib/CodeGen/MacroPPCallbacks.cpp index c5e5556..076d299 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.cpp +++ b/clang/lib/CodeGen/MacroPPCallbacks.cpp @@ -15,7 +15,6 @@ #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Preprocessor.h" -#include <optional> using namespace clang; @@ -168,9 +167,8 @@ void MacroPPCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason, void MacroPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { // Record the line location of the current included file. diff --git a/clang/lib/CodeGen/MacroPPCallbacks.h b/clang/lib/CodeGen/MacroPPCallbacks.h index f16521c..01041b16 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.h +++ b/clang/lib/CodeGen/MacroPPCallbacks.h @@ -14,7 +14,6 @@ #define LLVM_CLANG_LIB_CODEGEN_MACROPPCALLBACKS_H #include "clang/Lex/PPCallbacks.h" -#include <optional> namespace llvm { class DIMacroFile; @@ -102,9 +101,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; /// Hook called whenever a macro definition is seen. diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index 8238779..acb3cb8 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. - std::optional<FileEntryRef> ToFile = FileMgr.getOptionalFileRef(RF.second); + Optional<FileEntryRef> 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 std::optional<FileEntryRef> getPublicModuleMap(FileEntryRef File, - FileManager &FileMgr) { +static Optional<FileEntryRef> 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 (std::optional<FileEntryRef> ModuleMapFile = + if (Optional<FileEntryRef> 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 (std::optional<FileEntryRef> PublicMMFile = getPublicModuleMap( + if (Optional<FileEntryRef> PublicMMFile = getPublicModuleMap( *ModuleMapFile, ImportingInstance.getFileManager())) ModuleMapFile = PublicMMFile; diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 500c08c..8d712a2 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -10,11 +10,11 @@ // //===----------------------------------------------------------------------===// +#include "clang/Frontend/Utils.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/DependencyOutputOptions.h" #include "clang/Frontend/FrontendDiagnostic.h" -#include "clang/Frontend/Utils.h" #include "clang/Lex/DirectoryLookup.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PPCallbacks.h" @@ -24,7 +24,6 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include <optional> using namespace clang; @@ -65,9 +64,8 @@ struct DepCollectorPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { if (!File) DepCollector.maybeAddDependency(FileName, /*FromModule*/false, @@ -77,7 +75,7 @@ struct DepCollectorPPCallbacks : public PPCallbacks { } void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled, - std::optional<FileEntryRef> File, + Optional<FileEntryRef> File, SrcMgr::CharacteristicKind FileType) override { if (!File) return; diff --git a/clang/lib/Frontend/DependencyGraph.cpp b/clang/lib/Frontend/DependencyGraph.cpp index ccf34ac..4cbdb3d 100644 --- a/clang/lib/Frontend/DependencyGraph.cpp +++ b/clang/lib/Frontend/DependencyGraph.cpp @@ -11,16 +11,15 @@ // //===----------------------------------------------------------------------===// +#include "clang/Frontend/Utils.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/FrontendDiagnostic.h" -#include "clang/Frontend/Utils.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/SetVector.h" #include "llvm/Support/GraphWriter.h" #include "llvm/Support/raw_ostream.h" -#include <optional> using namespace clang; namespace DOT = llvm::DOT; @@ -49,9 +48,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override { @@ -68,16 +66,21 @@ void clang::AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, } void DependencyGraphCallback::InclusionDirective( - SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + SourceLocation HashLoc, + const Token &IncludeTok, + StringRef FileName, + bool IsAngled, + CharSourceRange FilenameRange, + Optional<FileEntryRef> File, + StringRef SearchPath, + StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!File) return; SourceManager &SM = PP->getSourceManager(); - std::optional<FileEntryRef> FromFile = + Optional<FileEntryRef> 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 a3b4080..e97a2dd 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -40,7 +40,6 @@ #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include <memory> -#include <optional> #include <system_error> using namespace clang; @@ -824,7 +823,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, Dir = *DirOrErr; SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 1> CWD; CWD.push_back({nullptr, Dir}); - std::optional<FileEntryRef> FE = + Optional<FileEntryRef> 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 785bff7..7e19ed3 100644 --- a/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -19,7 +19,6 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" -#include <optional> using namespace clang; @@ -49,9 +48,8 @@ struct ModuleDependencyPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { if (!File) return; diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index 9da3306..e3c3466 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -33,7 +33,6 @@ #include "llvm/Support/VirtualFileSystem.h" #include <limits> #include <mutex> -#include <optional> #include <utility> using namespace clang; @@ -98,9 +97,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { // File is None if it wasn't found. // (We have some false negatives if PP recovered e.g. <foo> -> "foo") diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index 8274a2f..d81a11a 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -11,11 +11,11 @@ // //===----------------------------------------------------------------------===// +#include "clang/Frontend/Utils.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/PreprocessorOutputOptions.h" -#include "clang/Frontend/Utils.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Pragma.h" @@ -27,7 +27,6 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include <cstdio> -#include <optional> using namespace clang; /// PrintMacroDefinition - Print a macro definition in a form that will be @@ -147,9 +146,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void Ident(SourceLocation Loc, StringRef str) override; void PragmaMessage(SourceLocation Loc, StringRef Namespace, @@ -391,10 +389,15 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, } void PrintPPOutputPPCallbacks::InclusionDirective( - SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + SourceLocation HashLoc, + const Token &IncludeTok, + StringRef FileName, + bool IsAngled, + CharSourceRange FilenameRange, + Optional<FileEntryRef> 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 7fa2328..37178d1 100644 --- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -74,9 +74,8 @@ private: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override; @@ -183,12 +182,16 @@ 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*/, std::optional<FileEntryRef> /*File*/, - StringRef /*SearchPath*/, StringRef /*RelativePath*/, - const Module *Imported, SrcMgr::CharacteristicKind FileType) { +void InclusionRewriter::InclusionDirective(SourceLocation HashLoc, + const Token &/*IncludeTok*/, + StringRef /*FileName*/, + bool /*IsAngled*/, + CharSourceRange /*FilenameRange*/, + Optional<FileEntryRef> /*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 b6e2533..f67dcee 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -40,7 +40,6 @@ #include <cstring> #include <iterator> #include <memory> -#include <optional> #include <string> #include <utility> #include <vector> @@ -542,7 +541,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, ExpectedLoc = SourceLocation(); } else { // Lookup file via Preprocessor, like a #include. - std::optional<FileEntryRef> File = + Optional<FileEntryRef> File = PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (!File) { diff --git a/clang/lib/Index/IndexingAction.cpp b/clang/lib/Index/IndexingAction.cpp index a958b64..c9fcaad 100644 --- a/clang/lib/Index/IndexingAction.cpp +++ b/clang/lib/Index/IndexingAction.cpp @@ -17,7 +17,6 @@ #include "clang/Serialization/ASTReader.h" #include "llvm/ADT/STLExtras.h" #include <memory> -#include <optional> using namespace clang; using namespace clang::index; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index ffb2780..1ce6df4 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -25,11 +25,11 @@ #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/Hashing.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringRef.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Errc.h" @@ -42,7 +42,6 @@ #include <cstddef> #include <cstdio> #include <cstring> -#include <optional> #include <string> #include <system_error> #include <utility> @@ -172,7 +171,7 @@ void HeaderSearch::getHeaderMapFileNames( } std::string HeaderSearch::getCachedModuleFileName(Module *Module) { - std::optional<FileEntryRef> ModuleMap = + Optional<FileEntryRef> 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. @@ -213,7 +212,7 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName, } std::string HeaderSearch::getPrebuiltImplicitModuleFileName(Module *Module) { - std::optional<FileEntryRef> ModuleMap = + Optional<FileEntryRef> ModuleMap = getModuleMap().getModuleMapFileForUniquing(Module); StringRef ModuleName = Module->Name; StringRef ModuleMapPath = ModuleMap->getName(); @@ -416,7 +415,7 @@ StringRef DirectoryLookup::getName() const { return getHeaderMap()->getFileName(); } -std::optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule( +Optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule( StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir, bool IsSystemHeaderDir, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool OpenFile /*=true*/, @@ -448,7 +447,7 @@ std::optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule( /// LookupFile - Lookup the specified file in this search path, returning it /// if it exists or returning null if not. -std::optional<FileEntryRef> DirectoryLookup::LookupFile( +Optional<FileEntryRef> DirectoryLookup::LookupFile( StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, @@ -587,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. -std::optional<FileEntryRef> DirectoryLookup::DoFrameworkLookup( +Optional<FileEntryRef> DirectoryLookup::DoFrameworkLookup( StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, @@ -856,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. -std::optional<FileEntryRef> HeaderSearch::LookupFile( +Optional<FileEntryRef> HeaderSearch::LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg, ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers, @@ -899,7 +898,7 @@ std::optional<FileEntryRef> HeaderSearch::LookupFile( // This is the header that MSVC's header search would have found. ModuleMap::KnownHeader MSSuggestedModule; - std::optional<FileEntryRef> MSFE; + Optional<FileEntryRef> 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 @@ -928,7 +927,7 @@ std::optional<FileEntryRef> HeaderSearch::LookupFile( bool IncluderIsSystemHeader = Includer ? getFileInfo(Includer).DirInfo != SrcMgr::C_User : BuildSystemModule; - if (std::optional<FileEntryRef> FE = getFileAndSuggestModule( + if (Optional<FileEntryRef> FE = getFileAndSuggestModule( TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader, RequestingModule, SuggestedModule)) { if (!Includer) { @@ -1044,7 +1043,7 @@ std::optional<FileEntryRef> HeaderSearch::LookupFile( bool InUserSpecifiedSystemFramework = false; bool IsInHeaderMap = false; bool IsFrameworkFoundInDir = false; - std::optional<FileEntryRef> File = It->LookupFile( + Optional<FileEntryRef> File = It->LookupFile( Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule, SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir, IsInHeaderMap, MappedName, OpenFile); @@ -1139,7 +1138,7 @@ std::optional<FileEntryRef> HeaderSearch::LookupFile( ScratchFilename += '/'; ScratchFilename += Filename; - std::optional<FileEntryRef> File = LookupFile( + Optional<FileEntryRef> File = LookupFile( ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, &CurDir, Includers.front(), SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, /*IsFrameworkFound=*/nullptr); @@ -1176,7 +1175,7 @@ std::optional<FileEntryRef> HeaderSearch::LookupFile( /// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox /// is a subframework within Carbon.framework. If so, return the FileEntry /// for the designated file, otherwise return null. -std::optional<FileEntryRef> HeaderSearch::LookupSubframeworkHeader( +Optional<FileEntryRef> HeaderSearch::LookupSubframeworkHeader( StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule) { diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index c061790..f5a7f51 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -46,7 +46,6 @@ #include <cassert> #include <cstdint> #include <cstring> -#include <optional> #include <string> #include <system_error> #include <utility> @@ -1259,7 +1258,7 @@ void ModuleMap::addHeader(Module *Mod, Module::Header Header, Cb->moduleMapAddHeader(Header.Entry->getName()); } -std::optional<FileEntryRef> +Optional<FileEntryRef> ModuleMap::getContainingModuleMapFile(const Module *Module) const { if (Module->DefinitionLoc.isInvalid()) return std::nullopt; @@ -1268,7 +1267,7 @@ ModuleMap::getContainingModuleMapFile(const Module *Module) const { SourceMgr.getFileID(Module->DefinitionLoc)); } -std::optional<FileEntryRef> +Optional<FileEntryRef> 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 9c98669..b618071 100644 --- a/clang/lib/Lex/PPCallbacks.cpp +++ b/clang/lib/Lex/PPCallbacks.cpp @@ -8,7 +8,6 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Basic/FileManager.h" -#include <optional> using namespace clang; @@ -16,16 +15,16 @@ using namespace clang; PPCallbacks::~PPCallbacks() = default; void PPCallbacks::HasInclude(SourceLocation Loc, StringRef FileName, - bool IsAngled, std::optional<FileEntryRef> File, + bool IsAngled, Optional<FileEntryRef> File, SrcMgr::CharacteristicKind FileType) {} // Out of line key method. PPChainedCallbacks::~PPChainedCallbacks() = default; void PPChainedCallbacks::HasInclude(SourceLocation Loc, StringRef FileName, - bool IsAngled, - std::optional<FileEntryRef> File, + bool IsAngled, Optional<FileEntryRef> 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 fcac1bf..5264c00 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -47,7 +47,6 @@ #include <cassert> #include <cstring> #include <new> -#include <optional> #include <string> #include <utility> @@ -948,7 +947,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc, return nullptr; } -std::optional<FileEntryRef> Preprocessor::LookupFile( +Optional<FileEntryRef> Preprocessor::LookupFile( SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDirArg, SmallVectorImpl<char> *SearchPath, @@ -1013,7 +1012,7 @@ std::optional<FileEntryRef> Preprocessor::LookupFile( // the include path until we find that file or run out of files. ConstSearchDirIterator TmpCurDir = CurDir; ConstSearchDirIterator TmpFromDir = nullptr; - while (std::optional<FileEntryRef> FE = HeaderInfo.LookupFile( + while (Optional<FileEntryRef> FE = HeaderInfo.LookupFile( Filename, FilenameLoc, isAngled, TmpFromDir, &TmpCurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, /*IsMapped=*/nullptr, @@ -1031,7 +1030,7 @@ std::optional<FileEntryRef> Preprocessor::LookupFile( } // Do a standard file entry lookup. - std::optional<FileEntryRef> FE = HeaderInfo.LookupFile( + Optional<FileEntryRef> FE = HeaderInfo.LookupFile( Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures); @@ -1049,7 +1048,7 @@ std::optional<FileEntryRef> Preprocessor::LookupFile( // headers on the #include stack and pass them to HeaderInfo. if (IsFileLexer()) { if ((CurFileEnt = CurPPLexer->getFileEntry())) { - if (std::optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader( + if (Optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader( Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule, SuggestedModule)) { if (SuggestedModule && !LangOpts.AsmPreprocessor) @@ -1064,10 +1063,9 @@ std::optional<FileEntryRef> Preprocessor::LookupFile( for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) { if (IsFileLexer(ISEntry)) { if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) { - if (std::optional<FileEntryRef> FE = - HeaderInfo.LookupSubframeworkHeader( - Filename, CurFileEnt, SearchPath, RelativePath, - RequestingModule, SuggestedModule)) { + if (Optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader( + Filename, CurFileEnt, SearchPath, RelativePath, + RequestingModule, SuggestedModule)) { if (SuggestedModule && !LangOpts.AsmPreprocessor) HeaderInfo.getModuleMap().diagnoseHeaderInclusion( RequestingModule, RequestingModuleIsModuleInterface, @@ -2005,7 +2003,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, } } -std::optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( +Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( ConstSearchDirIterator *CurDir, StringRef &Filename, SourceLocation FilenameLoc, CharSourceRange FilenameRange, const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl, @@ -2013,8 +2011,9 @@ std::optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( const FileEntry *LookupFromFile, StringRef &LookupFilename, SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath, ModuleMap::KnownHeader &SuggestedModule, bool isAngled) { - std::optional<FileEntryRef> File = LookupFile( - FilenameLoc, LookupFilename, isAngled, LookupFrom, LookupFromFile, CurDir, + Optional<FileEntryRef> File = LookupFile( + FilenameLoc, LookupFilename, + isAngled, LookupFrom, LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, &IsFrameworkFound); if (File) @@ -2027,8 +2026,9 @@ std::optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( // brackets, we can attempt a lookup as though it were a quoted path to // provide the user with a possible fixit. if (isAngled) { - std::optional<FileEntryRef> File = LookupFile( - FilenameLoc, LookupFilename, false, LookupFrom, LookupFromFile, CurDir, + Optional<FileEntryRef> File = LookupFile( + FilenameLoc, LookupFilename, + false, LookupFrom, LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, /*IsFrameworkFound=*/nullptr); @@ -2057,9 +2057,9 @@ std::optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( StringRef TypoCorrectionName = CorrectTypoFilename(Filename); StringRef TypoCorrectionLookupName = CorrectTypoFilename(LookupFilename); - std::optional<FileEntryRef> File = LookupFile( - FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom, - LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, + Optional<FileEntryRef> File = LookupFile( + FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom, LookupFromFile, + CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, /*IsFrameworkFound=*/nullptr); if (File) { @@ -2182,7 +2182,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( BackslashStyle = llvm::sys::path::Style::windows; } - std::optional<FileEntryRef> File = LookupHeaderIncludeOrImport( + Optional<FileEntryRef> 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 b68a455..36d3aa5 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -22,7 +22,6 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBufferRef.h" #include "llvm/Support/Path.h" -#include <optional> using namespace clang; @@ -95,8 +94,7 @@ bool Preprocessor::EnterSourceFile(FileID FID, ConstSearchDirIterator CurDir, Lexer *TheLexer = new Lexer(FID, *InputFile, *this, IsFirstIncludeOfFile); if (getPreprocessorOpts().DependencyDirectivesForFile && FID != PredefinesFileID) { - if (std::optional<FileEntryRef> File = - SourceMgr.getFileEntryRefForID(FID)) { + if (Optional<FileEntryRef> File = SourceMgr.getFileEntryRefForID(FID)) { if (Optional<ArrayRef<dependency_directives_scan::Directive>> DepDirectives = getPreprocessorOpts().DependencyDirectivesForFile(*File)) { diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index 6f85d93..c33c9d1 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -53,7 +53,6 @@ #include <cstddef> #include <cstring> #include <ctime> -#include <optional> #include <string> #include <tuple> #include <utility> @@ -1250,7 +1249,7 @@ static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II, return false; // Search include directories. - std::optional<FileEntryRef> File = + Optional<FileEntryRef> 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 e55fbb5..01e0dbe 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -48,7 +48,6 @@ #include <cstddef> #include <cstdint> #include <limits> -#include <optional> #include <string> #include <utility> #include <vector> @@ -528,7 +527,7 @@ void Preprocessor::HandlePragmaDependency(Token &DependencyTok) { return; // Search include directories for this file. - std::optional<FileEntryRef> File = + Optional<FileEntryRef> 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 1d5a291..35f9e4d 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -31,7 +31,6 @@ #include <cstddef> #include <cstring> #include <iterator> -#include <optional> #include <utility> #include <vector> @@ -43,7 +42,7 @@ ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() = InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, - std::optional<FileEntryRef> File, + Optional<FileEntryRef> File, SourceRange Range) : PreprocessingDirective(InclusionDirectiveKind, Range), InQuotes(InQuotes), Kind(Kind), ImportedModule(ImportedModule), File(File) { @@ -476,10 +475,15 @@ void PreprocessingRecord::MacroUndefined(const Token &Id, } void PreprocessingRecord::InclusionDirective( - SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + SourceLocation HashLoc, + const Token &IncludeTok, + StringRef FileName, + bool IsAngled, + CharSourceRange FilenameRange, + Optional<FileEntryRef> 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 b1cb81c..281683b 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -65,7 +65,6 @@ #include <algorithm> #include <cassert> #include <memory> -#include <optional> #include <string> #include <utility> #include <vector> @@ -581,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. - std::optional<FileEntryRef> File = LookupFile( + Optional<FileEntryRef> 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 3383bdb..bb045760 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -15,7 +15,6 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/SemaInternal.h" -#include <optional> using namespace clang; using namespace sema; @@ -321,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 (std::optional<FileEntryRef> FE = M->getASTFile()) + else if (Optional<FileEntryRef> 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 4b765b3..63c525a 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -135,7 +135,6 @@ #include <limits> #include <map> #include <memory> -#include <optional> #include <string> #include <system_error> #include <tuple> @@ -1521,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); - std::optional<FileEntryRef> File = IF.getFile(); + Optional<FileEntryRef> File = IF.getFile(); bool OverriddenBuffer = IF.isOverridden(); // Note that we only check if a File was returned. If it was out-of-date @@ -2363,7 +2362,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { uint64_t StoredContentHash = FI.ContentHash; OptionalFileEntryRefDegradesToFileEntryPtr File = - expectedToStdOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)); + expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)); // For an overridden file, create a virtual file with the stored // size/timestamp. @@ -3965,7 +3964,7 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName, F.ImportLoc); auto &Map = PP.getHeaderSearchInfo().getModuleMap(); - std::optional<FileEntryRef> ModMap = + Optional<FileEntryRef> ModMap = M ? Map.getModuleMapFileForUniquing(M) : std::nullopt; // Don't emit module relocation error if we have -fno-validate-pch if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation & @@ -6127,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]); - std::optional<FileEntryRef> File; + Optional<FileEntryRef> File; if (!FullFileName.empty()) File = PP.getFileManager().getOptionalFileRef(FullFileName); diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index b9fa23b..ae4ea61 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -35,7 +35,6 @@ #include <algorithm> #include <cassert> #include <memory> -#include <optional> #include <string> #include <system_error> @@ -445,7 +444,7 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor, bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize, time_t ExpectedModTime, - std::optional<FileEntryRef> &File) { + Optional<FileEntryRef> &File) { File = std::nullopt; if (FileName == "-") return false; diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 6ab476b..e599681 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -14,7 +14,6 @@ #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h" #include "llvm/Support/BLAKE3.h" #include "llvm/Support/StringSaver.h" -#include <optional> using namespace clang; using namespace tooling; @@ -238,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 (std::optional<FileEntryRef> CurrentModuleMap = + if (Optional<FileEntryRef> CurrentModuleMap = PP.getHeaderSearchInfo() .getModuleMap() .getModuleMapFileForUniquing(CurrentModule)) @@ -335,9 +334,8 @@ void ModuleDepCollectorPP::FileChanged(SourceLocation Loc, void ModuleDepCollectorPP::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!File && !Imported) { // This is a non-modular include that HeaderSearch failed to find. Add it @@ -421,8 +419,7 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) { ModuleMap &ModMapInfo = MDC.ScanInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); - std::optional<FileEntryRef> ModuleMap = - ModMapInfo.getModuleMapFileForUniquing(M); + Optional<FileEntryRef> 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 37bca8c..9958671 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -57,7 +57,6 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/thread.h" #include <mutex> -#include <optional> #if LLVM_ENABLE_THREADS != 0 && defined(__APPLE__) #define USE_DARWIN_THREADS @@ -8532,7 +8531,7 @@ CXFile clang_getIncludedFile(CXCursor cursor) { return nullptr; const InclusionDirective *ID = getCursorInclusionDirective(cursor); - std::optional<FileEntryRef> File = ID->getFile(); + Optional<FileEntryRef> File = ID->getFile(); return const_cast<FileEntry *>(File ? &File->getFileEntry() : nullptr); } diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp index 0a30891..979acae 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.cpp +++ b/clang/tools/libclang/CXIndexDataConsumer.cpp @@ -14,7 +14,6 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclVisitor.h" #include "clang/Frontend/ASTUnit.h" -#include <optional> using namespace clang; using namespace clang::index; @@ -464,10 +463,10 @@ void CXIndexDataConsumer::enteredMainFile(const FileEntry *File) { } void CXIndexDataConsumer::ppIncludedFile(SourceLocation hashLoc, - StringRef filename, - std::optional<FileEntryRef> File, - bool isImport, bool isAngled, - bool isModuleImport) { + StringRef filename, + Optional<FileEntryRef> 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 3be37a2..04c64ca 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.h +++ b/clang/tools/libclang/CXIndexDataConsumer.h @@ -11,11 +11,10 @@ #include "CXCursor.h" #include "Index_Internal.h" +#include "clang/Index/IndexDataConsumer.h" #include "clang/AST/DeclGroup.h" #include "clang/AST/DeclObjC.h" -#include "clang/Index/IndexDataConsumer.h" #include "llvm/ADT/DenseSet.h" -#include <optional> namespace clang { class FileEntry; @@ -364,8 +363,8 @@ public: void enteredMainFile(const FileEntry *File); void ppIncludedFile(SourceLocation hashLoc, StringRef filename, - std::optional<FileEntryRef> File, bool isImport, - bool isAngled, bool isModuleImport); + Optional<FileEntryRef> File, bool isImport, bool isAngled, + bool isModuleImport); void importedModule(const ImportDecl *ImportD); void importedPCH(const FileEntry *File); diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index 752b7fb..206dd48 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -31,7 +31,6 @@ #include "llvm/Support/MemoryBuffer.h" #include <cstdio> #include <mutex> -#include <optional> #include <utility> using namespace clang; @@ -263,9 +262,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { bool isImport = (IncludeTok.is(tok::identifier) && IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import); diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index 6ccde51..6fe4a3d 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -14,7 +14,6 @@ #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" -#include <optional> using namespace llvm; using namespace clang; @@ -543,7 +542,7 @@ TEST_F(FileManagerTest, getBypassFile) { EXPECT_EQ(FE.getSize(), 10); // Bypass the file. - std::optional<FileEntryRef> BypassRef = + llvm::Optional<FileEntryRef> 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 a8d3aa3..43f7b4a 100644 --- a/clang/unittests/Lex/PPCallbacksTest.cpp +++ b/clang/unittests/Lex/PPCallbacksTest.cpp @@ -6,6 +6,7 @@ // //===--------------------------------------------------------------===// +#include "clang/Lex/Preprocessor.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/Diagnostic.h" @@ -18,14 +19,12 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleLoader.h" -#include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Parse/Parser.h" #include "clang/Sema/Sema.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Path.h" #include "gtest/gtest.h" -#include <optional> using namespace clang; @@ -37,9 +36,8 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - std::optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, - const Module *Imported, + Optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override { this->HashLoc = HashLoc; this->IncludeTok = IncludeTok; @@ -58,7 +56,7 @@ public: SmallString<16> FileName; bool IsAngled; CharSourceRange FilenameRange; - std::optional<FileEntryRef> File; + Optional<FileEntryRef> File; SmallString<16> SearchPath; SmallString<16> RelativePath; const Module* Imported; |