diff --git a/clang-tools-extra/clang-move/Move.cpp b/clang-tools-extra/clang-move/Move.cpp index 9e44fe12ecdcee..8fe1a99c1d774a 100644 --- a/clang-tools-extra/clang-move/Move.cpp +++ b/clang-tools-extra/clang-move/Move.cpp @@ -18,6 +18,7 @@ #include "clang/Tooling/Core/Replacement.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Path.h" +#include #define DEBUG_TYPE "clang-move" @@ -131,8 +132,8 @@ class FindAllIncludes : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token & /*IncludeTok*/, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional /*File*/, StringRef SearchPath, - StringRef /*RelativePath*/, + std::optional /*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 f88e24c10901c8..62a1700ef67b31 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp @@ -12,6 +12,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Serialization/ASTReader.h" +#include #define DEBUG_TYPE "clang-tidy" @@ -162,7 +163,7 @@ void ExpandModularHeadersPPCallbacks::FileChanged( void ExpandModularHeadersPPCallbacks::InclusionDirective( SourceLocation DirectiveLoc, const Token &IncludeToken, StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange, - Optional IncludedFile, StringRef SearchPath, + std::optional IncludedFile, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (Imported) { @@ -224,7 +225,8 @@ void ExpandModularHeadersPPCallbacks::PragmaDiagnostic(SourceLocation Loc, parseToLocation(Loc); } void ExpandModularHeadersPPCallbacks::HasInclude(SourceLocation Loc, StringRef, - bool, Optional, + bool, + std::optional, SrcMgr::CharacteristicKind) { parseToLocation(Loc); } diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h index 29f060507e53c8..7e616dcbbb194f 100644 --- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h +++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h @@ -12,6 +12,7 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/DenseSet.h" +#include namespace llvm { namespace vfs { @@ -69,7 +70,7 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation DirectiveLoc, const Token &IncludeToken, StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange, - Optional IncludedFile, + std::optional IncludedFile, StringRef SearchPath, StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -91,7 +92,8 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks { void PragmaDiagnosticPop(SourceLocation Loc, StringRef) override; void PragmaDiagnostic(SourceLocation Loc, StringRef, diag::Severity, StringRef) override; - void HasInclude(SourceLocation Loc, StringRef, bool, Optional , + void HasInclude(SourceLocation Loc, StringRef, bool, + std::optional, 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 c51fd53e334ccb..6a8214c57e77f1 100644 --- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp +++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp @@ -10,6 +10,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" +#include #include #include @@ -30,8 +31,9 @@ class KernelNameRestrictionPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FileNameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; @@ -62,7 +64,7 @@ void KernelNameRestrictionCheck::registerPPCallbacks(const SourceManager &SM, void KernelNameRestrictionPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &, StringRef FileName, bool, - CharSourceRange, Optional, StringRef, StringRef, + CharSourceRange, std::optional, 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 b8fbc6ed1e740a..08d2cf19a71c2d 100644 --- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp @@ -9,6 +9,7 @@ #include "SuspiciousIncludeCheck.h" #include "clang/AST/ASTContext.h" #include "clang/Lex/Preprocessor.h" +#include namespace clang { namespace tidy { @@ -25,8 +26,9 @@ class SuspiciousIncludePPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; private: @@ -72,8 +74,9 @@ void SuspiciousIncludeCheck::registerPPCallbacks( void SuspiciousIncludePPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import) return; @@ -93,7 +96,7 @@ void SuspiciousIncludePPCallbacks::InclusionDirective( llvm::sys::path::replace_extension(GuessedFileName, (HFE.size() ? "." : "") + HFE); - Optional File = + std::optional 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 f701bd182683c1..617dfb68623411 100644 --- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp @@ -13,6 +13,7 @@ #include "llvm/ADT/STLExtras.h" #include +#include namespace clang { namespace tidy { @@ -28,8 +29,9 @@ class IncludeOrderPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override; @@ -82,8 +84,9 @@ static int getPriority(StringRef Filename, bool IsAngled, bool IsMainModule) { void IncludeOrderPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional 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 62379f1214d84b..97b5bae6255214 100644 --- a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp @@ -12,6 +12,7 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/Preprocessor.h" +#include // FixItHint - Hint to check documentation script to mark this check as // providing a FixIt. @@ -34,8 +35,9 @@ class RestrictedIncludesPPCallbacks void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; private: @@ -46,8 +48,9 @@ class RestrictedIncludesPPCallbacks void RestrictedIncludesPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional 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 64e70ad746c59a..ea3e84dcdcf9c0 100644 --- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp @@ -15,6 +15,7 @@ #include "llvm/ADT/StringSet.h" #include +#include #include using IncludeMarker = @@ -33,8 +34,9 @@ class IncludeModernizePPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; private: @@ -179,8 +181,9 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks( void IncludeModernizePPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional 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 1c196a9a92749f..32489e03b5ff36 100644 --- a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace clang { @@ -119,8 +120,9 @@ class MacroToEnumCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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 7faf7ccce24052..c914d9cc24223e 100644 --- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp @@ -15,6 +15,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Path.h" #include +#include namespace clang { namespace tidy { @@ -22,8 +23,9 @@ namespace portability { void RestrictedIncludesPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional 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 2919b064f9406b..165aadb4db1496 100644 --- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h @@ -12,6 +12,7 @@ #include "../ClangTidyCheck.h" #include "../GlobList.h" #include "clang/Lex/PPCallbacks.h" +#include namespace clang { namespace tidy { @@ -51,8 +52,9 @@ class RestrictedIncludesPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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 22a4e4eeec6d7d..84b97d16bba210 100644 --- a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp @@ -12,6 +12,7 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallVector.h" #include +#include namespace clang { namespace tidy { @@ -48,8 +49,9 @@ class DuplicateIncludeCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void MacroDefined(const Token &MacroNameTok, @@ -77,8 +79,9 @@ void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc, void DuplicateIncludeCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional 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 08bbe9deca4067..f497f7906be83d 100644 --- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp +++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp @@ -10,6 +10,7 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "clang/Lex/Token.h" +#include namespace clang { namespace tidy { @@ -24,7 +25,7 @@ class IncludeInserterCallback : public PPCallbacks { void InclusionDirective(SourceLocation HashLocation, const Token &IncludeToken, StringRef FileNameRef, bool IsAngled, CharSourceRange FileNameRange, - Optional /*IncludedFile*/, + std::optional /*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 4314ef15d3eb3d..a4647b34ecdb3f 100644 --- a/clang-tools-extra/clangd/Headers.cpp +++ b/clang-tools-extra/clangd/Headers.cpp @@ -19,6 +19,7 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Path.h" #include +#include namespace clang { namespace clangd { @@ -35,7 +36,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks, void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange /*FilenameRange*/, - Optional File, + std::optional 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 4e99365facb613..edb46cf116833f 100644 --- a/clang-tools-extra/clangd/ParsedAST.cpp +++ b/clang-tools-extra/clangd/ParsedAST.cpp @@ -50,6 +50,7 @@ #include "llvm/ADT/StringRef.h" #include #include +#include #include // Force the linker to link in Clang-tidy modules. @@ -171,9 +172,10 @@ class ReplayPreamble : private PPCallbacks { void replay() { for (const auto &Inc : Includes) { - llvm::Optional File; + std::optional File; if (Inc.Resolved != "") - File = expectedToOptional(SM.getFileManager().getFileRef(Inc.Resolved)); + File = + expectedToStdOptional(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 aaba2c90056da1..9041c79e7f648d 100644 --- a/clang-tools-extra/clangd/index/IndexAction.cpp +++ b/clang-tools-extra/clangd/index/IndexAction.cpp @@ -22,13 +22,14 @@ #include #include #include +#include #include namespace clang { namespace clangd { namespace { -llvm::Optional toURI(Optional File) { +std::optional toURI(std::optional File) { if (!File) return std::nullopt; auto AbsolutePath = File->getFileEntry().tryGetRealPathName(); @@ -85,7 +86,7 @@ struct IncludeGraphCollector : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, + std::optional 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 81674134689407..52f7ded6156b1a 100644 --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp @@ -37,6 +37,7 @@ #include "gmock/gmock-matchers.h" #include "gmock/gmock.h" #include "gtest/gtest.h" +#include namespace clang { namespace clangd { @@ -381,7 +382,7 @@ TEST(ParsedASTTest, ReplayPreambleForTidyCheckers) { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional, StringRef, StringRef, + std::optional, 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 e16be1221e5805..efdacc78bd6c92 100644 --- a/clang-tools-extra/include-cleaner/lib/Record.cpp +++ b/clang-tools-extra/include-cleaner/lib/Record.cpp @@ -17,6 +17,7 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "clang/Tooling/Inclusions/HeaderAnalysis.h" +#include namespace clang::include_cleaner { namespace { @@ -35,7 +36,7 @@ class PPRecorder : public PPCallbacks { void InclusionDirective(SourceLocation Hash, const Token &IncludeTok, StringRef SpelledFilename, bool IsAngled, CharSourceRange FilenameRange, - llvm::Optional File, + std::optional File, StringRef SearchPath, StringRef RelativePath, const Module *, SrcMgr::CharacteristicKind) override { if (!Active) @@ -180,7 +181,7 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange /*FilenameRange*/, - Optional File, + std::optional 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 610fb596305c0a..d1c0cf89087fe5 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,6 +69,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include using namespace Modularize; using namespace clang; @@ -89,8 +90,9 @@ class CoverageCheckerCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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 171a9380b793e6..f6972886631a09 100644 --- a/clang-tools-extra/modularize/PreprocessorTracker.cpp +++ b/clang-tools-extra/modularize/PreprocessorTracker.cpp @@ -251,6 +251,7 @@ #include "llvm/ADT/SmallSet.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/raw_ostream.h" +#include namespace Modularize { @@ -734,7 +735,7 @@ class PreprocessorCallbacks : public clang::PPCallbacks { const clang::Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, - llvm::Optional File, + std::optional File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const clang::Module *Imported, @@ -1278,7 +1279,7 @@ void PreprocessorCallbacks::InclusionDirective( clang::SourceLocation HashLoc, const clang::Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, clang::CharSourceRange FilenameRange, - llvm::Optional File, llvm::StringRef SearchPath, + std::optional 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 c1434558698dbc..1f2eeda6ed9256 100644 --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp @@ -17,6 +17,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Lex/MacroArgs.h" #include "llvm/Support/raw_ostream.h" +#include namespace clang { namespace pp_trace { @@ -133,9 +134,10 @@ void PPCallbacksTracker::FileSkipped(const FileEntryRef &SkippedFile, // of whether the inclusion will actually result in an inclusion. void PPCallbacksTracker::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, - llvm::StringRef SearchPath, llvm::StringRef RelativePath, - const Module *Imported, SrcMgr::CharacteristicKind FileType) { + bool IsAngled, CharSourceRange FilenameRange, + std::optional File, llvm::StringRef SearchPath, + llvm::StringRef RelativePath, const Module *Imported, + SrcMgr::CharacteristicKind FileType) { beginCallback("InclusionDirective"); appendArgument("HashLoc", HashLoc); appendArgument("IncludeTok", IncludeTok); @@ -486,7 +488,7 @@ void PPCallbacksTracker::appendArgument(const char *Name, FileID Value) { // Append a FileEntry argument to the top trace item. void PPCallbacksTracker::appendArgument(const char *Name, - Optional Value) { + std::optional 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 864014631f04a6..c494556b44248c 100644 --- a/clang-tools-extra/pp-trace/PPCallbacksTracker.h +++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.h @@ -21,14 +21,15 @@ #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 #include #include @@ -94,7 +95,7 @@ class PPCallbacksTracker : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, + std::optional File, llvm::StringRef SearchPath, llvm::StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) override; @@ -179,7 +180,7 @@ class PPCallbacksTracker : public PPCallbacks { void appendArgument(const char *Name, FileID Value); /// Append a FileEntryRef argument to the top trace item. - void appendArgument(const char *Name, Optional Value); + void appendArgument(const char *Name, std::optional 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 9f00cfaeec2a79..3a22bba121586d 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -24,6 +24,7 @@ #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem/UniqueID.h" +#include #include namespace llvm { @@ -294,9 +295,9 @@ namespace clang { /// /// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and /// FileEntry::getName have been deleted, delete this class and replace -/// instances with Optional. +/// instances with std::optional. class OptionalFileEntryRefDegradesToFileEntryPtr - : public Optional { + : public std::optional { public: OptionalFileEntryRefDegradesToFileEntryPtr() = default; OptionalFileEntryRefDegradesToFileEntryPtr( @@ -310,50 +311,74 @@ class OptionalFileEntryRefDegradesToFileEntryPtr OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {} OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref) - : Optional(Ref) {} - OptionalFileEntryRefDegradesToFileEntryPtr(Optional MaybeRef) - : Optional(MaybeRef) {} + : std::optional(Ref) {} + OptionalFileEntryRefDegradesToFileEntryPtr( + std::optional MaybeRef) + : std::optional(MaybeRef) {} OptionalFileEntryRefDegradesToFileEntryPtr &operator=(std::nullopt_t) { - Optional::operator=(std::nullopt); + std::optional::operator=(std::nullopt); return *this; } OptionalFileEntryRefDegradesToFileEntryPtr &operator=(FileEntryRef Ref) { - Optional::operator=(Ref); + std::optional::operator=(Ref); return *this; } OptionalFileEntryRefDegradesToFileEntryPtr & - operator=(Optional MaybeRef) { - Optional::operator=(MaybeRef); + operator=(std::optional MaybeRef) { + std::optional::operator=(MaybeRef); return *this; } /// Degrade to 'const FileEntry *' to allow FileEntry::LastRef and /// FileEntry::getName have been deleted, delete this class and replace - /// instances with Optional + /// instances with std::optional 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 &X, + const std::optional &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 &>(X) == + static_cast &>(Y); +} +constexpr bool operator==(const OptionalFileEntryRefDegradesToFileEntryPtr &X, + const std::optional &Y) { + return static_cast &>(X) == Y; +} +constexpr bool operator==(const std::optional &X, + const OptionalFileEntryRefDegradesToFileEntryPtr &Y) { + return X == static_cast &>(Y); +} + static_assert( std::is_trivially_copyable< OptionalFileEntryRefDegradesToFileEntryPtr>::value, "OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable"); inline bool operator==(const FileEntry *LHS, - const Optional &RHS) { + const std::optional &RHS) { return LHS == (RHS ? &RHS->getFileEntry() : nullptr); } -inline bool operator==(const Optional &LHS, +inline bool operator==(const std::optional &LHS, const FileEntry *RHS) { return (LHS ? &LHS->getFileEntry() : nullptr) == RHS; } inline bool operator!=(const FileEntry *LHS, - const Optional &RHS) { + const std::optional &RHS) { return !(LHS == RHS); } -inline bool operator!=(const Optional &LHS, +inline bool operator!=(const std::optional &LHS, const FileEntry *RHS) { return !(LHS == RHS); } diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ec62e0091e0c03..43cda9dee7cfbb 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -31,6 +31,7 @@ #include #include #include +#include #include namespace llvm { @@ -231,10 +232,10 @@ class FileManager : public RefCountedBase { llvm::Expected getSTDIN(); /// Get a FileEntryRef if it exists, without doing anything on error. - llvm::Optional getOptionalFileRef(StringRef Filename, - bool OpenFile = false, - bool CacheFailure = true) { - return llvm::expectedToOptional( + std::optional getOptionalFileRef(StringRef Filename, + bool OpenFile = false, + bool CacheFailure = true) { + return llvm::expectedToStdOptional( getFileRef(Filename, OpenFile, CacheFailure)); } @@ -270,7 +271,7 @@ class FileManager : public RefCountedBase { /// bypasses all mapping and uniquing, blindly creating a new FileEntry. /// There is no attempt to deduplicate these; if you bypass the same file /// twice, you get two new file entries. - llvm::Optional getBypassFile(FileEntryRef VFE); + std::optional 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 c41ae417378987..02312cdd0b3668 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -185,7 +186,7 @@ class alignas(8) Module { /// The AST file if this is a top-level module which has a /// corresponding serialized AST file, or null otherwise. - Optional ASTFile; + std::optional ASTFile; /// The top-level headers associated with this module. llvm::SmallSetVector TopHeaders; @@ -610,7 +611,7 @@ class alignas(8) Module { } /// Set the serialized AST file for the top-level module of this module. - void setASTFile(Optional File) { + void setASTFile(std::optional 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 20f2415ddce38c..8b16ab5c030ded 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -1003,7 +1004,7 @@ class SourceManager : public RefCountedBase { /// is no such file in the filesystem. /// /// This should be called before parsing has begun. - Optional bypassFileContentsOverride(FileEntryRef File); + std::optional bypassFileContentsOverride(FileEntryRef File); /// Specify that a file is transient. void setFileIsTransient(const FileEntry *SourceFile); @@ -1049,7 +1050,7 @@ class SourceManager : public RefCountedBase { } /// Returns the FileEntryRef for the provided FileID. - Optional getFileEntryRefForID(FileID FID) const { + std::optional 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 375e52515a334b..ed54fba752caa7 100644 --- a/clang/include/clang/Lex/DirectoryLookup.h +++ b/clang/include/clang/Lex/DirectoryLookup.h @@ -13,10 +13,11 @@ #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H -#include "clang/Basic/LLVM.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/LLVM.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/ModuleMap.h" +#include namespace clang { class HeaderMap; @@ -180,7 +181,7 @@ class DirectoryLookup { /// \param [out] MappedName if this is a headermap which maps the filename to /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this /// vector and point Filename to it. - Optional + std::optional LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, @@ -190,7 +191,7 @@ class DirectoryLookup { bool OpenFile = true) const; private: - Optional DoFrameworkLookup( + std::optional DoFrameworkLookup( StringRef Filename, HeaderSearch &HS, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 4684f554dc24db..637a24c14953c3 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -479,7 +480,7 @@ class HeaderSearch { /// found in any of searched SearchDirs. Will be set to false if a framework /// is found only through header maps. Doesn't guarantee the requested file is /// found. - Optional LookupFile( + std::optional LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir, ArrayRef> Includers, @@ -495,7 +496,7 @@ class HeaderSearch { /// within ".../Carbon.framework/Headers/Carbon.h", check to see if /// HIToolbox is a subframework within Carbon.framework. If so, return /// the FileEntry for the designated file, otherwise return null. - Optional LookupSubframeworkHeader( + std::optional LookupSubframeworkHeader( StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule); @@ -769,7 +770,7 @@ class HeaderSearch { /// Look up the file with the specified name and determine its owning /// module. - Optional + std::optional 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 8c8fa4d456a6ae..1b83321f53235d 100644 --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -30,6 +30,7 @@ #include "llvm/ADT/Twine.h" #include #include +#include #include #include @@ -606,7 +607,8 @@ class ModuleMap { /// /// \returns The file entry for the module map file containing the given /// module, or nullptr if the module definition was inferred. - Optional getContainingModuleMapFile(const Module *Module) const; + std::optional + getContainingModuleMapFile(const Module *Module) const; /// Get the module map file that (along with the module name) uniquely /// identifies this module. @@ -617,7 +619,8 @@ class ModuleMap { /// of inferred modules, returns the module map that allowed the inference /// (e.g. contained 'module *'). Otherwise, returns /// getContainingModuleMapFile(). - Optional getModuleMapFileForUniquing(const Module *M) const; + std::optional + 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 045df8711a41b7..744da1a63f0f7f 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -20,6 +20,7 @@ #include "clang/Lex/ModuleLoader.h" #include "clang/Lex/Pragma.h" #include "llvm/ADT/StringRef.h" +#include namespace clang { class Token; @@ -125,16 +126,12 @@ class PPCallbacks { /// implicitly 'extern "C"' in C++ mode. /// virtual void InclusionDirective(SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional File, - StringRef SearchPath, - StringRef RelativePath, + const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, + std::optional File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { - } + SrcMgr::CharacteristicKind FileType) {} /// Callback invoked whenever a submodule was entered. /// @@ -327,7 +324,7 @@ class PPCallbacks { /// Hook called when a '__has_include' or '__has_include_next' directive is /// read. virtual void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, - Optional File, + std::optional File, SrcMgr::CharacteristicKind FileType); /// Hook called when a source range is skipped. @@ -458,8 +455,9 @@ class PPChainedCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override { First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath, RelativePath, @@ -548,7 +546,7 @@ class PPChainedCallbacks : public PPCallbacks { } void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, - Optional File, + std::optional 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 ee22f1eeaa8897..66ca5d3f313094 100644 --- a/clang/include/clang/Lex/PreprocessingRecord.h +++ b/clang/include/clang/Lex/PreprocessingRecord.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -240,12 +241,12 @@ class Token; unsigned ImportedModule : 1; /// The file that was included. - Optional File; + std::optional File; public: InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, - Optional File, SourceRange Range); + std::optional File, SourceRange Range); /// Determine what kind of inclusion directive this is. InclusionKind getKind() const { return static_cast(Kind); } @@ -263,7 +264,7 @@ class Token; /// Retrieve the file entry for the actual file that was included /// by this directive. - Optional getFile() const { return File; } + std::optional getFile() const { return File; } // Implement isa/cast/dyncast/etc. static bool classof(const PreprocessedEntity *PE) { @@ -528,8 +529,9 @@ class Token; void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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 05e05e883be69b..ab481c5b2d2e31 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -51,6 +51,7 @@ #include #include #include +#include #include #include #include @@ -2243,7 +2244,7 @@ class Preprocessor { /// /// Returns std::nullopt on failure. \p isAngled indicates whether the file /// reference is for system \#include's or not (i.e. using <> instead of ""). - Optional + std::optional LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDir, SmallVectorImpl *SearchPath, @@ -2510,7 +2511,7 @@ class Preprocessor { } }; - Optional LookupHeaderIncludeOrImport( + std::optional 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 5f453c3bfa9654..1db9e96e7305dc 100644 --- a/clang/include/clang/Serialization/ModuleManager.h +++ b/clang/include/clang/Serialization/ModuleManager.h @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -302,7 +303,8 @@ class ModuleManager { /// modification time criteria, false if the file is either available and /// suitable, or is missing. bool lookupModuleFile(StringRef FileName, off_t ExpectedSize, - time_t ExpectedModTime, Optional &File); + time_t ExpectedModTime, + std::optional &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 1cc6208a4c36ad..cfa01358973ff3 100644 --- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h +++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h @@ -19,6 +19,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/raw_ostream.h" +#include #include #include @@ -134,8 +135,9 @@ class ModuleDepCollectorPP final : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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 d690d4c5450710..e96771f2c19912 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "Transforms.h" -#include "clang/Analysis/RetainSummaryManager.h" #include "clang/ARCMigrate/ARCMT.h" #include "clang/ARCMigrate/ARCMTActions.h" #include "clang/AST/ASTConsumer.h" @@ -17,6 +16,7 @@ #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,6 +32,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLParser.h" +#include using namespace clang; using namespace arcmt; @@ -156,7 +157,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer { return AllowListFilenames.find(llvm::sys::path::filename(Path)) != AllowListFilenames.end(); } - bool canModifyFile(Optional FE) { + bool canModifyFile(std::optional FE) { if (!FE) return false; return canModifyFile(FE->getName()); @@ -1958,7 +1959,8 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { FileID FID = I->first; RewriteBuffer &buf = I->second; - Optional file = Ctx.getSourceManager().getFileEntryRefForID(FID); + std::optional file = + Ctx.getSourceManager().getFileEntryRefForID(FID); assert(file); SmallString<512> newText; llvm::raw_svector_ostream vecOS(newText); @@ -2028,7 +2030,7 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { namespace { struct EditEntry { - Optional File; + std::optional 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 4fefbaa01e52ff..1d960931875cf9 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -471,7 +471,7 @@ FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size, return FileEntryRef(NamedFileEnt); } -llvm::Optional FileManager::getBypassFile(FileEntryRef VF) { +std::optional 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 8eca151e82e146..c9312c61b97830 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -712,10 +713,10 @@ void SourceManager::overrideFileContents(const FileEntry *SourceFile, Pair.first->second = NewFile; } -Optional +std::optional SourceManager::bypassFileContentsOverride(FileEntryRef File) { assert(isFileOverridden(&File.getFileEntry())); - llvm::Optional BypassFile = FileMgr.getBypassFile(File); + std::optional 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 382b7f37c26050..2bd7faa20a4063 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -536,7 +536,7 @@ void CGDebugInfo::CreateCompileUnit() { // a relative path, so we look into the actual file entry for the main // file to determine the real absolute path for the file. std::string MainFileDir; - if (Optional MainFile = + if (std::optional 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 563d540514b0ef..f7cb2d07565af5 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -36,6 +36,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/ConvertUTF.h" #include +#include using namespace clang; using namespace CodeGen; @@ -3864,7 +3865,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() { // The path to the source file where this module was declared SourceManager &SM = CGM.getContext().getSourceManager(); - Optional mainFile = + std::optional 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 076d2990fededa..c5e55562aab49a 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.cpp +++ b/clang/lib/CodeGen/MacroPPCallbacks.cpp @@ -15,6 +15,7 @@ #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Preprocessor.h" +#include using namespace clang; @@ -167,8 +168,9 @@ void MacroPPCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason, void MacroPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional 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 01041b16e4b7e4..f16521c497a31e 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.h +++ b/clang/lib/CodeGen/MacroPPCallbacks.h @@ -14,6 +14,7 @@ #define LLVM_CLANG_LIB_CODEGEN_MACROPPCALLBACKS_H #include "clang/Lex/PPCallbacks.h" +#include namespace llvm { class DIMacroFile; @@ -101,8 +102,9 @@ class MacroPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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 acb3cb85314dd8..82387791c91984 100644 --- a/clang/lib/Frontend/CompilerInstance.cpp +++ b/clang/lib/Frontend/CompilerInstance.cpp @@ -426,7 +426,7 @@ static void InitializeFileRemapping(DiagnosticsEngine &Diags, // Remap files in the source manager (with other files). for (const auto &RF : InitOpts.RemappedFiles) { // Find the file that we're mapping to. - Optional ToFile = FileMgr.getOptionalFileRef(RF.second); + std::optional ToFile = FileMgr.getOptionalFileRef(RF.second); if (!ToFile) { Diags.Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second; continue; @@ -1281,8 +1281,8 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, Instance.getFrontendOpts().AllowPCMWithCompilerErrors; } -static Optional getPublicModuleMap(FileEntryRef File, - FileManager &FileMgr) { +static std::optional getPublicModuleMap(FileEntryRef File, + FileManager &FileMgr) { StringRef Filename = llvm::sys::path::filename(File.getName()); SmallString<128> PublicFilename(File.getDir().getName()); if (Filename == "module_private.map") @@ -1307,12 +1307,12 @@ static bool compileModule(CompilerInstance &ImportingInstance, ModuleMap &ModMap = ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); bool Result; - if (Optional ModuleMapFile = + if (std::optional ModuleMapFile = ModMap.getContainingModuleMapFile(Module)) { // Canonicalize compilation to start with the public module map. This is // vital for submodules declarations in the private module maps to be // correctly parsed when depending on a top level module in the public one. - if (Optional PublicMMFile = getPublicModuleMap( + if (std::optional PublicMMFile = getPublicModuleMap( *ModuleMapFile, ImportingInstance.getFileManager())) ModuleMapFile = PublicMMFile; diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 8d712a2c50b5e2..500c08c9d94cb3 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,6 +24,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include using namespace clang; @@ -64,8 +65,9 @@ struct DepCollectorPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override { if (!File) DepCollector.maybeAddDependency(FileName, /*FromModule*/false, @@ -75,7 +77,7 @@ struct DepCollectorPPCallbacks : public PPCallbacks { } void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled, - Optional File, + std::optional File, SrcMgr::CharacteristicKind FileType) override { if (!File) return; diff --git a/clang/lib/Frontend/DependencyGraph.cpp b/clang/lib/Frontend/DependencyGraph.cpp index 4cbdb3d5eeb898..ccf34acb428e68 100644 --- a/clang/lib/Frontend/DependencyGraph.cpp +++ b/clang/lib/Frontend/DependencyGraph.cpp @@ -11,15 +11,16 @@ // //===----------------------------------------------------------------------===// -#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 using namespace clang; namespace DOT = llvm::DOT; @@ -48,8 +49,9 @@ class DependencyGraphCallback : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override { @@ -66,21 +68,16 @@ void clang::AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, } void DependencyGraphCallback::InclusionDirective( - SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported, + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, + std::optional File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!File) return; SourceManager &SM = PP->getSourceManager(); - Optional FromFile = + std::optional 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 e97a2dda1463a7..a3b40807dd1e32 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -40,6 +40,7 @@ #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include +#include #include using namespace clang; @@ -823,7 +824,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI, Dir = *DirOrErr; SmallVector, 1> CWD; CWD.push_back({nullptr, Dir}); - Optional FE = + std::optional 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 7e19ed3d56e503..785bff7bbbdb84 100644 --- a/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include using namespace clang; @@ -48,8 +49,9 @@ struct ModuleDependencyPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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 e3c34665504926..9da330649a9abb 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -33,6 +33,7 @@ #include "llvm/Support/VirtualFileSystem.h" #include #include +#include #include using namespace clang; @@ -97,8 +98,9 @@ class MissingFileCollector : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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") diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index d81a11a4e3c360..8274a2f4cee45d 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,6 +27,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include +#include using namespace clang; /// PrintMacroDefinition - Print a macro definition in a form that will be @@ -146,8 +147,9 @@ class PrintPPOutputPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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, @@ -389,15 +391,10 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc, } void PrintPPOutputPPCallbacks::InclusionDirective( - SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported, + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, + std::optional 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 37178d12a4790b..7fa2328cba7150 100644 --- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -74,8 +74,9 @@ class InclusionRewriter : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override; @@ -182,16 +183,12 @@ void InclusionRewriter::FileSkipped(const FileEntryRef & /*SkippedFile*/, /// FileChanged() or FileSkipped() is called after this (or neither is /// called if this #include results in an error or does not textually include /// anything). -void InclusionRewriter::InclusionDirective(SourceLocation HashLoc, - const Token &/*IncludeTok*/, - StringRef /*FileName*/, - bool /*IsAngled*/, - CharSourceRange /*FilenameRange*/, - Optional /*File*/, - StringRef /*SearchPath*/, - StringRef /*RelativePath*/, - const Module *Imported, - SrcMgr::CharacteristicKind FileType){ +void InclusionRewriter::InclusionDirective( + SourceLocation HashLoc, const Token & /*IncludeTok*/, + StringRef /*FileName*/, bool /*IsAngled*/, + CharSourceRange /*FilenameRange*/, std::optional /*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 f67dceea9135d8..b6e25335b356d8 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -541,7 +542,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, ExpectedLoc = SourceLocation(); } else { // Lookup file via Preprocessor, like a #include. - Optional File = + std::optional 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 c9fcaad311282e..a958b64e06c9d9 100644 --- a/clang/lib/Index/IndexingAction.cpp +++ b/clang/lib/Index/IndexingAction.cpp @@ -17,6 +17,7 @@ #include "clang/Serialization/ASTReader.h" #include "llvm/ADT/STLExtras.h" #include +#include using namespace clang; using namespace clang::index; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 1ce6df468d00d8..ffb27809c11cb9 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,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -171,7 +172,7 @@ void HeaderSearch::getHeaderMapFileNames( } std::string HeaderSearch::getCachedModuleFileName(Module *Module) { - Optional ModuleMap = + std::optional ModuleMap = getModuleMap().getModuleMapFileForUniquing(Module); // The ModuleMap maybe a nullptr, when we load a cached C++ module without // *.modulemap file. In this case, just return an empty string. @@ -212,7 +213,7 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName, } std::string HeaderSearch::getPrebuiltImplicitModuleFileName(Module *Module) { - Optional ModuleMap = + std::optional ModuleMap = getModuleMap().getModuleMapFileForUniquing(Module); StringRef ModuleName = Module->Name; StringRef ModuleMapPath = ModuleMap->getName(); @@ -415,7 +416,7 @@ StringRef DirectoryLookup::getName() const { return getHeaderMap()->getFileName(); } -Optional HeaderSearch::getFileAndSuggestModule( +std::optional HeaderSearch::getFileAndSuggestModule( StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir, bool IsSystemHeaderDir, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool OpenFile /*=true*/, @@ -447,7 +448,7 @@ Optional HeaderSearch::getFileAndSuggestModule( /// LookupFile - Lookup the specified file in this search path, returning it /// if it exists or returning null if not. -Optional DirectoryLookup::LookupFile( +std::optional DirectoryLookup::LookupFile( StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, @@ -586,7 +587,7 @@ static bool needModuleLookup(Module *RequestingModule, /// DoFrameworkLookup - Do a lookup of the specified file in the current /// DirectoryLookup, which is a framework directory. -Optional DirectoryLookup::DoFrameworkLookup( +std::optional DirectoryLookup::DoFrameworkLookup( StringRef Filename, HeaderSearch &HS, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, @@ -855,7 +856,7 @@ diagnoseFrameworkInclude(DiagnosticsEngine &Diags, SourceLocation IncludeLoc, /// for system \#include's or not (i.e. using <> instead of ""). Includers, if /// non-empty, indicates where the \#including file(s) are, in case a relative /// search is needed. Microsoft mode will pass all \#including files. -Optional HeaderSearch::LookupFile( +std::optional HeaderSearch::LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg, ArrayRef> Includers, @@ -898,7 +899,7 @@ Optional HeaderSearch::LookupFile( // This is the header that MSVC's header search would have found. ModuleMap::KnownHeader MSSuggestedModule; - Optional MSFE; + std::optional MSFE; // Unless disabled, check to see if the file is in the #includer's // directory. This cannot be based on CurDir, because each includer could be @@ -927,7 +928,7 @@ Optional HeaderSearch::LookupFile( bool IncluderIsSystemHeader = Includer ? getFileInfo(Includer).DirInfo != SrcMgr::C_User : BuildSystemModule; - if (Optional FE = getFileAndSuggestModule( + if (std::optional FE = getFileAndSuggestModule( TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader, RequestingModule, SuggestedModule)) { if (!Includer) { @@ -1043,7 +1044,7 @@ Optional HeaderSearch::LookupFile( bool InUserSpecifiedSystemFramework = false; bool IsInHeaderMap = false; bool IsFrameworkFoundInDir = false; - Optional File = It->LookupFile( + std::optional File = It->LookupFile( Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule, SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir, IsInHeaderMap, MappedName, OpenFile); @@ -1138,7 +1139,7 @@ Optional HeaderSearch::LookupFile( ScratchFilename += '/'; ScratchFilename += Filename; - Optional File = LookupFile( + std::optional File = LookupFile( ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, &CurDir, Includers.front(), SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, /*IsFrameworkFound=*/nullptr); @@ -1175,7 +1176,7 @@ Optional HeaderSearch::LookupFile( /// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox /// is a subframework within Carbon.framework. If so, return the FileEntry /// for the designated file, otherwise return null. -Optional HeaderSearch::LookupSubframeworkHeader( +std::optional HeaderSearch::LookupSubframeworkHeader( StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl *SearchPath, SmallVectorImpl *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule) { diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index f5a7f5102d13c6..c06179023514e4 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -1258,7 +1259,7 @@ void ModuleMap::addHeader(Module *Mod, Module::Header Header, Cb->moduleMapAddHeader(Header.Entry->getName()); } -Optional +std::optional ModuleMap::getContainingModuleMapFile(const Module *Module) const { if (Module->DefinitionLoc.isInvalid()) return std::nullopt; @@ -1267,7 +1268,7 @@ ModuleMap::getContainingModuleMapFile(const Module *Module) const { SourceMgr.getFileID(Module->DefinitionLoc)); } -Optional +std::optional 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 b618071590bafc..9c9866959c2a15 100644 --- a/clang/lib/Lex/PPCallbacks.cpp +++ b/clang/lib/Lex/PPCallbacks.cpp @@ -8,6 +8,7 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Basic/FileManager.h" +#include using namespace clang; @@ -15,16 +16,16 @@ using namespace clang; PPCallbacks::~PPCallbacks() = default; void PPCallbacks::HasInclude(SourceLocation Loc, StringRef FileName, - bool IsAngled, Optional File, + bool IsAngled, std::optional File, SrcMgr::CharacteristicKind FileType) {} // Out of line key method. PPChainedCallbacks::~PPChainedCallbacks() = default; void PPChainedCallbacks::HasInclude(SourceLocation Loc, StringRef FileName, - bool IsAngled, Optional File, + bool IsAngled, + std::optional 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 5264c006b33012..fcac1bf107e6d2 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -947,7 +948,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc, return nullptr; } -Optional Preprocessor::LookupFile( +std::optional Preprocessor::LookupFile( SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDirArg, SmallVectorImpl *SearchPath, @@ -1012,7 +1013,7 @@ Optional Preprocessor::LookupFile( // the include path until we find that file or run out of files. ConstSearchDirIterator TmpCurDir = CurDir; ConstSearchDirIterator TmpFromDir = nullptr; - while (Optional FE = HeaderInfo.LookupFile( + while (std::optional FE = HeaderInfo.LookupFile( Filename, FilenameLoc, isAngled, TmpFromDir, &TmpCurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, /*IsMapped=*/nullptr, @@ -1030,7 +1031,7 @@ Optional Preprocessor::LookupFile( } // Do a standard file entry lookup. - Optional FE = HeaderInfo.LookupFile( + std::optional FE = HeaderInfo.LookupFile( Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures); @@ -1048,7 +1049,7 @@ Optional Preprocessor::LookupFile( // headers on the #include stack and pass them to HeaderInfo. if (IsFileLexer()) { if ((CurFileEnt = CurPPLexer->getFileEntry())) { - if (Optional FE = HeaderInfo.LookupSubframeworkHeader( + if (std::optional FE = HeaderInfo.LookupSubframeworkHeader( Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule, SuggestedModule)) { if (SuggestedModule && !LangOpts.AsmPreprocessor) @@ -1063,9 +1064,10 @@ Optional Preprocessor::LookupFile( for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) { if (IsFileLexer(ISEntry)) { if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) { - if (Optional FE = HeaderInfo.LookupSubframeworkHeader( - Filename, CurFileEnt, SearchPath, RelativePath, - RequestingModule, SuggestedModule)) { + if (std::optional FE = + HeaderInfo.LookupSubframeworkHeader( + Filename, CurFileEnt, SearchPath, RelativePath, + RequestingModule, SuggestedModule)) { if (SuggestedModule && !LangOpts.AsmPreprocessor) HeaderInfo.getModuleMap().diagnoseHeaderInclusion( RequestingModule, RequestingModuleIsModuleInterface, @@ -2003,7 +2005,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, } } -Optional Preprocessor::LookupHeaderIncludeOrImport( +std::optional Preprocessor::LookupHeaderIncludeOrImport( ConstSearchDirIterator *CurDir, StringRef &Filename, SourceLocation FilenameLoc, CharSourceRange FilenameRange, const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl, @@ -2011,9 +2013,8 @@ Optional Preprocessor::LookupHeaderIncludeOrImport( const FileEntry *LookupFromFile, StringRef &LookupFilename, SmallVectorImpl &RelativePath, SmallVectorImpl &SearchPath, ModuleMap::KnownHeader &SuggestedModule, bool isAngled) { - Optional File = LookupFile( - FilenameLoc, LookupFilename, - isAngled, LookupFrom, LookupFromFile, CurDir, + std::optional File = LookupFile( + FilenameLoc, LookupFilename, isAngled, LookupFrom, LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, &IsFrameworkFound); if (File) @@ -2026,9 +2027,8 @@ Optional Preprocessor::LookupHeaderIncludeOrImport( // brackets, we can attempt a lookup as though it were a quoted path to // provide the user with a possible fixit. if (isAngled) { - Optional File = LookupFile( - FilenameLoc, LookupFilename, - false, LookupFrom, LookupFromFile, CurDir, + std::optional File = LookupFile( + FilenameLoc, LookupFilename, false, LookupFrom, LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, /*IsFrameworkFound=*/nullptr); @@ -2057,9 +2057,9 @@ Optional Preprocessor::LookupHeaderIncludeOrImport( StringRef TypoCorrectionName = CorrectTypoFilename(Filename); StringRef TypoCorrectionLookupName = CorrectTypoFilename(LookupFilename); - Optional File = LookupFile( - FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom, LookupFromFile, - CurDir, Callbacks ? &SearchPath : nullptr, + std::optional 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; } - Optional File = LookupHeaderIncludeOrImport( + std::optional 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 36d3aa59bb2f73..b68a455788c954 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBufferRef.h" #include "llvm/Support/Path.h" +#include using namespace clang; @@ -94,7 +95,8 @@ bool Preprocessor::EnterSourceFile(FileID FID, ConstSearchDirIterator CurDir, Lexer *TheLexer = new Lexer(FID, *InputFile, *this, IsFirstIncludeOfFile); if (getPreprocessorOpts().DependencyDirectivesForFile && FID != PredefinesFileID) { - if (Optional File = SourceMgr.getFileEntryRefForID(FID)) { + if (std::optional File = + SourceMgr.getFileEntryRefForID(FID)) { if (Optional> DepDirectives = getPreprocessorOpts().DependencyDirectivesForFile(*File)) { diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index c33c9d13bd7f9c..6f85d9356b0c8a 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -1249,7 +1250,7 @@ static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II, return false; // Search include directories. - Optional File = + std::optional 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 01e0dbe05ac96c..e55fbb51febed8 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -527,7 +528,7 @@ void Preprocessor::HandlePragmaDependency(Token &DependencyTok) { return; // Search include directories for this file. - Optional File = + std::optional 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 35f9e4dbfe3ff5..1d5a29190516d6 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -42,7 +43,7 @@ ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() = InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, - Optional File, + std::optional File, SourceRange Range) : PreprocessingDirective(InclusionDirectiveKind, Range), InQuotes(InQuotes), Kind(Kind), ImportedModule(ImportedModule), File(File) { @@ -475,15 +476,10 @@ void PreprocessingRecord::MacroUndefined(const Token &Id, } void PreprocessingRecord::InclusionDirective( - SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported, + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, + std::optional 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 281683be8d06ae..b1cb81cca0a3f7 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -65,6 +65,7 @@ #include #include #include +#include #include #include #include @@ -580,7 +581,7 @@ void Preprocessor::EnterMainSourceFile() { if (!PPOpts->PCHThroughHeader.empty()) { // Lookup and save the FileID for the through header. If it isn't found // in the search path, it's a fatal error. - Optional File = LookupFile( + std::optional 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 bb0457605704df..3383bdb5b7d1d0 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -15,6 +15,7 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/SemaInternal.h" +#include using namespace clang; using namespace sema; @@ -320,7 +321,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, Diag(Path[0].second, diag::err_module_redefinition) << ModuleName; if (M->DefinitionLoc.isValid()) Diag(M->DefinitionLoc, diag::note_prev_module_definition); - else if (Optional FE = M->getASTFile()) + else if (std::optional 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 63c525a4c7642b..4b765b337b226b 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -135,6 +135,7 @@ #include #include #include +#include #include #include #include @@ -1520,7 +1521,7 @@ bool ASTReader::ReadSLocEntry(int ID) { // we will also try to fail gracefully by setting up the SLocEntry. unsigned InputID = Record[4]; InputFile IF = getInputFile(*F, InputID); - Optional File = IF.getFile(); + std::optional File = IF.getFile(); bool OverriddenBuffer = IF.isOverridden(); // Note that we only check if a File was returned. If it was out-of-date @@ -2362,7 +2363,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { uint64_t StoredContentHash = FI.ContentHash; OptionalFileEntryRefDegradesToFileEntryPtr File = - expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)); + expectedToStdOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)); // For an overridden file, create a virtual file with the stored // size/timestamp. @@ -3964,7 +3965,7 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName, F.ImportLoc); auto &Map = PP.getHeaderSearchInfo().getModuleMap(); - Optional ModMap = + std::optional ModMap = M ? Map.getModuleMapFileForUniquing(M) : std::nullopt; // Don't emit module relocation error if we have -fno-validate-pch if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation & @@ -6126,7 +6127,7 @@ PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { case PPD_INCLUSION_DIRECTIVE: { const char *FullFileNameStart = Blob.data() + Record[0]; StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); - Optional File; + std::optional File; if (!FullFileName.empty()) File = PP.getFileManager().getOptionalFileRef(FullFileName); diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index ae4ea61d9d8e83..b9fa23b9026256 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -444,7 +445,7 @@ void ModuleManager::visit(llvm::function_ref Visitor, bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize, time_t ExpectedModTime, - Optional &File) { + std::optional &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 e5996815881ea3..6ab476b9a1fa45 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -14,6 +14,7 @@ #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h" #include "llvm/Support/BLAKE3.h" #include "llvm/Support/StringSaver.h" +#include using namespace clang; using namespace tooling; @@ -237,7 +238,7 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) { if (llvm::any_of(CI.getFrontendOpts().Inputs, needsModules)) { Preprocessor &PP = ScanInstance.getPreprocessor(); if (Module *CurrentModule = PP.getCurrentModuleImplementation()) - if (Optional CurrentModuleMap = + if (std::optional CurrentModuleMap = PP.getHeaderSearchInfo() .getModuleMap() .getModuleMapFileForUniquing(CurrentModule)) @@ -334,8 +335,9 @@ void ModuleDepCollectorPP::FileChanged(SourceLocation Loc, void ModuleDepCollectorPP::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional 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 @@ -419,7 +421,8 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) { ModuleMap &ModMapInfo = MDC.ScanInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); - Optional ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M); + std::optional 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 9958671e03a180..37bca8c5033131 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -57,6 +57,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/thread.h" #include +#include #if LLVM_ENABLE_THREADS != 0 && defined(__APPLE__) #define USE_DARWIN_THREADS @@ -8531,7 +8532,7 @@ CXFile clang_getIncludedFile(CXCursor cursor) { return nullptr; const InclusionDirective *ID = getCursorInclusionDirective(cursor); - Optional File = ID->getFile(); + std::optional File = ID->getFile(); return const_cast(File ? &File->getFileEntry() : nullptr); } diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp index 979acaef8d00d4..0a3089173e22ac 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.cpp +++ b/clang/tools/libclang/CXIndexDataConsumer.cpp @@ -14,6 +14,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclVisitor.h" #include "clang/Frontend/ASTUnit.h" +#include using namespace clang; using namespace clang::index; @@ -463,10 +464,10 @@ void CXIndexDataConsumer::enteredMainFile(const FileEntry *File) { } void CXIndexDataConsumer::ppIncludedFile(SourceLocation hashLoc, - StringRef filename, - Optional File, - bool isImport, bool isAngled, - bool isModuleImport) { + StringRef filename, + std::optional 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 04c64cab1952e8..3be37a29d3b57b 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.h +++ b/clang/tools/libclang/CXIndexDataConsumer.h @@ -11,10 +11,11 @@ #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 namespace clang { class FileEntry; @@ -363,8 +364,8 @@ class CXIndexDataConsumer : public index::IndexDataConsumer { void enteredMainFile(const FileEntry *File); void ppIncludedFile(SourceLocation hashLoc, StringRef filename, - Optional File, bool isImport, bool isAngled, - bool isModuleImport); + std::optional 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 206dd48828869d..752b7fb8697f52 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -31,6 +31,7 @@ #include "llvm/Support/MemoryBuffer.h" #include #include +#include #include using namespace clang; @@ -262,8 +263,9 @@ class IndexPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional 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 6fe4a3d65d172c..6ccde5160d679b 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" +#include using namespace llvm; using namespace clang; @@ -542,7 +543,7 @@ TEST_F(FileManagerTest, getBypassFile) { EXPECT_EQ(FE.getSize(), 10); // Bypass the file. - llvm::Optional BypassRef = + std::optional 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 43f7b4a8dca5b3..a8d3aa31aad182 100644 --- a/clang/unittests/Lex/PPCallbacksTest.cpp +++ b/clang/unittests/Lex/PPCallbacksTest.cpp @@ -6,7 +6,6 @@ // //===--------------------------------------------------------------===// -#include "clang/Lex/Preprocessor.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/Diagnostic.h" @@ -19,12 +18,14 @@ #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 using namespace clang; @@ -36,8 +37,9 @@ class InclusionDirectiveCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override { this->HashLoc = HashLoc; this->IncludeTok = IncludeTok; @@ -56,7 +58,7 @@ class InclusionDirectiveCallbacks : public PPCallbacks { SmallString<16> FileName; bool IsAngled; CharSourceRange FilenameRange; - Optional File; + std::optional File; SmallString<16> SearchPath; SmallString<16> RelativePath; const Module* Imported;