[clang] 854c10f - [Clang] Prepare for llvm::Optional becoming std::optional.
Benjamin Kramer via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 19 15:49:29 PST 2022
Author: Benjamin Kramer
Date: 2022-12-20T00:41:40+01:00
New Revision: 854c10f8d185286d941307e1033eb492e085c203
URL: https://github.com/llvm/llvm-project/commit/854c10f8d185286d941307e1033eb492e085c203
DIFF: https://github.com/llvm/llvm-project/commit/854c10f8d185286d941307e1033eb492e085c203.diff
LOG: [Clang] Prepare for llvm::Optional becoming std::optional.
The needed tweaks are mostly trivial, the one nasty bit is Clang's usage
of OptionalStorage. To keep this working old Optional stays around as
clang::CustomizableOptional, with the default Storage removed.
Optional<File/DirectoryEntryRef> is replaced with a typedef.
I tested this with GCC 7.5, the oldest supported GCC I had around.
Differential Revision: https://reviews.llvm.org/D140332
Added:
clang/include/clang/Basic/CustomizableOptional.h
Modified:
clang-tools-extra/clang-move/Move.cpp
clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/Headers.cpp
clang-tools-extra/clangd/ParsedAST.cpp
clang-tools-extra/clangd/index/IndexAction.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
clang-tools-extra/include-cleaner/lib/Record.cpp
clang-tools-extra/modularize/CoverageChecker.cpp
clang-tools-extra/modularize/PreprocessorTracker.cpp
clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
clang-tools-extra/pp-trace/PPCallbacksTracker.h
clang/include/clang/Basic/Diagnostic.h
clang/include/clang/Basic/DirectoryEntry.h
clang/include/clang/Basic/FileEntry.h
clang/include/clang/Basic/FileManager.h
clang/include/clang/Basic/LLVM.h
clang/include/clang/Basic/Module.h
clang/include/clang/Basic/SourceManager.h
clang/include/clang/Lex/DirectoryLookup.h
clang/include/clang/Lex/HeaderSearch.h
clang/include/clang/Lex/ModuleMap.h
clang/include/clang/Lex/PPCallbacks.h
clang/include/clang/Lex/PreprocessingRecord.h
clang/include/clang/Lex/Preprocessor.h
clang/include/clang/Serialization/ModuleManager.h
clang/include/clang/Tooling/Core/Replacement.h
clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
clang/include/clang/Tooling/Inclusions/StandardLibrary.h
clang/lib/ARCMigrate/ObjCMT.cpp
clang/lib/Basic/FileManager.cpp
clang/lib/Basic/SourceManager.cpp
clang/lib/Basic/TargetInfo.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/CodeGen/MacroPPCallbacks.cpp
clang/lib/CodeGen/MacroPPCallbacks.h
clang/lib/Frontend/CompilerInstance.cpp
clang/lib/Frontend/DependencyFile.cpp
clang/lib/Frontend/DependencyGraph.cpp
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Frontend/ModuleDependencyCollector.cpp
clang/lib/Frontend/PrecompiledPreamble.cpp
clang/lib/Frontend/PrintPreprocessedOutput.cpp
clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/lib/Lex/ModuleMap.cpp
clang/lib/Lex/PPCallbacks.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Lex/PPLexerChange.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Lex/Pragma.cpp
clang/lib/Lex/PreprocessingRecord.cpp
clang/lib/Lex/Preprocessor.cpp
clang/lib/Sema/SemaModule.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ModuleManager.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXIndexDataConsumer.cpp
clang/tools/libclang/CXIndexDataConsumer.h
clang/tools/libclang/Indexing.cpp
clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
clang/unittests/Basic/FileManagerTest.cpp
clang/unittests/Lex/PPCallbacksTest.cpp
clang/unittests/Lex/PPDependencyDirectivesTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-move/Move.cpp b/clang-tools-extra/clang-move/Move.cpp
index 9e44fe12ecdce..e237a8ee1ebf1 100644
--- a/clang-tools-extra/clang-move/Move.cpp
+++ b/clang-tools-extra/clang-move/Move.cpp
@@ -131,7 +131,7 @@ class FindAllIncludes : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token & /*IncludeTok*/,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> /*File*/, StringRef SearchPath,
+ OptionalFileEntryRef /*File*/, StringRef SearchPath,
StringRef /*RelativePath*/,
const Module * /*Imported*/,
SrcMgr::CharacteristicKind /*FileType*/) override {
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
index f88e24c10901c..9df26411060c1 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.cpp
@@ -162,7 +162,7 @@ void ExpandModularHeadersPPCallbacks::FileChanged(
void ExpandModularHeadersPPCallbacks::InclusionDirective(
SourceLocation DirectiveLoc, const Token &IncludeToken,
StringRef IncludedFilename, bool IsAngled, CharSourceRange FilenameRange,
- Optional<FileEntryRef> IncludedFile, StringRef SearchPath,
+ OptionalFileEntryRef IncludedFile, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (Imported) {
@@ -224,7 +224,7 @@ void ExpandModularHeadersPPCallbacks::PragmaDiagnostic(SourceLocation Loc,
parseToLocation(Loc);
}
void ExpandModularHeadersPPCallbacks::HasInclude(SourceLocation Loc, StringRef,
- bool, Optional<FileEntryRef>,
+ bool, OptionalFileEntryRef,
SrcMgr::CharacteristicKind) {
parseToLocation(Loc);
}
diff --git a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
index 29f060507e53c..7585fd36673f8 100644
--- a/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
+++ b/clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h
@@ -69,7 +69,7 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation DirectiveLoc,
const Token &IncludeToken, StringRef IncludedFilename,
bool IsAngled, CharSourceRange FilenameRange,
- Optional<FileEntryRef> IncludedFile,
+ OptionalFileEntryRef IncludedFile,
StringRef SearchPath, StringRef RelativePath,
const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
@@ -91,7 +91,7 @@ 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<FileEntryRef> ,
+ void HasInclude(SourceLocation Loc, StringRef, bool, OptionalFileEntryRef,
SrcMgr::CharacteristicKind) override;
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *,
SourceLocation StateLoc, unsigned) override;
diff --git a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
index c51fd53e334cc..ddf09ca2a5c69 100644
--- a/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/KernelNameRestrictionCheck.cpp
@@ -30,7 +30,7 @@ class KernelNameRestrictionPPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FileNameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
@@ -62,8 +62,8 @@ void KernelNameRestrictionCheck::registerPPCallbacks(const SourceManager &SM,
void KernelNameRestrictionPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &, StringRef FileName, bool,
- CharSourceRange, Optional<FileEntryRef>, StringRef, StringRef,
- const Module *, SrcMgr::CharacteristicKind) {
+ CharSourceRange, OptionalFileEntryRef, StringRef, StringRef, const Module *,
+ SrcMgr::CharacteristicKind) {
IncludeDirective ID = {HashLoc, FileName};
IncludeDirectives.push_back(std::move(ID));
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
index b8fbc6ed1e740..cd9aa00079e12 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
@@ -25,7 +25,7 @@ class SuspiciousIncludePPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
@@ -72,7 +72,7 @@ void SuspiciousIncludeCheck::registerPPCallbacks(
void SuspiciousIncludePPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import)
@@ -93,7 +93,7 @@ void SuspiciousIncludePPCallbacks::InclusionDirective(
llvm::sys::path::replace_extension(GuessedFileName,
(HFE.size() ? "." : "") + HFE);
- Optional<FileEntryRef> File =
+ OptionalFileEntryRef File =
PP->LookupFile(DiagLoc, GuessedFileName, IsAngled, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
if (File) {
diff --git a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
index f701bd182683c..5cf4064444cce 100644
--- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
@@ -28,7 +28,7 @@ class IncludeOrderPPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void EndOfMainFile() override;
@@ -82,7 +82,7 @@ static int getPriority(StringRef Filename, bool IsAngled, bool IsMainModule) {
void IncludeOrderPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
// We recognize the first include as a special main module header and want
diff --git a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
index 62379f1214d84..4bbbc5771db86 100644
--- a/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvmlibc/RestrictSystemLibcHeadersCheck.cpp
@@ -34,7 +34,7 @@ class RestrictedIncludesPPCallbacks
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
@@ -46,7 +46,7 @@ class RestrictedIncludesPPCallbacks
void RestrictedIncludesPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
// Compiler provided headers are allowed (e.g stddef.h).
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 64e70ad746c59..2498ec94a8437 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -33,7 +33,7 @@ class IncludeModernizePPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
@@ -179,7 +179,7 @@ IncludeModernizePPCallbacks::IncludeModernizePPCallbacks(
void IncludeModernizePPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
diff --git a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
index 1c196a9a92749..a3f5f2d3ad163 100644
--- a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -119,7 +119,7 @@ class MacroToEnumCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
clearCurrentEnum(HashLoc);
diff --git a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
index 7faf7ccce2405..3509cd4117dd9 100644
--- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp
@@ -22,7 +22,7 @@ namespace portability {
void RestrictedIncludesPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (!Check.contains(FileName) && SrcMgr::isSystem(FileType)) {
diff --git a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
index 2919b064f9406..81489bf529667 100644
--- a/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
+++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h
@@ -51,7 +51,7 @@ class RestrictedIncludesPPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void EndOfMainFile() override;
diff --git a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
index 22a4e4eeec6d7..8c69417a3cfab 100644
--- a/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/DuplicateIncludeCheck.cpp
@@ -48,7 +48,7 @@ class DuplicateIncludeCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
@@ -77,7 +77,7 @@ void DuplicateIncludeCallbacks::FileChanged(SourceLocation Loc,
void DuplicateIncludeCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (llvm::is_contained(Files.back(), FileName)) {
diff --git a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
index 08bbe9deca406..f4ca2d9129d73 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/IncludeInserter.cpp
@@ -24,7 +24,7 @@ class IncludeInserterCallback : public PPCallbacks {
void InclusionDirective(SourceLocation HashLocation,
const Token &IncludeToken, StringRef FileNameRef,
bool IsAngled, CharSourceRange FileNameRange,
- Optional<FileEntryRef> /*IncludedFile*/,
+ OptionalFileEntryRef /*IncludedFile*/,
StringRef /*SearchPath*/, StringRef /*RelativePath*/,
const Module * /*ImportedModule*/,
SrcMgr::CharacteristicKind /*FileType*/) override {
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index 84243409760dd..2291e5fdaf757 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -112,7 +112,7 @@ struct FragmentCompiler {
diag(Error, "Invalid regex " + Anchored + ": " + RegexError, Text.Range);
return std::nullopt;
}
- return Result;
+ return std::move(Result);
}
std::optional<std::string> makeAbsolute(Located<std::string> Path,
diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp
index 4314ef15d3eb3..b22589a374cd6 100644
--- a/clang-tools-extra/clangd/Headers.cpp
+++ b/clang-tools-extra/clangd/Headers.cpp
@@ -35,7 +35,7 @@ class IncludeStructure::RecordHeaders : public PPCallbacks,
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
CharSourceRange /*FilenameRange*/,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
llvm::StringRef /*SearchPath*/,
llvm::StringRef /*RelativePath*/,
const clang::Module * /*Imported*/,
diff --git a/clang-tools-extra/clangd/ParsedAST.cpp b/clang-tools-extra/clangd/ParsedAST.cpp
index 4e99365facb61..aa84ce35561d5 100644
--- a/clang-tools-extra/clangd/ParsedAST.cpp
+++ b/clang-tools-extra/clangd/ParsedAST.cpp
@@ -171,7 +171,7 @@ class ReplayPreamble : private PPCallbacks {
void replay() {
for (const auto &Inc : Includes) {
- llvm::Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
if (Inc.Resolved != "")
File = expectedToOptional(SM.getFileManager().getFileRef(Inc.Resolved));
@@ -679,7 +679,7 @@ ParsedAST::build(llvm::StringRef Filename, const ParseInputs &Inputs,
make_move_iterator(UnusedHeadersDiags.begin()),
make_move_iterator(UnusedHeadersDiags.end()));
}
- return Result;
+ return std::move(Result);
}
ParsedAST::ParsedAST(ParsedAST &&Other) = default;
diff --git a/clang-tools-extra/clangd/index/IndexAction.cpp b/clang-tools-extra/clangd/index/IndexAction.cpp
index aaba2c90056da..a5f8f6b4498c2 100644
--- a/clang-tools-extra/clangd/index/IndexAction.cpp
+++ b/clang-tools-extra/clangd/index/IndexAction.cpp
@@ -28,7 +28,7 @@ namespace clang {
namespace clangd {
namespace {
-llvm::Optional<std::string> toURI(Optional<FileEntryRef> File) {
+llvm::Optional<std::string> toURI(OptionalFileEntryRef File) {
if (!File)
return std::nullopt;
auto AbsolutePath = File->getFileEntry().tryGetRealPathName();
@@ -85,8 +85,7 @@ struct IncludeGraphCollector : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- llvm::StringRef SearchPath,
+ OptionalFileEntryRef File, llvm::StringRef SearchPath,
llvm::StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
auto IncludeURI = toURI(File);
diff --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 4051478a60cba..3493813069c49 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -898,9 +898,7 @@ class Foo final {})cpp";
HI.CalleeArgInfo.emplace();
HI.CalleeArgInfo->Name = "arg_b";
HI.CalleeArgInfo->Type = "int &";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Ref;
- HI.CallPassType->Converted = false;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
}},
{// Extra info for method call.
R"cpp(
@@ -926,9 +924,7 @@ class Foo final {})cpp";
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = "int";
HI.CalleeArgInfo->Default = "3";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Value;
- HI.CallPassType->Converted = false;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
}},
{// Dont crash on invalid decl
R"cpp(
@@ -3037,9 +3033,7 @@ private: union foo {})",
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = "int";
HI.CalleeArgInfo->Default = "7";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Value;
- HI.CallPassType->Converted = false;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, false};
},
R"(variable foo
@@ -3062,9 +3056,7 @@ int foo = 3)",
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = "int";
HI.CalleeArgInfo->Default = "7";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Ref;
- HI.CallPassType->Converted = false;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Ref, false};
},
R"(variable foo
@@ -3087,9 +3079,7 @@ int foo = 3)",
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = {"alias_int", "int"};
HI.CalleeArgInfo->Default = "7";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::Value;
- HI.CallPassType->Converted = true;
+ HI.CallPassType = HoverInfo::PassType{PassMode::Value, true};
},
R"(variable foo
@@ -3127,9 +3117,7 @@ int foo = 3)",
HI.CalleeArgInfo->Name = "arg_a";
HI.CalleeArgInfo->Type = "int";
HI.CalleeArgInfo->Default = "7";
- HI.CallPassType.emplace();
- HI.CallPassType->PassBy = PassMode::ConstRef;
- HI.CallPassType->Converted = true;
+ HI.CallPassType = HoverInfo::PassType{PassMode::ConstRef, true};
},
R"(variable foo
diff --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
index 8167413468940..5792359e3c785 100644
--- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp
@@ -380,9 +380,8 @@ TEST(ParsedASTTest, ReplayPreambleForTidyCheckers) {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef>, StringRef, StringRef,
- const clang::Module *,
+ CharSourceRange FilenameRange, OptionalFileEntryRef,
+ StringRef, StringRef, const clang::Module *,
SrcMgr::CharacteristicKind) override {
Includes.emplace_back(SM, HashLoc, IncludeTok, FileName, IsAngled,
FilenameRange);
diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp b/clang-tools-extra/include-cleaner/lib/Record.cpp
index e16be1221e580..ab5a2415cbf9f 100644
--- a/clang-tools-extra/include-cleaner/lib/Record.cpp
+++ b/clang-tools-extra/include-cleaner/lib/Record.cpp
@@ -35,9 +35,9 @@ class PPRecorder : public PPCallbacks {
void InclusionDirective(SourceLocation Hash, const Token &IncludeTok,
StringRef SpelledFilename, bool IsAngled,
CharSourceRange FilenameRange,
- llvm::Optional<FileEntryRef> File,
- StringRef SearchPath, StringRef RelativePath,
- const Module *, SrcMgr::CharacteristicKind) override {
+ OptionalFileEntryRef File, StringRef SearchPath,
+ StringRef RelativePath, const Module *,
+ SrcMgr::CharacteristicKind) override {
if (!Active)
return;
@@ -180,7 +180,7 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, public CommentHandler {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
CharSourceRange /*FilenameRange*/,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
llvm::StringRef /*SearchPath*/,
llvm::StringRef /*RelativePath*/,
const clang::Module * /*Imported*/,
diff --git a/clang-tools-extra/modularize/CoverageChecker.cpp b/clang-tools-extra/modularize/CoverageChecker.cpp
index 610fb596305c0..80e5749cf4172 100644
--- a/clang-tools-extra/modularize/CoverageChecker.cpp
+++ b/clang-tools-extra/modularize/CoverageChecker.cpp
@@ -89,7 +89,7 @@ class CoverageCheckerCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
Checker.collectUmbrellaHeaderHeader(File->getName());
diff --git a/clang-tools-extra/modularize/PreprocessorTracker.cpp b/clang-tools-extra/modularize/PreprocessorTracker.cpp
index 171a9380b793e..b80bff9150e63 100644
--- a/clang-tools-extra/modularize/PreprocessorTracker.cpp
+++ b/clang-tools-extra/modularize/PreprocessorTracker.cpp
@@ -734,7 +734,7 @@ class PreprocessorCallbacks : public clang::PPCallbacks {
const clang::Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
clang::CharSourceRange FilenameRange,
- llvm::Optional<clang::FileEntryRef> File,
+ clang::OptionalFileEntryRef File,
llvm::StringRef SearchPath,
llvm::StringRef RelativePath,
const clang::Module *Imported,
@@ -1277,10 +1277,9 @@ PreprocessorTracker *PreprocessorTracker::create(
void PreprocessorCallbacks::InclusionDirective(
clang::SourceLocation HashLoc, const clang::Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
- clang::CharSourceRange FilenameRange,
- llvm::Optional<clang::FileEntryRef> File, llvm::StringRef SearchPath,
- llvm::StringRef RelativePath, const clang::Module *Imported,
- clang::SrcMgr::CharacteristicKind FileType) {
+ clang::CharSourceRange FilenameRange, clang::OptionalFileEntryRef File,
+ llvm::StringRef SearchPath, llvm::StringRef RelativePath,
+ const clang::Module *Imported, clang::SrcMgr::CharacteristicKind FileType) {
int DirectiveLine, DirectiveColumn;
std::string HeaderPath = getSourceLocationFile(PP, HashLoc);
getSourceLocationLineAndColumn(PP, HashLoc, DirectiveLine, DirectiveColumn);
diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
index c1434558698db..a402c544ed036 100644
--- a/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
+++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.cpp
@@ -133,7 +133,7 @@ void PPCallbacksTracker::FileSkipped(const FileEntryRef &SkippedFile,
// of whether the inclusion will actually result in an inclusion.
void PPCallbacksTracker::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, llvm::StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
llvm::StringRef SearchPath, llvm::StringRef RelativePath,
const Module *Imported, SrcMgr::CharacteristicKind FileType) {
beginCallback("InclusionDirective");
@@ -486,7 +486,7 @@ void PPCallbacksTracker::appendArgument(const char *Name, FileID Value) {
// Append a FileEntry argument to the top trace item.
void PPCallbacksTracker::appendArgument(const char *Name,
- Optional<FileEntryRef> Value) {
+ OptionalFileEntryRef Value) {
if (!Value) {
appendArgument(Name, "(null)");
return;
diff --git a/clang-tools-extra/pp-trace/PPCallbacksTracker.h b/clang-tools-extra/pp-trace/PPCallbacksTracker.h
index 864014631f04a..c195a72b08c1a 100644
--- a/clang-tools-extra/pp-trace/PPCallbacksTracker.h
+++ b/clang-tools-extra/pp-trace/PPCallbacksTracker.h
@@ -94,8 +94,7 @@ class PPCallbacksTracker : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
llvm::StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- llvm::StringRef SearchPath,
+ OptionalFileEntryRef File, llvm::StringRef SearchPath,
llvm::StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
@@ -179,7 +178,7 @@ 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<FileEntryRef> Value);
+ void appendArgument(const char *Name, OptionalFileEntryRef Value);
void appendArgument(const char *Name, FileEntryRef Value);
/// Append a SourceLocation argument to the top trace item.
diff --git a/clang/include/clang/Basic/CustomizableOptional.h b/clang/include/clang/Basic/CustomizableOptional.h
new file mode 100644
index 0000000000000..52e761d449330
--- /dev/null
+++ b/clang/include/clang/Basic/CustomizableOptional.h
@@ -0,0 +1,280 @@
+//===- CustomizableOptional.h - Optional with custom storage ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H
+#define CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H
+
+#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/Support/Compiler.h"
+#include "llvm/Support/type_traits.h"
+#include <cassert>
+#include <new>
+#include <utility>
+
+namespace clang {
+
+namespace optional_detail {
+template <typename> class OptionalStorage;
+} // namespace optional_detail
+
+// Optional type which internal storage can be specialized by providing
+// OptionalStorage. The interface follows std::optional.
+template <typename T> class CustomizableOptional {
+ optional_detail::OptionalStorage<T> Storage;
+
+public:
+ using value_type = T;
+
+ constexpr CustomizableOptional() = default;
+ constexpr CustomizableOptional(std::nullopt_t) {}
+
+ constexpr CustomizableOptional(const T &y) : Storage(std::in_place, y) {}
+ constexpr CustomizableOptional(const CustomizableOptional &O) = default;
+
+ constexpr CustomizableOptional(T &&y)
+ : Storage(std::in_place, std::move(y)) {}
+ constexpr CustomizableOptional(CustomizableOptional &&O) = default;
+
+ template <typename... ArgTypes>
+ constexpr CustomizableOptional(std::in_place_t, ArgTypes &&...Args)
+ : Storage(std::in_place, std::forward<ArgTypes>(Args)...) {}
+
+ // Allow conversion from Optional<T>.
+ constexpr CustomizableOptional(const llvm::Optional<T> &y)
+ : CustomizableOptional(y ? *y : CustomizableOptional()) {}
+ constexpr CustomizableOptional(llvm::Optional<T> &&y)
+ : CustomizableOptional(y ? std::move(*y) : CustomizableOptional()) {}
+
+ CustomizableOptional &operator=(T &&y) {
+ Storage = std::move(y);
+ return *this;
+ }
+ CustomizableOptional &operator=(CustomizableOptional &&O) = default;
+
+ /// Create a new object by constructing it in place with the given arguments.
+ template <typename... ArgTypes> void emplace(ArgTypes &&...Args) {
+ Storage.emplace(std::forward<ArgTypes>(Args)...);
+ }
+
+ CustomizableOptional &operator=(const T &y) {
+ Storage = y;
+ return *this;
+ }
+ CustomizableOptional &operator=(const CustomizableOptional &O) = default;
+
+ void reset() { Storage.reset(); }
+
+ LLVM_DEPRECATED("Use &*X instead.", "&*X")
+ constexpr const T *getPointer() const { return &Storage.value(); }
+ LLVM_DEPRECATED("Use &*X instead.", "&*X")
+ T *getPointer() { return &Storage.value(); }
+ LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X")
+ constexpr const T &value() const & { return Storage.value(); }
+ LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X")
+ T &value() & { return Storage.value(); }
+
+ constexpr explicit operator bool() const { return has_value(); }
+ constexpr bool has_value() const { return Storage.has_value(); }
+ constexpr const T *operator->() const { return &Storage.value(); }
+ T *operator->() { return &Storage.value(); }
+ constexpr const T &operator*() const & { return Storage.value(); }
+ T &operator*() & { return Storage.value(); }
+
+ template <typename U> constexpr T value_or(U &&alt) const & {
+ return has_value() ? operator*() : std::forward<U>(alt);
+ }
+
+ LLVM_DEPRECATED("std::optional::value is throwing. Use *X instead", "*X")
+ T &&value() && { return std::move(Storage.value()); }
+ T &&operator*() && { return std::move(Storage.value()); }
+
+ template <typename U> T value_or(U &&alt) && {
+ return has_value() ? std::move(operator*()) : std::forward<U>(alt);
+ }
+
+ // Allow conversion to Optional<T>.
+ explicit operator llvm::Optional<T> &() const & {
+ return *this ? **this : llvm::Optional<T>();
+ }
+ explicit operator llvm::Optional<T> &&() const && {
+ return *this ? std::move(**this) : llvm::Optional<T>();
+ }
+};
+
+template <typename T>
+CustomizableOptional(const T &) -> CustomizableOptional<T>;
+
+template <class T>
+llvm::hash_code hash_value(const CustomizableOptional<T> &O) {
+ return O ? llvm::hash_combine(true, *O) : llvm::hash_value(false);
+}
+
+template <typename T, typename U>
+constexpr bool operator==(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ if (X && Y)
+ return *X == *Y;
+ return X.has_value() == Y.has_value();
+}
+
+template <typename T, typename U>
+constexpr bool operator!=(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ return !(X == Y);
+}
+
+template <typename T, typename U>
+constexpr bool operator<(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ if (X && Y)
+ return *X < *Y;
+ return X.has_value() < Y.has_value();
+}
+
+template <typename T, typename U>
+constexpr bool operator<=(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ return !(Y < X);
+}
+
+template <typename T, typename U>
+constexpr bool operator>(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ return Y < X;
+}
+
+template <typename T, typename U>
+constexpr bool operator>=(const CustomizableOptional<T> &X,
+ const CustomizableOptional<U> &Y) {
+ return !(X < Y);
+}
+
+template <typename T>
+constexpr bool operator==(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return !X;
+}
+
+template <typename T>
+constexpr bool operator==(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X == std::nullopt;
+}
+
+template <typename T>
+constexpr bool operator!=(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return !(X == std::nullopt);
+}
+
+template <typename T>
+constexpr bool operator!=(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X != std::nullopt;
+}
+
+template <typename T>
+constexpr bool operator<(const CustomizableOptional<T> &, std::nullopt_t) {
+ return false;
+}
+
+template <typename T>
+constexpr bool operator<(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X.has_value();
+}
+
+template <typename T>
+constexpr bool operator<=(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return !(std::nullopt < X);
+}
+
+template <typename T>
+constexpr bool operator<=(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return !(X < std::nullopt);
+}
+
+template <typename T>
+constexpr bool operator>(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return std::nullopt < X;
+}
+
+template <typename T>
+constexpr bool operator>(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X < std::nullopt;
+}
+
+template <typename T>
+constexpr bool operator>=(const CustomizableOptional<T> &X, std::nullopt_t) {
+ return std::nullopt <= X;
+}
+
+template <typename T>
+constexpr bool operator>=(std::nullopt_t, const CustomizableOptional<T> &X) {
+ return X <= std::nullopt;
+}
+
+template <typename T>
+constexpr bool operator==(const CustomizableOptional<T> &X, const T &Y) {
+ return X && *X == Y;
+}
+
+template <typename T>
+constexpr bool operator==(const T &X, const CustomizableOptional<T> &Y) {
+ return Y && X == *Y;
+}
+
+template <typename T>
+constexpr bool operator!=(const CustomizableOptional<T> &X, const T &Y) {
+ return !(X == Y);
+}
+
+template <typename T>
+constexpr bool operator!=(const T &X, const CustomizableOptional<T> &Y) {
+ return !(X == Y);
+}
+
+template <typename T>
+constexpr bool operator<(const CustomizableOptional<T> &X, const T &Y) {
+ return !X || *X < Y;
+}
+
+template <typename T>
+constexpr bool operator<(const T &X, const CustomizableOptional<T> &Y) {
+ return Y && X < *Y;
+}
+
+template <typename T>
+constexpr bool operator<=(const CustomizableOptional<T> &X, const T &Y) {
+ return !(Y < X);
+}
+
+template <typename T>
+constexpr bool operator<=(const T &X, const CustomizableOptional<T> &Y) {
+ return !(Y < X);
+}
+
+template <typename T>
+constexpr bool operator>(const CustomizableOptional<T> &X, const T &Y) {
+ return Y < X;
+}
+
+template <typename T>
+constexpr bool operator>(const T &X, const CustomizableOptional<T> &Y) {
+ return Y < X;
+}
+
+template <typename T>
+constexpr bool operator>=(const CustomizableOptional<T> &X, const T &Y) {
+ return !(X < Y);
+}
+
+template <typename T>
+constexpr bool operator>=(const T &X, const CustomizableOptional<T> &Y) {
+ return !(X < Y);
+}
+
+} // namespace clang
+
+#endif // CLANG_BASIC_CUSTOMIZABLEOPTIONAL_H
diff --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index 120e3f578568d..1aff5b4fa8a47 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -1471,6 +1471,12 @@ operator<<(const StreamingDiagnostic &DB, T *DC) {
return DB;
}
+inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
+ SourceLocation L) {
+ DB.AddSourceRange(CharSourceRange::getTokenRange(L));
+ return DB;
+}
+
inline const StreamingDiagnostic &operator<<(const StreamingDiagnostic &DB,
SourceRange R) {
DB.AddSourceRange(CharSourceRange::getTokenRange(R));
diff --git a/clang/include/clang/Basic/DirectoryEntry.h b/clang/include/clang/Basic/DirectoryEntry.h
index 1a318264717f4..dca68ef1b43d5 100644
--- a/clang/include/clang/Basic/DirectoryEntry.h
+++ b/clang/include/clang/Basic/DirectoryEntry.h
@@ -14,12 +14,13 @@
#ifndef LLVM_CLANG_BASIC_DIRECTORYENTRY_H
#define LLVM_CLANG_BASIC_DIRECTORYENTRY_H
+#include "clang/Basic/CustomizableOptional.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/ADT/Hashing.h"
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ErrorOr.h"
#include <utility>
@@ -115,6 +116,8 @@ class DirectoryEntryRef {
const MapEntry *ME;
};
+using OptionalDirectoryEntryRef = CustomizableOptional<DirectoryEntryRef>;
+
namespace FileMgr {
/// Customized storage for refs derived from map entires in FileManager, using
@@ -158,9 +161,7 @@ template <class RefTy> class MapEntryOptionalStorage {
};
} // end namespace FileMgr
-} // end namespace clang
-namespace llvm {
namespace optional_detail {
/// Customize OptionalStorage<DirectoryEntryRef> to use DirectoryEntryRef and
@@ -184,16 +185,16 @@ class OptionalStorage<clang::DirectoryEntryRef>
}
};
-static_assert(sizeof(Optional<clang::DirectoryEntryRef>) ==
- sizeof(clang::DirectoryEntryRef),
- "Optional<DirectoryEntryRef> must avoid size overhead");
+static_assert(sizeof(OptionalDirectoryEntryRef) == sizeof(DirectoryEntryRef),
+ "OptionalDirectoryEntryRef must avoid size overhead");
-static_assert(
- std::is_trivially_copyable<Optional<clang::DirectoryEntryRef>>::value,
- "Optional<DirectoryEntryRef> should be trivially copyable");
+static_assert(std::is_trivially_copyable<OptionalDirectoryEntryRef>::value,
+ "OptionalDirectoryEntryRef should be trivially copyable");
} // end namespace optional_detail
+} // namespace clang
+namespace llvm {
/// Specialisation of DenseMapInfo for DirectoryEntryRef.
template <> struct DenseMapInfo<clang::DirectoryEntryRef> {
static inline clang::DirectoryEntryRef getEmptyKey() {
@@ -229,19 +230,19 @@ template <> struct DenseMapInfo<clang::DirectoryEntryRef> {
namespace clang {
-/// Wrapper around Optional<DirectoryEntryRef> that degrades to 'const
+/// Wrapper around OptionalDirectoryEntryRef that degrades to 'const
/// DirectoryEntry*', facilitating incremental patches to propagate
/// DirectoryEntryRef.
///
/// This class can be used as return value or field where it's convenient for
-/// an Optional<DirectoryEntryRef> to degrade to a 'const DirectoryEntry*'. The
+/// an OptionalDirectoryEntryRef to degrade to a 'const DirectoryEntry*'. The
/// purpose is to avoid code churn due to dances like the following:
/// \code
/// // Old code.
/// lvalue = rvalue;
///
/// // Temporary code from an incremental patch.
-/// Optional<DirectoryEntryRef> MaybeF = rvalue;
+/// OptionalDirectoryEntryRef MaybeF = rvalue;
/// lvalue = MaybeF ? &MaybeF.getDirectoryEntry() : nullptr;
///
/// // Final code.
@@ -250,9 +251,9 @@ namespace clang {
///
/// FIXME: Once DirectoryEntryRef is "everywhere" and DirectoryEntry::LastRef
/// and DirectoryEntry::getName have been deleted, delete this class and
-/// replace instances with Optional<DirectoryEntryRef>.
+/// replace instances with OptionalDirectoryEntryRef.
class OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr
- : public Optional<DirectoryEntryRef> {
+ : public OptionalDirectoryEntryRef {
public:
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr() = default;
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(
@@ -266,28 +267,29 @@ class OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(std::nullopt_t) {}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(DirectoryEntryRef Ref)
- : Optional<DirectoryEntryRef>(Ref) {}
- OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(Optional<DirectoryEntryRef> MaybeRef)
- : Optional<DirectoryEntryRef>(MaybeRef) {}
+ : OptionalDirectoryEntryRef(Ref) {}
+ OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr(
+ OptionalDirectoryEntryRef MaybeRef)
+ : OptionalDirectoryEntryRef(MaybeRef) {}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
operator=(std::nullopt_t) {
- Optional<DirectoryEntryRef>::operator=(std::nullopt);
+ OptionalDirectoryEntryRef::operator=(std::nullopt);
return *this;
}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &operator=(DirectoryEntryRef Ref) {
- Optional<DirectoryEntryRef>::operator=(Ref);
+ OptionalDirectoryEntryRef::operator=(Ref);
return *this;
}
OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr &
- operator=(Optional<DirectoryEntryRef> MaybeRef) {
- Optional<DirectoryEntryRef>::operator=(MaybeRef);
+ operator=(OptionalDirectoryEntryRef MaybeRef) {
+ OptionalDirectoryEntryRef::operator=(MaybeRef);
return *this;
}
/// Degrade to 'const DirectoryEntry *' to allow DirectoryEntry::LastRef and
/// DirectoryEntry::getName have been deleted, delete this class and replace
- /// instances with Optional<DirectoryEntryRef>
+ /// instances with OptionalDirectoryEntryRef
operator const DirectoryEntry *() const {
return has_value() ? &(*this)->getDirEntry() : nullptr;
}
diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h
index 9f00cfaeec2a7..6ff9c19a7921d 100644
--- a/clang/include/clang/Basic/FileEntry.h
+++ b/clang/include/clang/Basic/FileEntry.h
@@ -14,6 +14,7 @@
#ifndef LLVM_CLANG_BASIC_FILEENTRY_H
#define LLVM_CLANG_BASIC_FILEENTRY_H
+#include "clang/Basic/CustomizableOptional.h"
#include "clang/Basic/DirectoryEntry.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/DenseMapInfo.h"
@@ -41,19 +42,12 @@ namespace clang {
class FileEntryRef;
-} // namespace clang
-
-namespace llvm {
namespace optional_detail {
/// Forward declare a template specialization for OptionalStorage.
-template <>
-class OptionalStorage<clang::FileEntryRef, /*is_trivially_copyable*/ true>;
+template <> class OptionalStorage<clang::FileEntryRef>;
} // namespace optional_detail
-} // namespace llvm
-
-namespace clang {
class FileEntry;
@@ -129,7 +123,7 @@ class FileEntryRef {
llvm::PointerUnion<FileEntry *, const void *> V;
/// Directory the file was found in. Set if and only if V is a FileEntry.
- Optional<DirectoryEntryRef> Dir;
+ OptionalDirectoryEntryRef Dir;
MapValue() = delete;
MapValue(FileEntry &FE, DirectoryEntryRef Dir) : V(&FE), Dir(Dir) {}
@@ -207,9 +201,8 @@ static_assert(sizeof(FileEntryRef) == sizeof(const FileEntry *),
static_assert(std::is_trivially_copyable<FileEntryRef>::value,
"FileEntryRef must be trivially copyable");
-} // end namespace clang
+using OptionalFileEntryRef = CustomizableOptional<FileEntryRef>;
-namespace llvm {
namespace optional_detail {
/// Customize OptionalStorage<FileEntryRef> to use FileEntryRef and its
@@ -233,15 +226,16 @@ class OptionalStorage<clang::FileEntryRef>
}
};
-static_assert(sizeof(Optional<clang::FileEntryRef>) ==
- sizeof(clang::FileEntryRef),
- "Optional<FileEntryRef> must avoid size overhead");
+static_assert(sizeof(OptionalFileEntryRef) == sizeof(FileEntryRef),
+ "OptionalFileEntryRef must avoid size overhead");
-static_assert(std::is_trivially_copyable<Optional<clang::FileEntryRef>>::value,
- "Optional<FileEntryRef> should be trivially copyable");
+static_assert(std::is_trivially_copyable<OptionalFileEntryRef>::value,
+ "OptionalFileEntryRef should be trivially copyable");
} // end namespace optional_detail
+} // namespace clang
+namespace llvm {
/// Specialisation of DenseMapInfo for FileEntryRef.
template <> struct DenseMapInfo<clang::FileEntryRef> {
static inline clang::FileEntryRef getEmptyKey() {
@@ -274,18 +268,18 @@ template <> struct DenseMapInfo<clang::FileEntryRef> {
namespace clang {
-/// Wrapper around Optional<FileEntryRef> that degrades to 'const FileEntry*',
+/// Wrapper around OptionalFileEntryRef that degrades to 'const FileEntry*',
/// facilitating incremental patches to propagate FileEntryRef.
///
/// This class can be used as return value or field where it's convenient for
-/// an Optional<FileEntryRef> to degrade to a 'const FileEntry*'. The purpose
+/// an OptionalFileEntryRef to degrade to a 'const FileEntry*'. The purpose
/// is to avoid code churn due to dances like the following:
/// \code
/// // Old code.
/// lvalue = rvalue;
///
/// // Temporary code from an incremental patch.
-/// Optional<FileEntryRef> MaybeF = rvalue;
+/// OptionalFileEntryRef MaybeF = rvalue;
/// lvalue = MaybeF ? &MaybeF.getFileEntry() : nullptr;
///
/// // Final code.
@@ -294,9 +288,8 @@ namespace clang {
///
/// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and
/// FileEntry::getName have been deleted, delete this class and replace
-/// instances with Optional<FileEntryRef>.
-class OptionalFileEntryRefDegradesToFileEntryPtr
- : public Optional<FileEntryRef> {
+/// instances with OptionalFileEntryRef.
+class OptionalFileEntryRefDegradesToFileEntryPtr : public OptionalFileEntryRef {
public:
OptionalFileEntryRefDegradesToFileEntryPtr() = default;
OptionalFileEntryRefDegradesToFileEntryPtr(
@@ -310,27 +303,27 @@ class OptionalFileEntryRefDegradesToFileEntryPtr
OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {}
OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref)
- : Optional<FileEntryRef>(Ref) {}
- OptionalFileEntryRefDegradesToFileEntryPtr(Optional<FileEntryRef> MaybeRef)
- : Optional<FileEntryRef>(MaybeRef) {}
+ : OptionalFileEntryRef(Ref) {}
+ OptionalFileEntryRefDegradesToFileEntryPtr(OptionalFileEntryRef MaybeRef)
+ : OptionalFileEntryRef(MaybeRef) {}
OptionalFileEntryRefDegradesToFileEntryPtr &operator=(std::nullopt_t) {
- Optional<FileEntryRef>::operator=(std::nullopt);
+ OptionalFileEntryRef::operator=(std::nullopt);
return *this;
}
OptionalFileEntryRefDegradesToFileEntryPtr &operator=(FileEntryRef Ref) {
- Optional<FileEntryRef>::operator=(Ref);
+ OptionalFileEntryRef::operator=(Ref);
return *this;
}
OptionalFileEntryRefDegradesToFileEntryPtr &
- operator=(Optional<FileEntryRef> MaybeRef) {
- Optional<FileEntryRef>::operator=(MaybeRef);
+ operator=(OptionalFileEntryRef MaybeRef) {
+ OptionalFileEntryRef::operator=(MaybeRef);
return *this;
}
/// Degrade to 'const FileEntry *' to allow FileEntry::LastRef and
/// FileEntry::getName have been deleted, delete this class and replace
- /// instances with Optional<FileEntryRef>
+ /// instances with OptionalFileEntryRef
operator const FileEntry *() const {
return has_value() ? &(*this)->getFileEntry() : nullptr;
}
@@ -341,20 +334,16 @@ static_assert(
OptionalFileEntryRefDegradesToFileEntryPtr>::value,
"OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable");
-inline bool operator==(const FileEntry *LHS,
- const Optional<FileEntryRef> &RHS) {
+inline bool operator==(const FileEntry *LHS, const OptionalFileEntryRef &RHS) {
return LHS == (RHS ? &RHS->getFileEntry() : nullptr);
}
-inline bool operator==(const Optional<FileEntryRef> &LHS,
- const FileEntry *RHS) {
+inline bool operator==(const OptionalFileEntryRef &LHS, const FileEntry *RHS) {
return (LHS ? &LHS->getFileEntry() : nullptr) == RHS;
}
-inline bool operator!=(const FileEntry *LHS,
- const Optional<FileEntryRef> &RHS) {
+inline bool operator!=(const FileEntry *LHS, const OptionalFileEntryRef &RHS) {
return !(LHS == RHS);
}
-inline bool operator!=(const Optional<FileEntryRef> &LHS,
- const FileEntry *RHS) {
+inline bool operator!=(const OptionalFileEntryRef &LHS, const FileEntry *RHS) {
return !(LHS == RHS);
}
@@ -390,7 +379,7 @@ class FileEntry {
// default constructor). It should always have a value in practice.
//
// TODO: remove this once everyone that needs a name uses FileEntryRef.
- Optional<FileEntryRef> LastRef;
+ OptionalFileEntryRef LastRef;
public:
~FileEntry();
diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h
index ec62e0091e0c0..84d569363a4a0 100644
--- a/clang/include/clang/Basic/FileManager.h
+++ b/clang/include/clang/Basic/FileManager.h
@@ -102,7 +102,7 @@ class FileManager : public RefCountedBase<FileManager> {
SeenBypassFileEntries;
/// The file entry for stdin, if it has been accessed through the FileManager.
- Optional<FileEntryRef> STDIN;
+ OptionalFileEntryRef STDIN;
/// The canonical names of files and directories .
llvm::DenseMap<const void *, llvm::StringRef> CanonicalNames;
@@ -166,8 +166,8 @@ class FileManager : public RefCountedBase<FileManager> {
bool CacheFailure = true);
/// Get a \c DirectoryEntryRef if it exists, without doing anything on error.
- llvm::Optional<DirectoryEntryRef>
- getOptionalDirectoryRef(StringRef DirName, bool CacheFailure = true) {
+ OptionalDirectoryEntryRef getOptionalDirectoryRef(StringRef DirName,
+ bool CacheFailure = true) {
return llvm::expectedToOptional(getDirectoryRef(DirName, CacheFailure));
}
@@ -231,9 +231,9 @@ class FileManager : public RefCountedBase<FileManager> {
llvm::Expected<FileEntryRef> getSTDIN();
/// Get a FileEntryRef if it exists, without doing anything on error.
- llvm::Optional<FileEntryRef> getOptionalFileRef(StringRef Filename,
- bool OpenFile = false,
- bool CacheFailure = true) {
+ OptionalFileEntryRef getOptionalFileRef(StringRef Filename,
+ bool OpenFile = false,
+ bool CacheFailure = true) {
return llvm::expectedToOptional(
getFileRef(Filename, OpenFile, CacheFailure));
}
@@ -270,7 +270,7 @@ class FileManager : public RefCountedBase<FileManager> {
/// 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<FileEntryRef> getBypassFile(FileEntryRef VFE);
+ OptionalFileEntryRef getBypassFile(FileEntryRef VFE);
/// Open the specified file as a MemoryBuffer, returning a new
/// MemoryBuffer if successful, otherwise returning null.
diff --git a/clang/include/clang/Basic/LLVM.h b/clang/include/clang/Basic/LLVM.h
index 6375bd05fb5c3..5d4d72630970b 100644
--- a/clang/include/clang/Basic/LLVM.h
+++ b/clang/include/clang/Basic/LLVM.h
@@ -37,7 +37,7 @@ namespace llvm {
template<unsigned InternalLen> class SmallString;
template<typename T, unsigned N> class SmallVector;
template<typename T> class SmallVectorImpl;
- template<typename T> class Optional;
+ template <typename T> class Optional;
template <class T> class Expected;
template<typename T>
diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h
index c41ae41737898..11c021eb6e58c 100644
--- a/clang/include/clang/Basic/Module.h
+++ b/clang/include/clang/Basic/Module.h
@@ -185,7 +185,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<FileEntryRef> ASTFile;
+ OptionalFileEntryRef ASTFile;
/// The top-level headers associated with this module.
llvm::SmallSetVector<const FileEntry *, 2> TopHeaders;
@@ -610,7 +610,7 @@ class alignas(8) Module {
}
/// Set the serialized AST file for the top-level module of this module.
- void setASTFile(Optional<FileEntryRef> File) {
+ void setASTFile(OptionalFileEntryRef File) {
assert((!getASTFile() || getASTFile() == File) && "file path changed");
getTopLevelModule()->ASTFile = File;
}
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index 20f2415ddce38..d7f81255e6119 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -1003,7 +1003,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
/// is no such file in the filesystem.
///
/// This should be called before parsing has begun.
- Optional<FileEntryRef> bypassFileContentsOverride(FileEntryRef File);
+ OptionalFileEntryRef bypassFileContentsOverride(FileEntryRef File);
/// Specify that a file is transient.
void setFileIsTransient(const FileEntry *SourceFile);
@@ -1049,7 +1049,7 @@ class SourceManager : public RefCountedBase<SourceManager> {
}
/// Returns the FileEntryRef for the provided FileID.
- Optional<FileEntryRef> getFileEntryRefForID(FileID FID) const {
+ OptionalFileEntryRef getFileEntryRefForID(FileID FID) const {
if (auto *Entry = getSLocEntryForFile(FID))
return Entry->getFile().getContentCache().OrigEntry;
return std::nullopt;
diff --git a/clang/include/clang/Lex/DirectoryLookup.h b/clang/include/clang/Lex/DirectoryLookup.h
index 375e52515a334..99f7c507c53e0 100644
--- a/clang/include/clang/Lex/DirectoryLookup.h
+++ b/clang/include/clang/Lex/DirectoryLookup.h
@@ -91,8 +91,8 @@ class DirectoryLookup {
return isNormalDir() ? &u.Dir.getDirEntry() : nullptr;
}
- Optional<DirectoryEntryRef> getDirRef() const {
- return isNormalDir() ? Optional<DirectoryEntryRef>(u.Dir) : std::nullopt;
+ OptionalDirectoryEntryRef getDirRef() const {
+ return isNormalDir() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
}
/// getFrameworkDir - Return the directory that this framework refers to.
@@ -101,8 +101,8 @@ class DirectoryLookup {
return isFramework() ? &u.Dir.getDirEntry() : nullptr;
}
- Optional<DirectoryEntryRef> getFrameworkDirRef() const {
- return isFramework() ? Optional<DirectoryEntryRef>(u.Dir) : std::nullopt;
+ OptionalDirectoryEntryRef getFrameworkDirRef() const {
+ return isFramework() ? OptionalDirectoryEntryRef(u.Dir) : std::nullopt;
}
/// getHeaderMap - Return the directory that this entry refers to.
@@ -180,7 +180,7 @@ 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<FileEntryRef>
+ OptionalFileEntryRef
LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc,
SmallVectorImpl<char> *SearchPath,
SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
@@ -190,7 +190,7 @@ class DirectoryLookup {
bool OpenFile = true) const;
private:
- Optional<FileEntryRef> DoFrameworkLookup(
+ OptionalFileEntryRef 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 4684f554dc24d..76e3e786ff070 100644
--- a/clang/include/clang/Lex/HeaderSearch.h
+++ b/clang/include/clang/Lex/HeaderSearch.h
@@ -145,7 +145,7 @@ class ExternalHeaderFileInfoSource {
/// This structure is used to record entries in our framework cache.
struct FrameworkCacheEntry {
/// The directory entry which should be used for the cached framework.
- Optional<DirectoryEntryRef> Directory;
+ OptionalDirectoryEntryRef Directory;
/// Whether this framework has been "user-specified" to be treated as if it
/// were a system framework (even if it was found outside a system framework
@@ -479,7 +479,7 @@ 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<FileEntryRef> LookupFile(
+ OptionalFileEntryRef LookupFile(
StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir,
ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
@@ -495,7 +495,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<FileEntryRef> LookupSubframeworkHeader(
+ OptionalFileEntryRef LookupSubframeworkHeader(
StringRef Filename, const FileEntry *ContextFileEnt,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule);
@@ -769,7 +769,7 @@ class HeaderSearch {
/// Look up the file with the specified name and determine its owning
/// module.
- Optional<FileEntryRef>
+ OptionalFileEntryRef
getFileAndSuggestModule(StringRef FileName, SourceLocation IncludeLoc,
const DirectoryEntry *Dir, bool IsSystemHeaderDir,
Module *RequestingModule,
diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h
index 8c8fa4d456a6a..ba7b6813c6141 100644
--- a/clang/include/clang/Lex/ModuleMap.h
+++ b/clang/include/clang/Lex/ModuleMap.h
@@ -333,7 +333,7 @@ class ModuleMap {
/// \param NeedsFramework If M is not a framework but a missing header would
/// be found in case M was, set it to true. False otherwise.
/// \return The resolved file, if any.
- Optional<FileEntryRef>
+ OptionalFileEntryRef
findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
SmallVectorImpl<char> &RelativePathName, bool &NeedsFramework);
@@ -606,7 +606,7 @@ class ModuleMap {
///
/// \returns The file entry for the module map file containing the given
/// module, or nullptr if the module definition was inferred.
- Optional<FileEntryRef> getContainingModuleMapFile(const Module *Module) const;
+ OptionalFileEntryRef getContainingModuleMapFile(const Module *Module) const;
/// Get the module map file that (along with the module name) uniquely
/// identifies this module.
@@ -617,7 +617,7 @@ class ModuleMap {
/// of inferred modules, returns the module map that allowed the inference
/// (e.g. contained 'module *'). Otherwise, returns
/// getContainingModuleMapFile().
- Optional<FileEntryRef> getModuleMapFileForUniquing(const Module *M) const;
+ OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const;
void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap);
diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h
index 045df8711a41b..2e99fd9300362 100644
--- a/clang/include/clang/Lex/PPCallbacks.h
+++ b/clang/include/clang/Lex/PPCallbacks.h
@@ -125,16 +125,12 @@ class PPCallbacks {
/// implicitly 'extern "C"' in C++ mode.
///
virtual void InclusionDirective(SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- StringRef SearchPath,
- StringRef RelativePath,
+ const Token &IncludeTok, StringRef FileName,
+ bool IsAngled, CharSourceRange FilenameRange,
+ OptionalFileEntryRef File,
+ StringRef SearchPath, StringRef RelativePath,
const Module *Imported,
- SrcMgr::CharacteristicKind FileType) {
- }
+ SrcMgr::CharacteristicKind FileType) {}
/// Callback invoked whenever a submodule was entered.
///
@@ -327,7 +323,7 @@ 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<FileEntryRef> File,
+ OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType);
/// Hook called when a source range is skipped.
@@ -458,7 +454,7 @@ class PPChainedCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled,
@@ -548,7 +544,7 @@ class PPChainedCallbacks : public PPCallbacks {
}
void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) override;
void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name,
diff --git a/clang/include/clang/Lex/PreprocessingRecord.h b/clang/include/clang/Lex/PreprocessingRecord.h
index ee22f1eeaa889..c385bc6a73179 100644
--- a/clang/include/clang/Lex/PreprocessingRecord.h
+++ b/clang/include/clang/Lex/PreprocessingRecord.h
@@ -240,12 +240,12 @@ class Token;
unsigned ImportedModule : 1;
/// The file that was included.
- Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
public:
InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind,
StringRef FileName, bool InQuotes, bool ImportedModule,
- Optional<FileEntryRef> File, SourceRange Range);
+ OptionalFileEntryRef File, SourceRange Range);
/// Determine what kind of inclusion directive this is.
InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); }
@@ -263,7 +263,7 @@ class Token;
/// Retrieve the file entry for the actual file that was included
/// by this directive.
- Optional<FileEntryRef> getFile() const { return File; }
+ OptionalFileEntryRef getFile() const { return File; }
// Implement isa/cast/dyncast/etc.
static bool classof(const PreprocessedEntity *PE) {
@@ -528,7 +528,7 @@ class Token;
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h
index 05e05e883be69..b39eca9e7983e 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -2243,7 +2243,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<FileEntryRef>
+ OptionalFileEntryRef
LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled,
ConstSearchDirIterator FromDir, const FileEntry *FromFile,
ConstSearchDirIterator *CurDir, SmallVectorImpl<char> *SearchPath,
@@ -2510,7 +2510,7 @@ class Preprocessor {
}
};
- Optional<FileEntryRef> LookupHeaderIncludeOrImport(
+ OptionalFileEntryRef LookupHeaderIncludeOrImport(
ConstSearchDirIterator *CurDir, StringRef &Filename,
SourceLocation FilenameLoc, CharSourceRange FilenameRange,
const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl,
diff --git a/clang/include/clang/Serialization/ModuleManager.h b/clang/include/clang/Serialization/ModuleManager.h
index 5f453c3bfa965..3bd379acf7eda 100644
--- a/clang/include/clang/Serialization/ModuleManager.h
+++ b/clang/include/clang/Serialization/ModuleManager.h
@@ -302,7 +302,7 @@ 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<FileEntryRef> &File);
+ time_t ExpectedModTime, OptionalFileEntryRef &File);
/// View the graphviz representation of the module graph.
void viewGraph();
diff --git a/clang/include/clang/Tooling/Core/Replacement.h b/clang/include/clang/Tooling/Core/Replacement.h
index 25d8cc6791960..2c4fb8f53c1e2 100644
--- a/clang/include/clang/Tooling/Core/Replacement.h
+++ b/clang/include/clang/Tooling/Core/Replacement.h
@@ -202,6 +202,9 @@ bool operator<(const Replacement &LHS, const Replacement &RHS);
/// Equal-to operator between two Replacements.
bool operator==(const Replacement &LHS, const Replacement &RHS);
+inline bool operator!=(const Replacement &LHS, const Replacement &RHS) {
+ return !(LHS == RHS);
+}
/// Maintains a set of replacements that are conflict-free.
/// Two replacements are considered conflicts if they overlap or have the same
diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
index 1cc6208a4c36a..8577e140cc6ca 100644
--- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
+++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h
@@ -134,7 +134,7 @@ class ModuleDepCollectorPP final : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path,
diff --git a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
index 5c657b40f10d9..beb2f496f51f4 100644
--- a/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
+++ b/clang/include/clang/Tooling/Inclusions/StandardLibrary.h
@@ -16,6 +16,7 @@
#define LLVM_CLANG_TOOLING_INCLUSIONS_STANDARDLIBRARY_H
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp
index d690d4c545071..ce1decd3ba3e1 100644
--- a/clang/lib/ARCMigrate/ObjCMT.cpp
+++ b/clang/lib/ARCMigrate/ObjCMT.cpp
@@ -156,7 +156,7 @@ class ObjCMigrateASTConsumer : public ASTConsumer {
return AllowListFilenames.find(llvm::sys::path::filename(Path)) !=
AllowListFilenames.end();
}
- bool canModifyFile(Optional<FileEntryRef> FE) {
+ bool canModifyFile(OptionalFileEntryRef FE) {
if (!FE)
return false;
return canModifyFile(FE->getName());
@@ -1958,7 +1958,8 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) {
I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) {
FileID FID = I->first;
RewriteBuffer &buf = I->second;
- Optional<FileEntryRef> file = Ctx.getSourceManager().getFileEntryRefForID(FID);
+ OptionalFileEntryRef file =
+ Ctx.getSourceManager().getFileEntryRefForID(FID);
assert(file);
SmallString<512> newText;
llvm::raw_svector_ostream vecOS(newText);
@@ -2028,7 +2029,7 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) {
namespace {
struct EditEntry {
- Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
unsigned Offset = 0;
unsigned RemoveLen = 0;
std::string Text;
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp
index 4fefbaa01e52f..e8d0f20019eba 100644
--- a/clang/lib/Basic/FileManager.cpp
+++ b/clang/lib/Basic/FileManager.cpp
@@ -471,7 +471,7 @@ FileEntryRef FileManager::getVirtualFileRef(StringRef Filename, off_t Size,
return FileEntryRef(NamedFileEnt);
}
-llvm::Optional<FileEntryRef> FileManager::getBypassFile(FileEntryRef VF) {
+OptionalFileEntryRef FileManager::getBypassFile(FileEntryRef VF) {
// Stat of the file and return nullptr if it doesn't exist.
llvm::vfs::Status Status;
if (getStatValue(VF.getName(), Status, /*isFile=*/true, /*F=*/nullptr))
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 8eca151e82e14..63dd4d64fea18 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -712,10 +712,10 @@ void SourceManager::overrideFileContents(const FileEntry *SourceFile,
Pair.first->second = NewFile;
}
-Optional<FileEntryRef>
+OptionalFileEntryRef
SourceManager::bypassFileContentsOverride(FileEntryRef File) {
assert(isFileOverridden(&File.getFileEntry()));
- llvm::Optional<FileEntryRef> BypassFile = FileMgr.getBypassFile(File);
+ OptionalFileEntryRef BypassFile = FileMgr.getBypassFile(File);
// If the file can't be found in the FS, give up.
if (!BypassFile)
diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp
index 45e2f4a7a5dad..8ee43261fc1d3 100644
--- a/clang/lib/Basic/TargetInfo.cpp
+++ b/clang/lib/Basic/TargetInfo.cpp
@@ -510,7 +510,7 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
}
if (Opts.MaxBitIntWidth)
- MaxBitIntWidth = Opts.MaxBitIntWidth;
+ MaxBitIntWidth = static_cast<unsigned>(Opts.MaxBitIntWidth);
if (Opts.FakeAddressSpaceMap)
AddrSpaceMap = &FakeAddrSpaceMap;
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 382b7f37c2605..4d1b0b65d6e8e 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -536,7 +536,7 @@ void CGDebugInfo::CreateCompileUnit() {
// a relative path, so we look into the actual file entry for the main
// file to determine the real absolute path for the file.
std::string MainFileDir;
- if (Optional<FileEntryRef> MainFile =
+ if (OptionalFileEntryRef MainFile =
SM.getFileEntryRefForID(SM.getMainFileID())) {
MainFileDir = std::string(MainFile->getDir().getName());
if (!llvm::sys::path::is_absolute(MainFileName)) {
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 563d540514b0e..ea62d5d94869a 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -3864,8 +3864,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
// The path to the source file where this module was declared
SourceManager &SM = CGM.getContext().getSourceManager();
- Optional<FileEntryRef> mainFile =
- SM.getFileEntryRefForID(SM.getMainFileID());
+ OptionalFileEntryRef mainFile = SM.getFileEntryRefForID(SM.getMainFileID());
std::string path =
(mainFile->getDir().getName() + "/" + mainFile->getName()).str();
module.add(MakeConstantString(path, ".objc_source_file_name"));
diff --git a/clang/lib/CodeGen/MacroPPCallbacks.cpp b/clang/lib/CodeGen/MacroPPCallbacks.cpp
index 076d2990feded..8589869f6e2fb 100644
--- a/clang/lib/CodeGen/MacroPPCallbacks.cpp
+++ b/clang/lib/CodeGen/MacroPPCallbacks.cpp
@@ -167,7 +167,7 @@ void MacroPPCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason,
void MacroPPCallbacks::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
diff --git a/clang/lib/CodeGen/MacroPPCallbacks.h b/clang/lib/CodeGen/MacroPPCallbacks.h
index 01041b16e4b7e..5af177d0c3fa2 100644
--- a/clang/lib/CodeGen/MacroPPCallbacks.h
+++ b/clang/lib/CodeGen/MacroPPCallbacks.h
@@ -101,7 +101,7 @@ class MacroPPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp
index acb3cb85314dd..a12456640c7ac 100644
--- a/clang/lib/Frontend/CompilerInstance.cpp
+++ b/clang/lib/Frontend/CompilerInstance.cpp
@@ -426,7 +426,7 @@ static void InitializeFileRemapping(DiagnosticsEngine &Diags,
// Remap files in the source manager (with other files).
for (const auto &RF : InitOpts.RemappedFiles) {
// Find the file that we're mapping to.
- Optional<FileEntryRef> ToFile = FileMgr.getOptionalFileRef(RF.second);
+ OptionalFileEntryRef ToFile = FileMgr.getOptionalFileRef(RF.second);
if (!ToFile) {
Diags.Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second;
continue;
@@ -1281,8 +1281,8 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc,
Instance.getFrontendOpts().AllowPCMWithCompilerErrors;
}
-static Optional<FileEntryRef> getPublicModuleMap(FileEntryRef File,
- FileManager &FileMgr) {
+static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File,
+ FileManager &FileMgr) {
StringRef Filename = llvm::sys::path::filename(File.getName());
SmallString<128> PublicFilename(File.getDir().getName());
if (Filename == "module_private.map")
@@ -1307,12 +1307,12 @@ static bool compileModule(CompilerInstance &ImportingInstance,
ModuleMap &ModMap
= ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
bool Result;
- if (Optional<FileEntryRef> ModuleMapFile =
+ if (OptionalFileEntryRef ModuleMapFile =
ModMap.getContainingModuleMapFile(Module)) {
// Canonicalize compilation to start with the public module map. This is
// vital for submodules declarations in the private module maps to be
// correctly parsed when depending on a top level module in the public one.
- if (Optional<FileEntryRef> PublicMMFile = getPublicModuleMap(
+ if (OptionalFileEntryRef PublicMMFile = getPublicModuleMap(
*ModuleMapFile, ImportingInstance.getFileManager()))
ModuleMapFile = PublicMMFile;
diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp
index 8d712a2c50b5e..6a0a7185acc1d 100644
--- a/clang/lib/Frontend/DependencyFile.cpp
+++ b/clang/lib/Frontend/DependencyFile.cpp
@@ -64,7 +64,7 @@ struct DepCollectorPPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
if (!File)
@@ -75,7 +75,7 @@ struct DepCollectorPPCallbacks : public PPCallbacks {
}
void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) override {
if (!File)
return;
diff --git a/clang/lib/Frontend/DependencyGraph.cpp b/clang/lib/Frontend/DependencyGraph.cpp
index 4cbdb3d5eeb89..6aad04370f6e7 100644
--- a/clang/lib/Frontend/DependencyGraph.cpp
+++ b/clang/lib/Frontend/DependencyGraph.cpp
@@ -48,7 +48,7 @@ class DependencyGraphCallback : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
@@ -66,21 +66,15 @@ void clang::AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile,
}
void DependencyGraphCallback::InclusionDirective(
- SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- StringRef SearchPath,
- StringRef RelativePath,
- const Module *Imported,
+ SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
+ StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (!File)
return;
SourceManager &SM = PP->getSourceManager();
- Optional<FileEntryRef> FromFile =
+ OptionalFileEntryRef FromFile =
SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(HashLoc)));
if (!FromFile)
return;
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index e97a2dda1463a..6ec6fa0499178 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -823,7 +823,7 @@ bool FrontendAction::BeginSourceFile(CompilerInstance &CI,
Dir = *DirOrErr;
SmallVector<std::pair<const FileEntry *, const DirectoryEntry *>, 1> CWD;
CWD.push_back({nullptr, Dir});
- Optional<FileEntryRef> FE =
+ OptionalFileEntryRef FE =
HS.LookupFile(FileName, SourceLocation(),
/*Angled*/ Input.getKind().getHeaderUnitKind() ==
InputKind::HeaderUnit_System,
diff --git a/clang/lib/Frontend/ModuleDependencyCollector.cpp b/clang/lib/Frontend/ModuleDependencyCollector.cpp
index 7e19ed3d56e50..99a2875d95337 100644
--- a/clang/lib/Frontend/ModuleDependencyCollector.cpp
+++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp
@@ -48,7 +48,7 @@ struct ModuleDependencyPPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
if (!File)
diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp
index e3c3466550492..17f960f47b787 100644
--- a/clang/lib/Frontend/PrecompiledPreamble.cpp
+++ b/clang/lib/Frontend/PrecompiledPreamble.cpp
@@ -97,7 +97,7 @@ class MissingFileCollector : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
// File is None if it wasn't found.
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index d81a11a4e3c36..ffa85e523c038 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -146,7 +146,7 @@ class PrintPPOutputPPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void Ident(SourceLocation Loc, StringRef str) override;
@@ -389,15 +389,9 @@ void PrintPPOutputPPCallbacks::FileChanged(SourceLocation Loc,
}
void PrintPPOutputPPCallbacks::InclusionDirective(
- SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- StringRef SearchPath,
- StringRef RelativePath,
- const Module *Imported,
+ SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
+ StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
// In -dI mode, dump #include directives prior to dumping their content or
// interpretation.
diff --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
index 37178d12a4790..810ec680448c5 100644
--- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
+++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp
@@ -74,7 +74,7 @@ class InclusionRewriter : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override;
void If(SourceLocation Loc, SourceRange ConditionRange,
@@ -182,16 +182,12 @@ void InclusionRewriter::FileSkipped(const FileEntryRef & /*SkippedFile*/,
/// FileChanged() or FileSkipped() is called after this (or neither is
/// called if this #include results in an error or does not textually include
/// anything).
-void InclusionRewriter::InclusionDirective(SourceLocation HashLoc,
- const Token &/*IncludeTok*/,
- StringRef /*FileName*/,
- bool /*IsAngled*/,
- CharSourceRange /*FilenameRange*/,
- Optional<FileEntryRef> /*File*/,
- StringRef /*SearchPath*/,
- StringRef /*RelativePath*/,
- const Module *Imported,
- SrcMgr::CharacteristicKind FileType){
+void InclusionRewriter::InclusionDirective(
+ SourceLocation HashLoc, const Token & /*IncludeTok*/,
+ StringRef /*FileName*/, bool /*IsAngled*/,
+ CharSourceRange /*FilenameRange*/, OptionalFileEntryRef /*File*/,
+ StringRef /*SearchPath*/, StringRef /*RelativePath*/,
+ const Module *Imported, SrcMgr::CharacteristicKind FileType) {
if (Imported) {
auto P = ModuleIncludes.insert(std::make_pair(HashLoc, Imported));
(void)P;
diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index f67dceea9135d..378f7ddd0159f 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -541,7 +541,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM,
ExpectedLoc = SourceLocation();
} else {
// Lookup file via Preprocessor, like a #include.
- Optional<FileEntryRef> File =
+ OptionalFileEntryRef File =
PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr);
if (!File) {
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp
index 1ce6df468d00d..074c147ba3c54 100644
--- a/clang/lib/Lex/HeaderSearch.cpp
+++ b/clang/lib/Lex/HeaderSearch.cpp
@@ -171,7 +171,7 @@ void HeaderSearch::getHeaderMapFileNames(
}
std::string HeaderSearch::getCachedModuleFileName(Module *Module) {
- Optional<FileEntryRef> ModuleMap =
+ OptionalFileEntryRef ModuleMap =
getModuleMap().getModuleMapFileForUniquing(Module);
// The ModuleMap maybe a nullptr, when we load a cached C++ module without
// *.modulemap file. In this case, just return an empty string.
@@ -212,7 +212,7 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName,
}
std::string HeaderSearch::getPrebuiltImplicitModuleFileName(Module *Module) {
- Optional<FileEntryRef> ModuleMap =
+ OptionalFileEntryRef ModuleMap =
getModuleMap().getModuleMapFileForUniquing(Module);
StringRef ModuleName = Module->Name;
StringRef ModuleMapPath = ModuleMap->getName();
@@ -415,7 +415,7 @@ StringRef DirectoryLookup::getName() const {
return getHeaderMap()->getFileName();
}
-Optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule(
+OptionalFileEntryRef HeaderSearch::getFileAndSuggestModule(
StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir,
bool IsSystemHeaderDir, Module *RequestingModule,
ModuleMap::KnownHeader *SuggestedModule, bool OpenFile /*=true*/,
@@ -447,7 +447,7 @@ Optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule(
/// LookupFile - Lookup the specified file in this search path, returning it
/// if it exists or returning null if not.
-Optional<FileEntryRef> DirectoryLookup::LookupFile(
+OptionalFileEntryRef DirectoryLookup::LookupFile(
StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule,
@@ -532,7 +532,7 @@ Optional<FileEntryRef> DirectoryLookup::LookupFile(
/// \param DirName The name of the framework directory.
/// \param SubmodulePath Will be populated with the submodule path from the
/// returned top-level module to the originally named framework.
-static Optional<DirectoryEntryRef>
+static OptionalDirectoryEntryRef
getTopFrameworkDir(FileManager &FileMgr, StringRef DirName,
SmallVectorImpl<std::string> &SubmodulePath) {
assert(llvm::sys::path::extension(DirName) == ".framework" &&
@@ -586,7 +586,7 @@ static bool needModuleLookup(Module *RequestingModule,
/// DoFrameworkLookup - Do a lookup of the specified file in the current
/// DirectoryLookup, which is a framework directory.
-Optional<FileEntryRef> DirectoryLookup::DoFrameworkLookup(
+OptionalFileEntryRef DirectoryLookup::DoFrameworkLookup(
StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath,
SmallVectorImpl<char> *RelativePath, Module *RequestingModule,
ModuleMap::KnownHeader *SuggestedModule,
@@ -855,7 +855,7 @@ diagnoseFrameworkInclude(DiagnosticsEngine &Diags, SourceLocation IncludeLoc,
/// for system \#include's or not (i.e. using <> instead of ""). Includers, if
/// non-empty, indicates where the \#including file(s) are, in case a relative
/// search is needed. Microsoft mode will pass all \#including files.
-Optional<FileEntryRef> HeaderSearch::LookupFile(
+OptionalFileEntryRef HeaderSearch::LookupFile(
StringRef Filename, SourceLocation IncludeLoc, bool isAngled,
ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg,
ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers,
@@ -898,7 +898,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile(
// This is the header that MSVC's header search would have found.
ModuleMap::KnownHeader MSSuggestedModule;
- Optional<FileEntryRef> MSFE;
+ OptionalFileEntryRef MSFE;
// Unless disabled, check to see if the file is in the #includer's
// directory. This cannot be based on CurDir, because each includer could be
@@ -927,7 +927,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile(
bool IncluderIsSystemHeader =
Includer ? getFileInfo(Includer).DirInfo != SrcMgr::C_User :
BuildSystemModule;
- if (Optional<FileEntryRef> FE = getFileAndSuggestModule(
+ if (OptionalFileEntryRef FE = getFileAndSuggestModule(
TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader,
RequestingModule, SuggestedModule)) {
if (!Includer) {
@@ -1043,7 +1043,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile(
bool InUserSpecifiedSystemFramework = false;
bool IsInHeaderMap = false;
bool IsFrameworkFoundInDir = false;
- Optional<FileEntryRef> File = It->LookupFile(
+ OptionalFileEntryRef File = It->LookupFile(
Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule,
SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir,
IsInHeaderMap, MappedName, OpenFile);
@@ -1138,7 +1138,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile(
ScratchFilename += '/';
ScratchFilename += Filename;
- Optional<FileEntryRef> File = LookupFile(
+ OptionalFileEntryRef File = LookupFile(
ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, &CurDir,
Includers.front(), SearchPath, RelativePath, RequestingModule,
SuggestedModule, IsMapped, /*IsFrameworkFound=*/nullptr);
@@ -1175,7 +1175,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile(
/// within ".../Carbon.framework/Headers/Carbon.h", check to see if HIToolbox
/// is a subframework within Carbon.framework. If so, return the FileEntry
/// for the designated file, otherwise return null.
-Optional<FileEntryRef> HeaderSearch::LookupSubframeworkHeader(
+OptionalFileEntryRef HeaderSearch::LookupSubframeworkHeader(
StringRef Filename, const FileEntry *ContextFileEnt,
SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath,
Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule) {
@@ -1628,7 +1628,7 @@ bool HeaderSearch::findUsableModuleForFrameworkHeader(
if (needModuleLookup(RequestingModule, SuggestedModule)) {
// Find the top-level framework based on this framework.
SmallVector<std::string, 4> SubmodulePath;
- Optional<DirectoryEntryRef> TopFrameworkDir =
+ OptionalDirectoryEntryRef TopFrameworkDir =
::getTopFrameworkDir(FileMgr, FrameworkName, SubmodulePath);
assert(TopFrameworkDir && "Could not find the top-most framework dir");
@@ -1668,7 +1668,7 @@ bool HeaderSearch::loadModuleMapFile(const FileEntry *File, bool IsSystem,
StringRef OriginalModuleMapFile) {
// Find the directory for the module. For frameworks, that may require going
// up from the 'Modules' directory.
- Optional<DirectoryEntryRef> Dir;
+ OptionalDirectoryEntryRef Dir;
if (getHeaderSearchOpts().ModuleMapFileHomeIsCwd) {
Dir = FileMgr.getOptionalDirectoryRef(".");
} else {
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index f5a7f5102d13c..633ea26fc08a1 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -176,14 +176,14 @@ static void appendSubframeworkPaths(Module *Mod,
llvm::sys::path::append(Path, "Frameworks", Framework + ".framework");
}
-Optional<FileEntryRef> ModuleMap::findHeader(
+OptionalFileEntryRef ModuleMap::findHeader(
Module *M, const Module::UnresolvedHeaderDirective &Header,
SmallVectorImpl<char> &RelativePathName, bool &NeedsFramework) {
// Search for the header file within the module's home directory.
auto *Directory = M->Directory;
SmallString<128> FullPathName(Directory->getName());
- auto GetFile = [&](StringRef Filename) -> Optional<FileEntryRef> {
+ auto GetFile = [&](StringRef Filename) -> OptionalFileEntryRef {
auto File =
expectedToOptional(SourceMgr.getFileManager().getFileRef(Filename));
if (!File || (Header.Size && File->getSize() != *Header.Size) ||
@@ -192,7 +192,7 @@ Optional<FileEntryRef> ModuleMap::findHeader(
return *File;
};
- auto GetFrameworkFile = [&]() -> Optional<FileEntryRef> {
+ auto GetFrameworkFile = [&]() -> OptionalFileEntryRef {
unsigned FullPathLength = FullPathName.size();
appendSubframeworkPaths(M, RelativePathName);
unsigned RelativePathLength = RelativePathName.size();
@@ -256,7 +256,7 @@ void ModuleMap::resolveHeader(Module *Mod,
const Module::UnresolvedHeaderDirective &Header,
bool &NeedsFramework) {
SmallString<128> RelativePathName;
- if (Optional<FileEntryRef> File =
+ if (OptionalFileEntryRef File =
findHeader(Mod, Header, RelativePathName, NeedsFramework)) {
if (Header.IsUmbrella) {
const DirectoryEntry *UmbrellaDir = &File->getDir().getDirEntry();
@@ -1258,7 +1258,7 @@ void ModuleMap::addHeader(Module *Mod, Module::Header Header,
Cb->moduleMapAddHeader(Header.Entry->getName());
}
-Optional<FileEntryRef>
+OptionalFileEntryRef
ModuleMap::getContainingModuleMapFile(const Module *Module) const {
if (Module->DefinitionLoc.isInvalid())
return std::nullopt;
@@ -1267,7 +1267,7 @@ ModuleMap::getContainingModuleMapFile(const Module *Module) const {
SourceMgr.getFileID(Module->DefinitionLoc));
}
-Optional<FileEntryRef>
+OptionalFileEntryRef
ModuleMap::getModuleMapFileForUniquing(const Module *M) const {
if (M->IsInferred) {
assert(InferredModuleAllowedBy.count(M) && "missing inferred module map");
diff --git a/clang/lib/Lex/PPCallbacks.cpp b/clang/lib/Lex/PPCallbacks.cpp
index b618071590baf..f2b60a728e901 100644
--- a/clang/lib/Lex/PPCallbacks.cpp
+++ b/clang/lib/Lex/PPCallbacks.cpp
@@ -15,16 +15,15 @@ using namespace clang;
PPCallbacks::~PPCallbacks() = default;
void PPCallbacks::HasInclude(SourceLocation Loc, StringRef FileName,
- bool IsAngled, Optional<FileEntryRef> File,
+ bool IsAngled, OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) {}
// Out of line key method.
PPChainedCallbacks::~PPChainedCallbacks() = default;
void PPChainedCallbacks::HasInclude(SourceLocation Loc, StringRef FileName,
- bool IsAngled, Optional<FileEntryRef> File,
+ bool IsAngled, OptionalFileEntryRef File,
SrcMgr::CharacteristicKind FileType) {
First->HasInclude(Loc, FileName, IsAngled, File, FileType);
Second->HasInclude(Loc, FileName, IsAngled, File, FileType);
}
-
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp
index 5264c006b3301..8a38fb41d43ad 100644
--- a/clang/lib/Lex/PPDirectives.cpp
+++ b/clang/lib/Lex/PPDirectives.cpp
@@ -947,7 +947,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc,
return nullptr;
}
-Optional<FileEntryRef> Preprocessor::LookupFile(
+OptionalFileEntryRef Preprocessor::LookupFile(
SourceLocation FilenameLoc, StringRef Filename, bool isAngled,
ConstSearchDirIterator FromDir, const FileEntry *FromFile,
ConstSearchDirIterator *CurDirArg, SmallVectorImpl<char> *SearchPath,
@@ -1012,7 +1012,7 @@ Optional<FileEntryRef> Preprocessor::LookupFile(
// the include path until we find that file or run out of files.
ConstSearchDirIterator TmpCurDir = CurDir;
ConstSearchDirIterator TmpFromDir = nullptr;
- while (Optional<FileEntryRef> FE = HeaderInfo.LookupFile(
+ while (OptionalFileEntryRef FE = HeaderInfo.LookupFile(
Filename, FilenameLoc, isAngled, TmpFromDir, &TmpCurDir,
Includers, SearchPath, RelativePath, RequestingModule,
SuggestedModule, /*IsMapped=*/nullptr,
@@ -1030,7 +1030,7 @@ Optional<FileEntryRef> Preprocessor::LookupFile(
}
// Do a standard file entry lookup.
- Optional<FileEntryRef> FE = HeaderInfo.LookupFile(
+ OptionalFileEntryRef FE = HeaderInfo.LookupFile(
Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath,
RelativePath, RequestingModule, SuggestedModule, IsMapped,
IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures);
@@ -1048,7 +1048,7 @@ Optional<FileEntryRef> Preprocessor::LookupFile(
// headers on the #include stack and pass them to HeaderInfo.
if (IsFileLexer()) {
if ((CurFileEnt = CurPPLexer->getFileEntry())) {
- if (Optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader(
+ if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader(
Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule,
SuggestedModule)) {
if (SuggestedModule && !LangOpts.AsmPreprocessor)
@@ -1063,7 +1063,7 @@ Optional<FileEntryRef> Preprocessor::LookupFile(
for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) {
if (IsFileLexer(ISEntry)) {
if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) {
- if (Optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader(
+ if (OptionalFileEntryRef FE = HeaderInfo.LookupSubframeworkHeader(
Filename, CurFileEnt, SearchPath, RelativePath,
RequestingModule, SuggestedModule)) {
if (SuggestedModule && !LangOpts.AsmPreprocessor)
@@ -2003,7 +2003,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
}
}
-Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport(
+OptionalFileEntryRef Preprocessor::LookupHeaderIncludeOrImport(
ConstSearchDirIterator *CurDir, StringRef &Filename,
SourceLocation FilenameLoc, CharSourceRange FilenameRange,
const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl,
@@ -2011,9 +2011,8 @@ Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport(
const FileEntry *LookupFromFile, StringRef &LookupFilename,
SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath,
ModuleMap::KnownHeader &SuggestedModule, bool isAngled) {
- Optional<FileEntryRef> File = LookupFile(
- FilenameLoc, LookupFilename,
- isAngled, LookupFrom, LookupFromFile, CurDir,
+ OptionalFileEntryRef File = LookupFile(
+ FilenameLoc, LookupFilename, isAngled, LookupFrom, LookupFromFile, CurDir,
Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr,
&SuggestedModule, &IsMapped, &IsFrameworkFound);
if (File)
@@ -2026,9 +2025,8 @@ Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport(
// brackets, we can attempt a lookup as though it were a quoted path to
// provide the user with a possible fixit.
if (isAngled) {
- Optional<FileEntryRef> File = LookupFile(
- FilenameLoc, LookupFilename,
- false, LookupFrom, LookupFromFile, CurDir,
+ OptionalFileEntryRef File = LookupFile(
+ FilenameLoc, LookupFilename, false, LookupFrom, LookupFromFile, CurDir,
Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr,
&SuggestedModule, &IsMapped,
/*IsFrameworkFound=*/nullptr);
@@ -2057,9 +2055,9 @@ Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport(
StringRef TypoCorrectionName = CorrectTypoFilename(Filename);
StringRef TypoCorrectionLookupName = CorrectTypoFilename(LookupFilename);
- Optional<FileEntryRef> File = LookupFile(
- FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom, LookupFromFile,
- CurDir, Callbacks ? &SearchPath : nullptr,
+ OptionalFileEntryRef File = LookupFile(
+ FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom,
+ LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr,
Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped,
/*IsFrameworkFound=*/nullptr);
if (File) {
@@ -2182,7 +2180,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport(
BackslashStyle = llvm::sys::path::Style::windows;
}
- Optional<FileEntryRef> File = LookupHeaderIncludeOrImport(
+ OptionalFileEntryRef File = LookupHeaderIncludeOrImport(
&CurDir, Filename, FilenameLoc, FilenameRange, FilenameTok,
IsFrameworkFound, IsImportDecl, IsMapped, LookupFrom, LookupFromFile,
LookupFilename, RelativePath, SearchPath, SuggestedModule, isAngled);
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index 36d3aa59bb2f7..570728e7b3162 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -94,7 +94,7 @@ bool Preprocessor::EnterSourceFile(FileID FID, ConstSearchDirIterator CurDir,
Lexer *TheLexer = new Lexer(FID, *InputFile, *this, IsFirstIncludeOfFile);
if (getPreprocessorOpts().DependencyDirectivesForFile &&
FID != PredefinesFileID) {
- if (Optional<FileEntryRef> File = SourceMgr.getFileEntryRefForID(FID)) {
+ if (OptionalFileEntryRef File = SourceMgr.getFileEntryRefForID(FID)) {
if (Optional<ArrayRef<dependency_directives_scan::Directive>>
DepDirectives =
getPreprocessorOpts().DependencyDirectivesForFile(*File)) {
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index c33c9d13bd7f9..9262d1c2ad83f 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/clang/lib/Lex/PPMacroExpansion.cpp
@@ -1249,7 +1249,7 @@ static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II,
return false;
// Search include directories.
- Optional<FileEntryRef> File =
+ OptionalFileEntryRef File =
PP.LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index 01e0dbe05ac96..fc86f7da32361 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -527,7 +527,7 @@ void Preprocessor::HandlePragmaDependency(Token &DependencyTok) {
return;
// Search include directories for this file.
- Optional<FileEntryRef> File =
+ OptionalFileEntryRef File =
LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr);
if (!File) {
diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp
index 35f9e4dbfe3ff..1b13d09f23498 100644
--- a/clang/lib/Lex/PreprocessingRecord.cpp
+++ b/clang/lib/Lex/PreprocessingRecord.cpp
@@ -42,7 +42,7 @@ ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() =
InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec,
InclusionKind Kind, StringRef FileName,
bool InQuotes, bool ImportedModule,
- Optional<FileEntryRef> File,
+ OptionalFileEntryRef File,
SourceRange Range)
: PreprocessingDirective(InclusionDirectiveKind, Range), InQuotes(InQuotes),
Kind(Kind), ImportedModule(ImportedModule), File(File) {
@@ -475,15 +475,9 @@ void PreprocessingRecord::MacroUndefined(const Token &Id,
}
void PreprocessingRecord::InclusionDirective(
- SourceLocation HashLoc,
- const Token &IncludeTok,
- StringRef FileName,
- bool IsAngled,
- CharSourceRange FilenameRange,
- Optional<FileEntryRef> File,
- StringRef SearchPath,
- StringRef RelativePath,
- const Module *Imported,
+ SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
+ StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
InclusionDirective::InclusionKind Kind = InclusionDirective::Include;
diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp
index 281683be8d06a..5f54c3b9e7539 100644
--- a/clang/lib/Lex/Preprocessor.cpp
+++ b/clang/lib/Lex/Preprocessor.cpp
@@ -580,7 +580,7 @@ void Preprocessor::EnterMainSourceFile() {
if (!PPOpts->PCHThroughHeader.empty()) {
// Lookup and save the FileID for the through header. If it isn't found
// in the search path, it's a fatal error.
- Optional<FileEntryRef> File = LookupFile(
+ OptionalFileEntryRef File = LookupFile(
SourceLocation(), PPOpts->PCHThroughHeader,
/*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr,
/*CurDir=*/nullptr, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr,
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index bb0457605704d..0adcc6856e098 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -320,7 +320,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
Diag(Path[0].second, diag::err_module_redefinition) << ModuleName;
if (M->DefinitionLoc.isValid())
Diag(M->DefinitionLoc, diag::note_prev_module_definition);
- else if (Optional<FileEntryRef> FE = M->getASTFile())
+ else if (OptionalFileEntryRef FE = M->getASTFile())
Diag(M->DefinitionLoc, diag::note_prev_module_definition_from_ast_file)
<< FE->getName();
Mod = M;
diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp
index 63c525a4c7642..35632d91a90e9 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -1520,7 +1520,7 @@ bool ASTReader::ReadSLocEntry(int ID) {
// we will also try to fail gracefully by setting up the SLocEntry.
unsigned InputID = Record[4];
InputFile IF = getInputFile(*F, InputID);
- Optional<FileEntryRef> File = IF.getFile();
+ OptionalFileEntryRef File = IF.getFile();
bool OverriddenBuffer = IF.isOverridden();
// Note that we only check if a File was returned. If it was out-of-date
@@ -2361,8 +2361,8 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) {
StringRef Filename = FI.Filename;
uint64_t StoredContentHash = FI.ContentHash;
- OptionalFileEntryRefDegradesToFileEntryPtr File =
- expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false));
+ OptionalFileEntryRefDegradesToFileEntryPtr File = OptionalFileEntryRef(
+ expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)));
// For an overridden file, create a virtual file with the stored
// size/timestamp.
@@ -3964,7 +3964,7 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
Module *M =
PP.getHeaderSearchInfo().lookupModule(F.ModuleName, F.ImportLoc);
auto &Map = PP.getHeaderSearchInfo().getModuleMap();
- Optional<FileEntryRef> ModMap =
+ OptionalFileEntryRef ModMap =
M ? Map.getModuleMapFileForUniquing(M) : std::nullopt;
// Don't emit module relocation error if we have -fno-validate-pch
if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation &
@@ -6126,7 +6126,7 @@ PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) {
case PPD_INCLUSION_DIRECTIVE: {
const char *FullFileNameStart = Blob.data() + Record[0];
StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]);
- Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
if (!FullFileName.empty())
File = PP.getFileManager().getOptionalFileRef(FullFileName);
diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp
index ae4ea61d9d8e8..81dd54692d77e 100644
--- a/clang/lib/Serialization/ModuleManager.cpp
+++ b/clang/lib/Serialization/ModuleManager.cpp
@@ -444,14 +444,14 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor,
bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize,
time_t ExpectedModTime,
- Optional<FileEntryRef> &File) {
+ OptionalFileEntryRef &File) {
File = std::nullopt;
if (FileName == "-")
return false;
// Open the file immediately to ensure there is no race between stat'ing and
// opening the file.
- Optional<FileEntryRef> FileOrErr =
+ OptionalFileEntryRef FileOrErr =
expectedToOptional(FileMgr.getFileRef(FileName, /*OpenFile=*/true,
/*CacheFailure=*/false));
if (!FileOrErr)
diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index e5996815881ea..61191fcdf8d5e 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -237,7 +237,7 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) {
if (llvm::any_of(CI.getFrontendOpts().Inputs, needsModules)) {
Preprocessor &PP = ScanInstance.getPreprocessor();
if (Module *CurrentModule = PP.getCurrentModuleImplementation())
- if (Optional<FileEntryRef> CurrentModuleMap =
+ if (OptionalFileEntryRef CurrentModuleMap =
PP.getHeaderSearchInfo()
.getModuleMap()
.getModuleMapFileForUniquing(CurrentModule))
@@ -334,7 +334,7 @@ void ModuleDepCollectorPP::FileChanged(SourceLocation Loc,
void ModuleDepCollectorPP::InclusionDirective(
SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName,
- bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File,
+ bool IsAngled, CharSourceRange FilenameRange, OptionalFileEntryRef File,
StringRef SearchPath, StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) {
if (!File && !Imported) {
@@ -419,7 +419,7 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) {
ModuleMap &ModMapInfo =
MDC.ScanInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
- Optional<FileEntryRef> ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M);
+ OptionalFileEntryRef ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M);
if (ModuleMap) {
SmallString<128> Path = ModuleMap->getNameAsRequested();
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 5a36679970585..06fc65136e3bd 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -8531,7 +8531,7 @@ CXFile clang_getIncludedFile(CXCursor cursor) {
return nullptr;
const InclusionDirective *ID = getCursorInclusionDirective(cursor);
- Optional<FileEntryRef> File = ID->getFile();
+ OptionalFileEntryRef 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 979acaef8d00d..da58a48001c26 100644
--- a/clang/tools/libclang/CXIndexDataConsumer.cpp
+++ b/clang/tools/libclang/CXIndexDataConsumer.cpp
@@ -463,10 +463,10 @@ void CXIndexDataConsumer::enteredMainFile(const FileEntry *File) {
}
void CXIndexDataConsumer::ppIncludedFile(SourceLocation hashLoc,
- StringRef filename,
- Optional<FileEntryRef> File,
- bool isImport, bool isAngled,
- bool isModuleImport) {
+ StringRef filename,
+ OptionalFileEntryRef File,
+ bool isImport, bool isAngled,
+ bool isModuleImport) {
if (!CB.ppIncludedFile)
return;
diff --git a/clang/tools/libclang/CXIndexDataConsumer.h b/clang/tools/libclang/CXIndexDataConsumer.h
index 04c64cab1952e..b78ef367eeaa1 100644
--- a/clang/tools/libclang/CXIndexDataConsumer.h
+++ b/clang/tools/libclang/CXIndexDataConsumer.h
@@ -363,7 +363,7 @@ class CXIndexDataConsumer : public index::IndexDataConsumer {
void enteredMainFile(const FileEntry *File);
void ppIncludedFile(SourceLocation hashLoc, StringRef filename,
- Optional<FileEntryRef> File, bool isImport, bool isAngled,
+ OptionalFileEntryRef File, bool isImport, bool isAngled,
bool isModuleImport);
void importedModule(const ImportDecl *ImportD);
diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp
index 206dd48828869..1be313dfff09c 100644
--- a/clang/tools/libclang/Indexing.cpp
+++ b/clang/tools/libclang/Indexing.cpp
@@ -262,7 +262,7 @@ class IndexPPCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
bool isImport = (IncludeTok.is(tok::identifier) &&
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
index df179dddf02fe..d546559cd0117 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferBranchTest.cpp
@@ -102,10 +102,10 @@ TEST(TransferBranchTest, IfElse) {
ASSERT_THAT(Results.keys(), UnorderedElementsAre("p", "q"));
const TestLattice &LP = getLatticeAtAnnotation(Results, "p");
- EXPECT_THAT(LP.Branch, Optional(true));
+ EXPECT_THAT(LP.Branch, std::make_optional(true));
const TestLattice &LQ = getLatticeAtAnnotation(Results, "q");
- EXPECT_THAT(LQ.Branch, Optional(false));
+ EXPECT_THAT(LQ.Branch, std::make_optional(false));
},
LangStandard::lang_cxx17);
}
diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp
index 6fe4a3d65d172..146a6098dfb8b 100644
--- a/clang/unittests/Basic/FileManagerTest.cpp
+++ b/clang/unittests/Basic/FileManagerTest.cpp
@@ -534,7 +534,7 @@ TEST_F(FileManagerTest, getBypassFile) {
// Calling a second time should not affect the UID or size.
unsigned VirtualUID = FE.getUID();
- llvm::Optional<FileEntryRef> SearchRef;
+ OptionalFileEntryRef SearchRef;
ASSERT_THAT_ERROR(Manager.getFileRef("/tmp/test").moveInto(SearchRef),
Succeeded());
EXPECT_EQ(&FE, &SearchRef->getFileEntry());
@@ -542,8 +542,7 @@ TEST_F(FileManagerTest, getBypassFile) {
EXPECT_EQ(FE.getSize(), 10);
// Bypass the file.
- llvm::Optional<FileEntryRef> BypassRef =
- Manager.getBypassFile(File->getLastRef());
+ OptionalFileEntryRef BypassRef = Manager.getBypassFile(File->getLastRef());
ASSERT_TRUE(BypassRef);
EXPECT_EQ("/tmp/test", BypassRef->getName());
diff --git a/clang/unittests/Lex/PPCallbacksTest.cpp b/clang/unittests/Lex/PPCallbacksTest.cpp
index 43f7b4a8dca5b..ec719387fa022 100644
--- a/clang/unittests/Lex/PPCallbacksTest.cpp
+++ b/clang/unittests/Lex/PPCallbacksTest.cpp
@@ -36,7 +36,7 @@ class InclusionDirectiveCallbacks : public PPCallbacks {
void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
StringRef FileName, bool IsAngled,
CharSourceRange FilenameRange,
- Optional<FileEntryRef> File, StringRef SearchPath,
+ OptionalFileEntryRef File, StringRef SearchPath,
StringRef RelativePath, const Module *Imported,
SrcMgr::CharacteristicKind FileType) override {
this->HashLoc = HashLoc;
@@ -56,7 +56,7 @@ class InclusionDirectiveCallbacks : public PPCallbacks {
SmallString<16> FileName;
bool IsAngled;
CharSourceRange FilenameRange;
- Optional<FileEntryRef> File;
+ OptionalFileEntryRef File;
SmallString<16> SearchPath;
SmallString<16> RelativePath;
const Module* Imported;
diff --git a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp
index b7d743132f6f9..b41d9658dca32 100644
--- a/clang/unittests/Lex/PPDependencyDirectivesTest.cpp
+++ b/clang/unittests/Lex/PPDependencyDirectivesTest.cpp
@@ -92,7 +92,7 @@ TEST_F(PPDependencyDirectivesTest, MacroGuard) {
"#include \"head3.h\"\n#include \"head3.h\"\n"));
FileMgr.setVirtualFileSystem(VFS);
- Optional<FileEntryRef> FE;
+ OptionalFileEntryRef FE;
ASSERT_THAT_ERROR(FileMgr.getFileRef("main.c").moveInto(FE),
llvm::Succeeded());
SourceMgr.setMainFileID(
More information about the cfe-commits
mailing list