diff options
author | Krzysztof Parzyszek <kparzysz@quicinc.com> | 2022-12-17 13:57:30 -0800 |
---|---|---|
committer | Krzysztof Parzyszek <kparzysz@quicinc.com> | 2022-12-17 15:24:14 -0800 |
commit | 8f0df9f3bbc6d7f3d5cbfd955c5ee4404c53a75d (patch) | |
tree | b16c78031a5bff93437c00aba53b03bc6a166bc0 /clang | |
parent | 1d43966bc33a55cad1db7758bf4d82526d125db7 (diff) | |
download | llvm-8f0df9f3bbc6d7f3d5cbfd955c5ee4404c53a75d.zip llvm-8f0df9f3bbc6d7f3d5cbfd955c5ee4404c53a75d.tar.gz llvm-8f0df9f3bbc6d7f3d5cbfd955c5ee4404c53a75d.tar.bz2 |
[clang] Convert OptionalFileEntryRefDegradesToFileEntryPtr to std::optional
Diffstat (limited to 'clang')
48 files changed, 257 insertions, 193 deletions
diff --git a/clang/include/clang/Basic/FileEntry.h b/clang/include/clang/Basic/FileEntry.h index 9f00cfa..3a22bba 100644 --- a/clang/include/clang/Basic/FileEntry.h +++ b/clang/include/clang/Basic/FileEntry.h @@ -24,6 +24,7 @@ #include "llvm/Support/ErrorOr.h" #include "llvm/Support/FileSystem/UniqueID.h" +#include <optional> #include <utility> namespace llvm { @@ -294,9 +295,9 @@ namespace clang { /// /// FIXME: Once FileEntryRef is "everywhere" and FileEntry::LastRef and /// FileEntry::getName have been deleted, delete this class and replace -/// instances with Optional<FileEntryRef>. +/// instances with std::optional<FileEntryRef>. class OptionalFileEntryRefDegradesToFileEntryPtr - : public Optional<FileEntryRef> { + : public std::optional<FileEntryRef> { public: OptionalFileEntryRefDegradesToFileEntryPtr() = default; OptionalFileEntryRefDegradesToFileEntryPtr( @@ -310,50 +311,74 @@ public: OptionalFileEntryRefDegradesToFileEntryPtr(std::nullopt_t) {} OptionalFileEntryRefDegradesToFileEntryPtr(FileEntryRef Ref) - : Optional<FileEntryRef>(Ref) {} - OptionalFileEntryRefDegradesToFileEntryPtr(Optional<FileEntryRef> MaybeRef) - : Optional<FileEntryRef>(MaybeRef) {} + : std::optional<FileEntryRef>(Ref) {} + OptionalFileEntryRefDegradesToFileEntryPtr( + std::optional<FileEntryRef> MaybeRef) + : std::optional<FileEntryRef>(MaybeRef) {} OptionalFileEntryRefDegradesToFileEntryPtr &operator=(std::nullopt_t) { - Optional<FileEntryRef>::operator=(std::nullopt); + std::optional<FileEntryRef>::operator=(std::nullopt); return *this; } OptionalFileEntryRefDegradesToFileEntryPtr &operator=(FileEntryRef Ref) { - Optional<FileEntryRef>::operator=(Ref); + std::optional<FileEntryRef>::operator=(Ref); return *this; } OptionalFileEntryRefDegradesToFileEntryPtr & - operator=(Optional<FileEntryRef> MaybeRef) { - Optional<FileEntryRef>::operator=(MaybeRef); + operator=(std::optional<FileEntryRef> MaybeRef) { + std::optional<FileEntryRef>::operator=(MaybeRef); return *this; } /// Degrade to 'const FileEntry *' to allow FileEntry::LastRef and /// FileEntry::getName have been deleted, delete this class and replace - /// instances with Optional<FileEntryRef> + /// instances with std::optional<FileEntryRef> operator const FileEntry *() const { return has_value() ? &(*this)->getFileEntry() : nullptr; } }; +// Add these operators to resolve ambiguities appearing after replacing +// llvm::Optional with std::optional. +constexpr bool operator==(const std::optional<FileEntryRef> &X, + const std::optional<FileEntryRef> &Y) { + // Copied from llvm::Optional. + if (X && Y) + return *X == *Y; + return X.has_value() == Y.has_value(); +} +constexpr bool operator==(const OptionalFileEntryRefDegradesToFileEntryPtr &X, + const OptionalFileEntryRefDegradesToFileEntryPtr &Y) { + return static_cast<const std::optional<FileEntryRef> &>(X) == + static_cast<const std::optional<FileEntryRef> &>(Y); +} +constexpr bool operator==(const OptionalFileEntryRefDegradesToFileEntryPtr &X, + const std::optional<FileEntryRef> &Y) { + return static_cast<const std::optional<FileEntryRef> &>(X) == Y; +} +constexpr bool operator==(const std::optional<FileEntryRef> &X, + const OptionalFileEntryRefDegradesToFileEntryPtr &Y) { + return X == static_cast<const std::optional<FileEntryRef> &>(Y); +} + static_assert( std::is_trivially_copyable< OptionalFileEntryRefDegradesToFileEntryPtr>::value, "OptionalFileEntryRefDegradesToFileEntryPtr should be trivially copyable"); inline bool operator==(const FileEntry *LHS, - const Optional<FileEntryRef> &RHS) { + const std::optional<FileEntryRef> &RHS) { return LHS == (RHS ? &RHS->getFileEntry() : nullptr); } -inline bool operator==(const Optional<FileEntryRef> &LHS, +inline bool operator==(const std::optional<FileEntryRef> &LHS, const FileEntry *RHS) { return (LHS ? &LHS->getFileEntry() : nullptr) == RHS; } inline bool operator!=(const FileEntry *LHS, - const Optional<FileEntryRef> &RHS) { + const std::optional<FileEntryRef> &RHS) { return !(LHS == RHS); } -inline bool operator!=(const Optional<FileEntryRef> &LHS, +inline bool operator!=(const std::optional<FileEntryRef> &LHS, const FileEntry *RHS) { return !(LHS == RHS); } diff --git a/clang/include/clang/Basic/FileManager.h b/clang/include/clang/Basic/FileManager.h index ec62e00..43cda9d 100644 --- a/clang/include/clang/Basic/FileManager.h +++ b/clang/include/clang/Basic/FileManager.h @@ -31,6 +31,7 @@ #include <ctime> #include <map> #include <memory> +#include <optional> #include <string> namespace llvm { @@ -231,10 +232,10 @@ public: 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) { - return llvm::expectedToOptional( + std::optional<FileEntryRef> getOptionalFileRef(StringRef Filename, + bool OpenFile = false, + bool CacheFailure = true) { + return llvm::expectedToStdOptional( getFileRef(Filename, OpenFile, CacheFailure)); } @@ -270,7 +271,7 @@ public: /// bypasses all mapping and uniquing, blindly creating a new FileEntry. /// There is no attempt to deduplicate these; if you bypass the same file /// twice, you get two new file entries. - llvm::Optional<FileEntryRef> getBypassFile(FileEntryRef VFE); + std::optional<FileEntryRef> getBypassFile(FileEntryRef VFE); /// Open the specified file as a MemoryBuffer, returning a new /// MemoryBuffer if successful, otherwise returning null. diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index c41ae41..02312cd 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -33,6 +33,7 @@ #include <cstdint> #include <ctime> #include <iterator> +#include <optional> #include <string> #include <utility> #include <vector> @@ -185,7 +186,7 @@ private: /// The AST file if this is a top-level module which has a /// corresponding serialized AST file, or null otherwise. - Optional<FileEntryRef> ASTFile; + std::optional<FileEntryRef> ASTFile; /// The top-level headers associated with this module. llvm::SmallSetVector<const FileEntry *, 2> TopHeaders; @@ -610,7 +611,7 @@ public: } /// Set the serialized AST file for the top-level module of this module. - void setASTFile(Optional<FileEntryRef> File) { + void setASTFile(std::optional<FileEntryRef> File) { assert((!getASTFile() || getASTFile() == File) && "file path changed"); getTopLevelModule()->ASTFile = File; } diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h index 20f2415..8b16ab5 100644 --- a/clang/include/clang/Basic/SourceManager.h +++ b/clang/include/clang/Basic/SourceManager.h @@ -53,6 +53,7 @@ #include <cstddef> #include <map> #include <memory> +#include <optional> #include <string> #include <utility> #include <vector> @@ -1003,7 +1004,7 @@ public: /// is no such file in the filesystem. /// /// This should be called before parsing has begun. - Optional<FileEntryRef> bypassFileContentsOverride(FileEntryRef File); + std::optional<FileEntryRef> bypassFileContentsOverride(FileEntryRef File); /// Specify that a file is transient. void setFileIsTransient(const FileEntry *SourceFile); @@ -1049,7 +1050,7 @@ public: } /// Returns the FileEntryRef for the provided FileID. - Optional<FileEntryRef> getFileEntryRefForID(FileID FID) const { + std::optional<FileEntryRef> getFileEntryRefForID(FileID FID) const { if (auto *Entry = getSLocEntryForFile(FID)) return Entry->getFile().getContentCache().OrigEntry; return std::nullopt; diff --git a/clang/include/clang/Lex/DirectoryLookup.h b/clang/include/clang/Lex/DirectoryLookup.h index 375e525..ed54fba 100644 --- a/clang/include/clang/Lex/DirectoryLookup.h +++ b/clang/include/clang/Lex/DirectoryLookup.h @@ -13,10 +13,11 @@ #ifndef LLVM_CLANG_LEX_DIRECTORYLOOKUP_H #define LLVM_CLANG_LEX_DIRECTORYLOOKUP_H -#include "clang/Basic/LLVM.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/LLVM.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/ModuleMap.h" +#include <optional> namespace clang { class HeaderMap; @@ -180,7 +181,7 @@ public: /// \param [out] MappedName if this is a headermap which maps the filename to /// a framework include ("Foo.h" -> "Foo/Foo.h"), set the new name to this /// vector and point Filename to it. - Optional<FileEntryRef> + std::optional<FileEntryRef> LookupFile(StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, @@ -190,7 +191,7 @@ public: bool OpenFile = true) const; private: - Optional<FileEntryRef> DoFrameworkLookup( + std::optional<FileEntryRef> DoFrameworkLookup( StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, diff --git a/clang/include/clang/Lex/HeaderSearch.h b/clang/include/clang/Lex/HeaderSearch.h index 4684f55..637a24c 100644 --- a/clang/include/clang/Lex/HeaderSearch.h +++ b/clang/include/clang/Lex/HeaderSearch.h @@ -28,6 +28,7 @@ #include <cassert> #include <cstddef> #include <memory> +#include <optional> #include <string> #include <utility> #include <vector> @@ -479,7 +480,7 @@ public: /// found in any of searched SearchDirs. Will be set to false if a framework /// is found only through header maps. Doesn't guarantee the requested file is /// found. - Optional<FileEntryRef> LookupFile( + std::optional<FileEntryRef> LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDir, ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers, @@ -495,7 +496,7 @@ public: /// within ".../Carbon.framework/Headers/Carbon.h", check to see if /// HIToolbox is a subframework within Carbon.framework. If so, return /// the FileEntry for the designated file, otherwise return null. - Optional<FileEntryRef> LookupSubframeworkHeader( + std::optional<FileEntryRef> LookupSubframeworkHeader( StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule); @@ -769,7 +770,7 @@ private: /// Look up the file with the specified name and determine its owning /// module. - Optional<FileEntryRef> + std::optional<FileEntryRef> getFileAndSuggestModule(StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir, bool IsSystemHeaderDir, Module *RequestingModule, diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h index 8c8fa4d..1b83321 100644 --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -30,6 +30,7 @@ #include "llvm/ADT/Twine.h" #include <ctime> #include <memory> +#include <optional> #include <string> #include <utility> @@ -606,7 +607,8 @@ public: /// /// \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; + std::optional<FileEntryRef> + getContainingModuleMapFile(const Module *Module) const; /// Get the module map file that (along with the module name) uniquely /// identifies this module. @@ -617,7 +619,8 @@ public: /// 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; + std::optional<FileEntryRef> + getModuleMapFileForUniquing(const Module *M) const; void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap); diff --git a/clang/include/clang/Lex/PPCallbacks.h b/clang/include/clang/Lex/PPCallbacks.h index 045df87..744da1a 100644 --- a/clang/include/clang/Lex/PPCallbacks.h +++ b/clang/include/clang/Lex/PPCallbacks.h @@ -20,6 +20,7 @@ #include "clang/Lex/ModuleLoader.h" #include "clang/Lex/Pragma.h" #include "llvm/ADT/StringRef.h" +#include <optional> namespace clang { class Token; @@ -125,16 +126,12 @@ public: /// 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, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, const Module *Imported, - SrcMgr::CharacteristicKind FileType) { - } + SrcMgr::CharacteristicKind FileType) {} /// Callback invoked whenever a submodule was entered. /// @@ -327,7 +324,7 @@ public: /// 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, + std::optional<FileEntryRef> File, SrcMgr::CharacteristicKind FileType); /// Hook called when a source range is skipped. @@ -458,8 +455,9 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override { First->InclusionDirective(HashLoc, IncludeTok, FileName, IsAngled, FilenameRange, File, SearchPath, RelativePath, @@ -548,7 +546,7 @@ public: } void HasInclude(SourceLocation Loc, StringRef FileName, bool IsAngled, - Optional<FileEntryRef> File, + std::optional<FileEntryRef> File, SrcMgr::CharacteristicKind FileType) override; void PragmaOpenCLExtension(SourceLocation NameLoc, const IdentifierInfo *Name, diff --git a/clang/include/clang/Lex/PreprocessingRecord.h b/clang/include/clang/Lex/PreprocessingRecord.h index ee22f1e..66ca5d3 100644 --- a/clang/include/clang/Lex/PreprocessingRecord.h +++ b/clang/include/clang/Lex/PreprocessingRecord.h @@ -29,6 +29,7 @@ #include <cassert> #include <cstddef> #include <iterator> +#include <optional> #include <utility> #include <vector> @@ -240,12 +241,12 @@ class Token; unsigned ImportedModule : 1; /// The file that was included. - Optional<FileEntryRef> File; + std::optional<FileEntryRef> File; public: InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, - Optional<FileEntryRef> File, SourceRange Range); + std::optional<FileEntryRef> File, SourceRange Range); /// Determine what kind of inclusion directive this is. InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); } @@ -263,7 +264,7 @@ class Token; /// Retrieve the file entry for the actual file that was included /// by this directive. - Optional<FileEntryRef> getFile() const { return File; } + std::optional<FileEntryRef> getFile() const { return File; } // Implement isa/cast/dyncast/etc. static bool classof(const PreprocessedEntity *PE) { @@ -528,8 +529,9 @@ class Token; void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void Ifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD) override; diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 05e05e8..ab481c5 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -51,6 +51,7 @@ #include <cstdint> #include <map> #include <memory> +#include <optional> #include <string> #include <utility> #include <vector> @@ -2243,7 +2244,7 @@ public: /// /// Returns std::nullopt on failure. \p isAngled indicates whether the file /// reference is for system \#include's or not (i.e. using <> instead of ""). - Optional<FileEntryRef> + std::optional<FileEntryRef> LookupFile(SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDir, SmallVectorImpl<char> *SearchPath, @@ -2510,7 +2511,7 @@ private: } }; - Optional<FileEntryRef> LookupHeaderIncludeOrImport( + std::optional<FileEntryRef> LookupHeaderIncludeOrImport( ConstSearchDirIterator *CurDir, StringRef &Filename, SourceLocation FilenameLoc, CharSourceRange FilenameRange, const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl, diff --git a/clang/include/clang/Serialization/ModuleManager.h b/clang/include/clang/Serialization/ModuleManager.h index 5f453c3..1db9e96 100644 --- a/clang/include/clang/Serialization/ModuleManager.h +++ b/clang/include/clang/Serialization/ModuleManager.h @@ -29,6 +29,7 @@ #include <cstdint> #include <ctime> #include <memory> +#include <optional> #include <string> #include <utility> @@ -302,7 +303,8 @@ public: /// modification time criteria, false if the file is either available and /// suitable, or is missing. bool lookupModuleFile(StringRef FileName, off_t ExpectedSize, - time_t ExpectedModTime, Optional<FileEntryRef> &File); + time_t ExpectedModTime, + std::optional<FileEntryRef> &File); /// View the graphviz representation of the module graph. void viewGraph(); diff --git a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h index 1cc6208..cfa0135 100644 --- a/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h +++ b/clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h @@ -19,6 +19,7 @@ #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/StringSet.h" #include "llvm/Support/raw_ostream.h" +#include <optional> #include <string> #include <unordered_map> @@ -134,8 +135,9 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void moduleImport(SourceLocation ImportLoc, ModuleIdPath Path, const Module *Imported) override; diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index d690d4c..e96771f 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -7,7 +7,6 @@ //===----------------------------------------------------------------------===// #include "Transforms.h" -#include "clang/Analysis/RetainSummaryManager.h" #include "clang/ARCMigrate/ARCMT.h" #include "clang/ARCMigrate/ARCMTActions.h" #include "clang/AST/ASTConsumer.h" @@ -17,6 +16,7 @@ #include "clang/AST/ParentMap.h" #include "clang/AST/RecursiveASTVisitor.h" #include "clang/Analysis/DomainSpecific/CocoaConventions.h" +#include "clang/Analysis/RetainSummaryManager.h" #include "clang/Basic/FileManager.h" #include "clang/Edit/Commit.h" #include "clang/Edit/EditedSource.h" @@ -32,6 +32,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/SourceMgr.h" #include "llvm/Support/YAMLParser.h" +#include <optional> using namespace clang; using namespace arcmt; @@ -156,7 +157,7 @@ protected: return AllowListFilenames.find(llvm::sys::path::filename(Path)) != AllowListFilenames.end(); } - bool canModifyFile(Optional<FileEntryRef> FE) { + bool canModifyFile(std::optional<FileEntryRef> FE) { if (!FE) return false; return canModifyFile(FE->getName()); @@ -1958,7 +1959,8 @@ void ObjCMigrateASTConsumer::HandleTranslationUnit(ASTContext &Ctx) { I = rewriter.buffer_begin(), E = rewriter.buffer_end(); I != E; ++I) { FileID FID = I->first; RewriteBuffer &buf = I->second; - Optional<FileEntryRef> file = Ctx.getSourceManager().getFileEntryRefForID(FID); + std::optional<FileEntryRef> file = + Ctx.getSourceManager().getFileEntryRefForID(FID); assert(file); SmallString<512> newText; llvm::raw_svector_ostream vecOS(newText); @@ -2028,7 +2030,7 @@ MigrateSourceAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { namespace { struct EditEntry { - Optional<FileEntryRef> File; + std::optional<FileEntryRef> File; unsigned Offset = 0; unsigned RemoveLen = 0; std::string Text; diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 4fefbaa..1d96093 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) { +std::optional<FileEntryRef> FileManager::getBypassFile(FileEntryRef VF) { // Stat of the file and return nullptr if it doesn't exist. llvm::vfs::Status Status; if (getStatValue(VF.getName(), Status, /*isFile=*/true, /*F=*/nullptr)) diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index 8eca151..c9312c6 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -38,6 +38,7 @@ #include <cstddef> #include <cstdint> #include <memory> +#include <optional> #include <tuple> #include <utility> #include <vector> @@ -712,10 +713,10 @@ void SourceManager::overrideFileContents(const FileEntry *SourceFile, Pair.first->second = NewFile; } -Optional<FileEntryRef> +std::optional<FileEntryRef> SourceManager::bypassFileContentsOverride(FileEntryRef File) { assert(isFileOverridden(&File.getFileEntry())); - llvm::Optional<FileEntryRef> BypassFile = FileMgr.getBypassFile(File); + std::optional<FileEntryRef> BypassFile = FileMgr.getBypassFile(File); // If the file can't be found in the FS, give up. if (!BypassFile) diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 382b7f3..2bd7faa 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 (std::optional<FileEntryRef> MainFile = SM.getFileEntryRefForID(SM.getMainFileID())) { MainFileDir = std::string(MainFile->getDir().getName()); if (!llvm::sys::path::is_absolute(MainFileName)) { diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp index 563d540..f7cb2d0 100644 --- a/clang/lib/CodeGen/CGObjCGNU.cpp +++ b/clang/lib/CodeGen/CGObjCGNU.cpp @@ -36,6 +36,7 @@ #include "llvm/Support/Compiler.h" #include "llvm/Support/ConvertUTF.h" #include <cctype> +#include <optional> using namespace clang; using namespace CodeGen; @@ -3864,7 +3865,7 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() { // The path to the source file where this module was declared SourceManager &SM = CGM.getContext().getSourceManager(); - Optional<FileEntryRef> mainFile = + std::optional<FileEntryRef> mainFile = SM.getFileEntryRefForID(SM.getMainFileID()); std::string path = (mainFile->getDir().getName() + "/" + mainFile->getName()).str(); diff --git a/clang/lib/CodeGen/MacroPPCallbacks.cpp b/clang/lib/CodeGen/MacroPPCallbacks.cpp index 076d299..c5e5556 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.cpp +++ b/clang/lib/CodeGen/MacroPPCallbacks.cpp @@ -15,6 +15,7 @@ #include "clang/CodeGen/ModuleBuilder.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/Preprocessor.h" +#include <optional> using namespace clang; @@ -167,8 +168,9 @@ void MacroPPCallbacks::FileChanged(SourceLocation Loc, FileChangeReason Reason, void MacroPPCallbacks::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { // Record the line location of the current included file. diff --git a/clang/lib/CodeGen/MacroPPCallbacks.h b/clang/lib/CodeGen/MacroPPCallbacks.h index 01041b16..f16521c 100644 --- a/clang/lib/CodeGen/MacroPPCallbacks.h +++ b/clang/lib/CodeGen/MacroPPCallbacks.h @@ -14,6 +14,7 @@ #define LLVM_CLANG_LIB_CODEGEN_MACROPPCALLBACKS_H #include "clang/Lex/PPCallbacks.h" +#include <optional> namespace llvm { class DIMacroFile; @@ -101,8 +102,9 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; /// Hook called whenever a macro definition is seen. diff --git a/clang/lib/Frontend/CompilerInstance.cpp b/clang/lib/Frontend/CompilerInstance.cpp index acb3cb8..8238779 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); + std::optional<FileEntryRef> ToFile = FileMgr.getOptionalFileRef(RF.second); if (!ToFile) { Diags.Report(diag::err_fe_remap_missing_to_file) << RF.first << RF.second; continue; @@ -1281,8 +1281,8 @@ compileModuleImpl(CompilerInstance &ImportingInstance, SourceLocation ImportLoc, Instance.getFrontendOpts().AllowPCMWithCompilerErrors; } -static Optional<FileEntryRef> getPublicModuleMap(FileEntryRef File, - FileManager &FileMgr) { +static std::optional<FileEntryRef> getPublicModuleMap(FileEntryRef File, + FileManager &FileMgr) { StringRef Filename = llvm::sys::path::filename(File.getName()); SmallString<128> PublicFilename(File.getDir().getName()); if (Filename == "module_private.map") @@ -1307,12 +1307,12 @@ static bool compileModule(CompilerInstance &ImportingInstance, ModuleMap &ModMap = ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); bool Result; - if (Optional<FileEntryRef> ModuleMapFile = + if (std::optional<FileEntryRef> ModuleMapFile = ModMap.getContainingModuleMapFile(Module)) { // Canonicalize compilation to start with the public module map. This is // vital for submodules declarations in the private module maps to be // correctly parsed when depending on a top level module in the public one. - if (Optional<FileEntryRef> PublicMMFile = getPublicModuleMap( + if (std::optional<FileEntryRef> PublicMMFile = getPublicModuleMap( *ModuleMapFile, ImportingInstance.getFileManager())) ModuleMapFile = PublicMMFile; diff --git a/clang/lib/Frontend/DependencyFile.cpp b/clang/lib/Frontend/DependencyFile.cpp index 8d712a2..500c08c 100644 --- a/clang/lib/Frontend/DependencyFile.cpp +++ b/clang/lib/Frontend/DependencyFile.cpp @@ -10,11 +10,11 @@ // //===----------------------------------------------------------------------===// -#include "clang/Frontend/Utils.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/DependencyOutputOptions.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/Frontend/Utils.h" #include "clang/Lex/DirectoryLookup.h" #include "clang/Lex/ModuleMap.h" #include "clang/Lex/PPCallbacks.h" @@ -24,6 +24,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include <optional> using namespace clang; @@ -64,8 +65,9 @@ struct DepCollectorPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override { if (!File) DepCollector.maybeAddDependency(FileName, /*FromModule*/false, @@ -75,7 +77,7 @@ struct DepCollectorPPCallbacks : public PPCallbacks { } void HasInclude(SourceLocation Loc, StringRef SpelledFilename, bool IsAngled, - Optional<FileEntryRef> File, + std::optional<FileEntryRef> File, SrcMgr::CharacteristicKind FileType) override { if (!File) return; diff --git a/clang/lib/Frontend/DependencyGraph.cpp b/clang/lib/Frontend/DependencyGraph.cpp index 4cbdb3d..ccf34ac 100644 --- a/clang/lib/Frontend/DependencyGraph.cpp +++ b/clang/lib/Frontend/DependencyGraph.cpp @@ -11,15 +11,16 @@ // //===----------------------------------------------------------------------===// -#include "clang/Frontend/Utils.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/Frontend/Utils.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/SetVector.h" #include "llvm/Support/GraphWriter.h" #include "llvm/Support/raw_ostream.h" +#include <optional> using namespace clang; namespace DOT = llvm::DOT; @@ -48,8 +49,9 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void EndOfMainFile() override { @@ -66,21 +68,16 @@ void clang::AttachDependencyGraphGen(Preprocessor &PP, StringRef OutputFile, } void DependencyGraphCallback::InclusionDirective( - SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional<FileEntryRef> File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported, + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, + std::optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!File) return; SourceManager &SM = PP->getSourceManager(); - Optional<FileEntryRef> FromFile = + std::optional<FileEntryRef> FromFile = SM.getFileEntryRefForID(SM.getFileID(SM.getExpansionLoc(HashLoc))); if (!FromFile) return; diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index e97a2dd..a3b4080 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -40,6 +40,7 @@ #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" #include <memory> +#include <optional> #include <system_error> using namespace clang; @@ -823,7 +824,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 = + std::optional<FileEntryRef> FE = HS.LookupFile(FileName, SourceLocation(), /*Angled*/ Input.getKind().getHeaderUnitKind() == InputKind::HeaderUnit_System, diff --git a/clang/lib/Frontend/ModuleDependencyCollector.cpp b/clang/lib/Frontend/ModuleDependencyCollector.cpp index 7e19ed3..785bff7 100644 --- a/clang/lib/Frontend/ModuleDependencyCollector.cpp +++ b/clang/lib/Frontend/ModuleDependencyCollector.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include <optional> using namespace clang; @@ -48,8 +49,9 @@ struct ModuleDependencyPPCallbacks : public PPCallbacks { void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override { if (!File) return; diff --git a/clang/lib/Frontend/PrecompiledPreamble.cpp b/clang/lib/Frontend/PrecompiledPreamble.cpp index e3c3466..9da3306 100644 --- a/clang/lib/Frontend/PrecompiledPreamble.cpp +++ b/clang/lib/Frontend/PrecompiledPreamble.cpp @@ -33,6 +33,7 @@ #include "llvm/Support/VirtualFileSystem.h" #include <limits> #include <mutex> +#include <optional> #include <utility> using namespace clang; @@ -97,8 +98,9 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override { // File is None if it wasn't found. // (We have some false negatives if PP recovered e.g. <foo> -> "foo") diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index d81a11a..8274a2f 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -11,11 +11,11 @@ // //===----------------------------------------------------------------------===// -#include "clang/Frontend/Utils.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceManager.h" #include "clang/Frontend/PreprocessorOutputOptions.h" +#include "clang/Frontend/Utils.h" #include "clang/Lex/MacroInfo.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Pragma.h" @@ -27,6 +27,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" #include <cstdio> +#include <optional> using namespace clang; /// PrintMacroDefinition - Print a macro definition in a form that will be @@ -146,8 +147,9 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void Ident(SourceLocation Loc, StringRef str) override; void PragmaMessage(SourceLocation Loc, StringRef Namespace, @@ -389,15 +391,10 @@ 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, + std::optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { // In -dI mode, dump #include directives prior to dumping their content or // interpretation. diff --git a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp index 37178d1..7fa2328 100644 --- a/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp +++ b/clang/lib/Frontend/Rewrite/InclusionRewriter.cpp @@ -74,8 +74,9 @@ private: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override; void If(SourceLocation Loc, SourceRange ConditionRange, ConditionValueKind ConditionValue) override; @@ -182,16 +183,12 @@ void InclusionRewriter::FileSkipped(const FileEntryRef & /*SkippedFile*/, /// FileChanged() or FileSkipped() is called after this (or neither is /// called if this #include results in an error or does not textually include /// anything). -void InclusionRewriter::InclusionDirective(SourceLocation HashLoc, - const Token &/*IncludeTok*/, - StringRef /*FileName*/, - bool /*IsAngled*/, - CharSourceRange /*FilenameRange*/, - Optional<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*/, std::optional<FileEntryRef> /*File*/, + StringRef /*SearchPath*/, StringRef /*RelativePath*/, + const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (Imported) { auto P = ModuleIncludes.insert(std::make_pair(HashLoc, Imported)); (void)P; diff --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp index f67dcee..b6e2533 100644 --- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp +++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp @@ -40,6 +40,7 @@ #include <cstring> #include <iterator> #include <memory> +#include <optional> #include <string> #include <utility> #include <vector> @@ -541,7 +542,7 @@ static bool ParseDirective(StringRef S, ExpectedData *ED, SourceManager &SM, ExpectedLoc = SourceLocation(); } else { // Lookup file via Preprocessor, like a #include. - Optional<FileEntryRef> File = + std::optional<FileEntryRef> File = PP->LookupFile(Pos, Filename, false, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (!File) { diff --git a/clang/lib/Index/IndexingAction.cpp b/clang/lib/Index/IndexingAction.cpp index c9fcaad..a958b64 100644 --- a/clang/lib/Index/IndexingAction.cpp +++ b/clang/lib/Index/IndexingAction.cpp @@ -17,6 +17,7 @@ #include "clang/Serialization/ASTReader.h" #include "llvm/ADT/STLExtras.h" #include <memory> +#include <optional> using namespace clang; using namespace clang::index; diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 1ce6df4..ffb2780 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -25,11 +25,11 @@ #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/Hashing.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Errc.h" @@ -42,6 +42,7 @@ #include <cstddef> #include <cstdio> #include <cstring> +#include <optional> #include <string> #include <system_error> #include <utility> @@ -171,7 +172,7 @@ void HeaderSearch::getHeaderMapFileNames( } std::string HeaderSearch::getCachedModuleFileName(Module *Module) { - Optional<FileEntryRef> ModuleMap = + std::optional<FileEntryRef> ModuleMap = getModuleMap().getModuleMapFileForUniquing(Module); // The ModuleMap maybe a nullptr, when we load a cached C++ module without // *.modulemap file. In this case, just return an empty string. @@ -212,7 +213,7 @@ std::string HeaderSearch::getPrebuiltModuleFileName(StringRef ModuleName, } std::string HeaderSearch::getPrebuiltImplicitModuleFileName(Module *Module) { - Optional<FileEntryRef> ModuleMap = + std::optional<FileEntryRef> ModuleMap = getModuleMap().getModuleMapFileForUniquing(Module); StringRef ModuleName = Module->Name; StringRef ModuleMapPath = ModuleMap->getName(); @@ -415,7 +416,7 @@ StringRef DirectoryLookup::getName() const { return getHeaderMap()->getFileName(); } -Optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule( +std::optional<FileEntryRef> HeaderSearch::getFileAndSuggestModule( StringRef FileName, SourceLocation IncludeLoc, const DirectoryEntry *Dir, bool IsSystemHeaderDir, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, bool OpenFile /*=true*/, @@ -447,7 +448,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( +std::optional<FileEntryRef> DirectoryLookup::LookupFile( StringRef &Filename, HeaderSearch &HS, SourceLocation IncludeLoc, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, @@ -586,7 +587,7 @@ static bool needModuleLookup(Module *RequestingModule, /// DoFrameworkLookup - Do a lookup of the specified file in the current /// DirectoryLookup, which is a framework directory. -Optional<FileEntryRef> DirectoryLookup::DoFrameworkLookup( +std::optional<FileEntryRef> DirectoryLookup::DoFrameworkLookup( StringRef Filename, HeaderSearch &HS, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule, @@ -855,7 +856,7 @@ diagnoseFrameworkInclude(DiagnosticsEngine &Diags, SourceLocation IncludeLoc, /// for system \#include's or not (i.e. using <> instead of ""). Includers, if /// non-empty, indicates where the \#including file(s) are, in case a relative /// search is needed. Microsoft mode will pass all \#including files. -Optional<FileEntryRef> HeaderSearch::LookupFile( +std::optional<FileEntryRef> HeaderSearch::LookupFile( StringRef Filename, SourceLocation IncludeLoc, bool isAngled, ConstSearchDirIterator FromDir, ConstSearchDirIterator *CurDirArg, ArrayRef<std::pair<const FileEntry *, const DirectoryEntry *>> Includers, @@ -898,7 +899,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( // This is the header that MSVC's header search would have found. ModuleMap::KnownHeader MSSuggestedModule; - Optional<FileEntryRef> MSFE; + std::optional<FileEntryRef> MSFE; // Unless disabled, check to see if the file is in the #includer's // directory. This cannot be based on CurDir, because each includer could be @@ -927,7 +928,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( bool IncluderIsSystemHeader = Includer ? getFileInfo(Includer).DirInfo != SrcMgr::C_User : BuildSystemModule; - if (Optional<FileEntryRef> FE = getFileAndSuggestModule( + if (std::optional<FileEntryRef> FE = getFileAndSuggestModule( TmpDir, IncludeLoc, IncluderAndDir.second, IncluderIsSystemHeader, RequestingModule, SuggestedModule)) { if (!Includer) { @@ -1043,7 +1044,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( bool InUserSpecifiedSystemFramework = false; bool IsInHeaderMap = false; bool IsFrameworkFoundInDir = false; - Optional<FileEntryRef> File = It->LookupFile( + std::optional<FileEntryRef> File = It->LookupFile( Filename, *this, IncludeLoc, SearchPath, RelativePath, RequestingModule, SuggestedModule, InUserSpecifiedSystemFramework, IsFrameworkFoundInDir, IsInHeaderMap, MappedName, OpenFile); @@ -1138,7 +1139,7 @@ Optional<FileEntryRef> HeaderSearch::LookupFile( ScratchFilename += '/'; ScratchFilename += Filename; - Optional<FileEntryRef> File = LookupFile( + std::optional<FileEntryRef> File = LookupFile( ScratchFilename, IncludeLoc, /*isAngled=*/true, FromDir, &CurDir, Includers.front(), SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, /*IsFrameworkFound=*/nullptr); @@ -1175,7 +1176,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( +std::optional<FileEntryRef> HeaderSearch::LookupSubframeworkHeader( StringRef Filename, const FileEntry *ContextFileEnt, SmallVectorImpl<char> *SearchPath, SmallVectorImpl<char> *RelativePath, Module *RequestingModule, ModuleMap::KnownHeader *SuggestedModule) { diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index f5a7f51..c061790 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -46,6 +46,7 @@ #include <cassert> #include <cstdint> #include <cstring> +#include <optional> #include <string> #include <system_error> #include <utility> @@ -1258,7 +1259,7 @@ void ModuleMap::addHeader(Module *Mod, Module::Header Header, Cb->moduleMapAddHeader(Header.Entry->getName()); } -Optional<FileEntryRef> +std::optional<FileEntryRef> ModuleMap::getContainingModuleMapFile(const Module *Module) const { if (Module->DefinitionLoc.isInvalid()) return std::nullopt; @@ -1267,7 +1268,7 @@ ModuleMap::getContainingModuleMapFile(const Module *Module) const { SourceMgr.getFileID(Module->DefinitionLoc)); } -Optional<FileEntryRef> +std::optional<FileEntryRef> ModuleMap::getModuleMapFileForUniquing(const Module *M) const { if (M->IsInferred) { assert(InferredModuleAllowedBy.count(M) && "missing inferred module map"); diff --git a/clang/lib/Lex/PPCallbacks.cpp b/clang/lib/Lex/PPCallbacks.cpp index b618071..9c98669 100644 --- a/clang/lib/Lex/PPCallbacks.cpp +++ b/clang/lib/Lex/PPCallbacks.cpp @@ -8,6 +8,7 @@ #include "clang/Lex/PPCallbacks.h" #include "clang/Basic/FileManager.h" +#include <optional> using namespace clang; @@ -15,16 +16,16 @@ using namespace clang; PPCallbacks::~PPCallbacks() = default; void PPCallbacks::HasInclude(SourceLocation Loc, StringRef FileName, - bool IsAngled, Optional<FileEntryRef> File, + bool IsAngled, std::optional<FileEntryRef> 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, + std::optional<FileEntryRef> File, SrcMgr::CharacteristicKind FileType) { First->HasInclude(Loc, FileName, IsAngled, File, FileType); Second->HasInclude(Loc, FileName, IsAngled, File, FileType); } - diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 5264c00..fcac1bf 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -47,6 +47,7 @@ #include <cassert> #include <cstring> #include <new> +#include <optional> #include <string> #include <utility> @@ -947,7 +948,7 @@ Preprocessor::getHeaderToIncludeForDiagnostics(SourceLocation IncLoc, return nullptr; } -Optional<FileEntryRef> Preprocessor::LookupFile( +std::optional<FileEntryRef> Preprocessor::LookupFile( SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDirArg, SmallVectorImpl<char> *SearchPath, @@ -1012,7 +1013,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 (std::optional<FileEntryRef> FE = HeaderInfo.LookupFile( Filename, FilenameLoc, isAngled, TmpFromDir, &TmpCurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, /*IsMapped=*/nullptr, @@ -1030,7 +1031,7 @@ Optional<FileEntryRef> Preprocessor::LookupFile( } // Do a standard file entry lookup. - Optional<FileEntryRef> FE = HeaderInfo.LookupFile( + std::optional<FileEntryRef> FE = HeaderInfo.LookupFile( Filename, FilenameLoc, isAngled, FromDir, &CurDir, Includers, SearchPath, RelativePath, RequestingModule, SuggestedModule, IsMapped, IsFrameworkFound, SkipCache, BuildSystemModule, OpenFile, CacheFailures); @@ -1048,7 +1049,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 (std::optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader( Filename, CurFileEnt, SearchPath, RelativePath, RequestingModule, SuggestedModule)) { if (SuggestedModule && !LangOpts.AsmPreprocessor) @@ -1063,9 +1064,10 @@ Optional<FileEntryRef> Preprocessor::LookupFile( for (IncludeStackInfo &ISEntry : llvm::reverse(IncludeMacroStack)) { if (IsFileLexer(ISEntry)) { if ((CurFileEnt = ISEntry.ThePPLexer->getFileEntry())) { - if (Optional<FileEntryRef> FE = HeaderInfo.LookupSubframeworkHeader( - Filename, CurFileEnt, SearchPath, RelativePath, - RequestingModule, SuggestedModule)) { + if (std::optional<FileEntryRef> FE = + HeaderInfo.LookupSubframeworkHeader( + Filename, CurFileEnt, SearchPath, RelativePath, + RequestingModule, SuggestedModule)) { if (SuggestedModule && !LangOpts.AsmPreprocessor) HeaderInfo.getModuleMap().diagnoseHeaderInclusion( RequestingModule, RequestingModuleIsModuleInterface, @@ -2003,7 +2005,7 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc, } } -Optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( +std::optional<FileEntryRef> Preprocessor::LookupHeaderIncludeOrImport( ConstSearchDirIterator *CurDir, StringRef &Filename, SourceLocation FilenameLoc, CharSourceRange FilenameRange, const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl, @@ -2011,9 +2013,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, + std::optional<FileEntryRef> File = LookupFile( + FilenameLoc, LookupFilename, isAngled, LookupFrom, LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, &IsFrameworkFound); if (File) @@ -2026,9 +2027,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, + std::optional<FileEntryRef> File = LookupFile( + FilenameLoc, LookupFilename, false, LookupFrom, LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, /*IsFrameworkFound=*/nullptr); @@ -2057,9 +2057,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, + std::optional<FileEntryRef> File = LookupFile( + FilenameLoc, TypoCorrectionLookupName, isAngled, LookupFrom, + LookupFromFile, CurDir, Callbacks ? &SearchPath : nullptr, Callbacks ? &RelativePath : nullptr, &SuggestedModule, &IsMapped, /*IsFrameworkFound=*/nullptr); if (File) { @@ -2182,7 +2182,7 @@ Preprocessor::ImportAction Preprocessor::HandleHeaderIncludeOrImport( BackslashStyle = llvm::sys::path::Style::windows; } - Optional<FileEntryRef> File = LookupHeaderIncludeOrImport( + std::optional<FileEntryRef> File = LookupHeaderIncludeOrImport( &CurDir, Filename, FilenameLoc, FilenameRange, FilenameTok, IsFrameworkFound, IsImportDecl, IsMapped, LookupFrom, LookupFromFile, LookupFilename, RelativePath, SearchPath, SuggestedModule, isAngled); diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp index 36d3aa5..b68a455 100644 --- a/clang/lib/Lex/PPLexerChange.cpp +++ b/clang/lib/Lex/PPLexerChange.cpp @@ -22,6 +22,7 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/MemoryBufferRef.h" #include "llvm/Support/Path.h" +#include <optional> using namespace clang; @@ -94,7 +95,8 @@ bool Preprocessor::EnterSourceFile(FileID FID, ConstSearchDirIterator CurDir, Lexer *TheLexer = new Lexer(FID, *InputFile, *this, IsFirstIncludeOfFile); if (getPreprocessorOpts().DependencyDirectivesForFile && FID != PredefinesFileID) { - if (Optional<FileEntryRef> File = SourceMgr.getFileEntryRefForID(FID)) { + if (std::optional<FileEntryRef> File = + SourceMgr.getFileEntryRefForID(FID)) { if (Optional<ArrayRef<dependency_directives_scan::Directive>> DepDirectives = getPreprocessorOpts().DependencyDirectivesForFile(*File)) { diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index c33c9d1..6f85d93 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -53,6 +53,7 @@ #include <cstddef> #include <cstring> #include <ctime> +#include <optional> #include <string> #include <tuple> #include <utility> @@ -1249,7 +1250,7 @@ static bool EvaluateHasIncludeCommon(Token &Tok, IdentifierInfo *II, return false; // Search include directories. - Optional<FileEntryRef> File = + std::optional<FileEntryRef> File = PP.LookupFile(FilenameLoc, Filename, isAngled, LookupFrom, LookupFromFile, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 01e0dbe..e55fbb5 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -48,6 +48,7 @@ #include <cstddef> #include <cstdint> #include <limits> +#include <optional> #include <string> #include <utility> #include <vector> @@ -527,7 +528,7 @@ void Preprocessor::HandlePragmaDependency(Token &DependencyTok) { return; // Search include directories for this file. - Optional<FileEntryRef> File = + std::optional<FileEntryRef> File = LookupFile(FilenameTok.getLocation(), Filename, isAngled, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr); if (!File) { diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index 35f9e4d..1d5a291 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -31,6 +31,7 @@ #include <cstddef> #include <cstring> #include <iterator> +#include <optional> #include <utility> #include <vector> @@ -42,7 +43,7 @@ ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() = InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, - Optional<FileEntryRef> File, + std::optional<FileEntryRef> File, SourceRange Range) : PreprocessingDirective(InclusionDirectiveKind, Range), InQuotes(InQuotes), Kind(Kind), ImportedModule(ImportedModule), File(File) { @@ -475,15 +476,10 @@ void PreprocessingRecord::MacroUndefined(const Token &Id, } void PreprocessingRecord::InclusionDirective( - SourceLocation HashLoc, - const Token &IncludeTok, - StringRef FileName, - bool IsAngled, - CharSourceRange FilenameRange, - Optional<FileEntryRef> File, - StringRef SearchPath, - StringRef RelativePath, - const Module *Imported, + SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, + bool IsAngled, CharSourceRange FilenameRange, + std::optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { InclusionDirective::InclusionKind Kind = InclusionDirective::Include; diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 281683b..b1cb81c 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -65,6 +65,7 @@ #include <algorithm> #include <cassert> #include <memory> +#include <optional> #include <string> #include <utility> #include <vector> @@ -580,7 +581,7 @@ void Preprocessor::EnterMainSourceFile() { if (!PPOpts->PCHThroughHeader.empty()) { // Lookup and save the FileID for the through header. If it isn't found // in the search path, it's a fatal error. - Optional<FileEntryRef> File = LookupFile( + std::optional<FileEntryRef> File = LookupFile( SourceLocation(), PPOpts->PCHThroughHeader, /*isAngled=*/false, /*FromDir=*/nullptr, /*FromFile=*/nullptr, /*CurDir=*/nullptr, /*SearchPath=*/nullptr, /*RelativePath=*/nullptr, diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp index bb045760..3383bdb 100644 --- a/clang/lib/Sema/SemaModule.cpp +++ b/clang/lib/Sema/SemaModule.cpp @@ -15,6 +15,7 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/Preprocessor.h" #include "clang/Sema/SemaInternal.h" +#include <optional> using namespace clang; using namespace sema; @@ -320,7 +321,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc, Diag(Path[0].second, diag::err_module_redefinition) << ModuleName; if (M->DefinitionLoc.isValid()) Diag(M->DefinitionLoc, diag::note_prev_module_definition); - else if (Optional<FileEntryRef> FE = M->getASTFile()) + else if (std::optional<FileEntryRef> FE = M->getASTFile()) Diag(M->DefinitionLoc, diag::note_prev_module_definition_from_ast_file) << FE->getName(); Mod = M; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 63c525a..4b765b3 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -135,6 +135,7 @@ #include <limits> #include <map> #include <memory> +#include <optional> #include <string> #include <system_error> #include <tuple> @@ -1520,7 +1521,7 @@ bool ASTReader::ReadSLocEntry(int ID) { // we will also try to fail gracefully by setting up the SLocEntry. unsigned InputID = Record[4]; InputFile IF = getInputFile(*F, InputID); - Optional<FileEntryRef> File = IF.getFile(); + std::optional<FileEntryRef> File = IF.getFile(); bool OverriddenBuffer = IF.isOverridden(); // Note that we only check if a File was returned. If it was out-of-date @@ -2362,7 +2363,7 @@ InputFile ASTReader::getInputFile(ModuleFile &F, unsigned ID, bool Complain) { uint64_t StoredContentHash = FI.ContentHash; OptionalFileEntryRefDegradesToFileEntryPtr File = - expectedToOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)); + expectedToStdOptional(FileMgr.getFileRef(Filename, /*OpenFile=*/false)); // For an overridden file, create a virtual file with the stored // size/timestamp. @@ -3964,7 +3965,7 @@ ASTReader::ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F, Module *M = PP.getHeaderSearchInfo().lookupModule(F.ModuleName, F.ImportLoc); auto &Map = PP.getHeaderSearchInfo().getModuleMap(); - Optional<FileEntryRef> ModMap = + std::optional<FileEntryRef> ModMap = M ? Map.getModuleMapFileForUniquing(M) : std::nullopt; // Don't emit module relocation error if we have -fno-validate-pch if (!bool(PP.getPreprocessorOpts().DisablePCHOrModuleValidation & @@ -6126,7 +6127,7 @@ PreprocessedEntity *ASTReader::ReadPreprocessedEntity(unsigned Index) { case PPD_INCLUSION_DIRECTIVE: { const char *FullFileNameStart = Blob.data() + Record[0]; StringRef FullFileName(FullFileNameStart, Blob.size() - Record[0]); - Optional<FileEntryRef> File; + std::optional<FileEntryRef> File; if (!FullFileName.empty()) File = PP.getFileManager().getOptionalFileRef(FullFileName); diff --git a/clang/lib/Serialization/ModuleManager.cpp b/clang/lib/Serialization/ModuleManager.cpp index ae4ea61..b9fa23b 100644 --- a/clang/lib/Serialization/ModuleManager.cpp +++ b/clang/lib/Serialization/ModuleManager.cpp @@ -35,6 +35,7 @@ #include <algorithm> #include <cassert> #include <memory> +#include <optional> #include <string> #include <system_error> @@ -444,7 +445,7 @@ void ModuleManager::visit(llvm::function_ref<bool(ModuleFile &M)> Visitor, bool ModuleManager::lookupModuleFile(StringRef FileName, off_t ExpectedSize, time_t ExpectedModTime, - Optional<FileEntryRef> &File) { + std::optional<FileEntryRef> &File) { File = std::nullopt; if (FileName == "-") return false; diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index e599681..6ab476b 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -14,6 +14,7 @@ #include "clang/Tooling/DependencyScanning/DependencyScanningWorker.h" #include "llvm/Support/BLAKE3.h" #include "llvm/Support/StringSaver.h" +#include <optional> using namespace clang; using namespace tooling; @@ -237,7 +238,7 @@ void ModuleDepCollector::applyDiscoveredDependencies(CompilerInvocation &CI) { if (llvm::any_of(CI.getFrontendOpts().Inputs, needsModules)) { Preprocessor &PP = ScanInstance.getPreprocessor(); if (Module *CurrentModule = PP.getCurrentModuleImplementation()) - if (Optional<FileEntryRef> CurrentModuleMap = + if (std::optional<FileEntryRef> CurrentModuleMap = PP.getHeaderSearchInfo() .getModuleMap() .getModuleMapFileForUniquing(CurrentModule)) @@ -334,8 +335,9 @@ void ModuleDepCollectorPP::FileChanged(SourceLocation Loc, void ModuleDepCollectorPP::InclusionDirective( SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, - bool IsAngled, CharSourceRange FilenameRange, Optional<FileEntryRef> File, - StringRef SearchPath, StringRef RelativePath, const Module *Imported, + bool IsAngled, CharSourceRange FilenameRange, + std::optional<FileEntryRef> File, StringRef SearchPath, + StringRef RelativePath, const Module *Imported, SrcMgr::CharacteristicKind FileType) { if (!File && !Imported) { // This is a non-modular include that HeaderSearch failed to find. Add it @@ -419,7 +421,8 @@ ModuleID ModuleDepCollectorPP::handleTopLevelModule(const Module *M) { ModuleMap &ModMapInfo = MDC.ScanInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap(); - Optional<FileEntryRef> ModuleMap = ModMapInfo.getModuleMapFileForUniquing(M); + std::optional<FileEntryRef> ModuleMap = + ModMapInfo.getModuleMapFileForUniquing(M); if (ModuleMap) { SmallString<128> Path = ModuleMap->getNameAsRequested(); diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index 9958671..37bca8c 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -57,6 +57,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/thread.h" #include <mutex> +#include <optional> #if LLVM_ENABLE_THREADS != 0 && defined(__APPLE__) #define USE_DARWIN_THREADS @@ -8531,7 +8532,7 @@ CXFile clang_getIncludedFile(CXCursor cursor) { return nullptr; const InclusionDirective *ID = getCursorInclusionDirective(cursor); - Optional<FileEntryRef> File = ID->getFile(); + std::optional<FileEntryRef> File = ID->getFile(); return const_cast<FileEntry *>(File ? &File->getFileEntry() : nullptr); } diff --git a/clang/tools/libclang/CXIndexDataConsumer.cpp b/clang/tools/libclang/CXIndexDataConsumer.cpp index 979acae..0a30891 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.cpp +++ b/clang/tools/libclang/CXIndexDataConsumer.cpp @@ -14,6 +14,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/DeclVisitor.h" #include "clang/Frontend/ASTUnit.h" +#include <optional> using namespace clang; using namespace clang::index; @@ -463,10 +464,10 @@ void CXIndexDataConsumer::enteredMainFile(const FileEntry *File) { } void CXIndexDataConsumer::ppIncludedFile(SourceLocation hashLoc, - StringRef filename, - Optional<FileEntryRef> File, - bool isImport, bool isAngled, - bool isModuleImport) { + StringRef filename, + std::optional<FileEntryRef> File, + bool isImport, bool isAngled, + bool isModuleImport) { if (!CB.ppIncludedFile) return; diff --git a/clang/tools/libclang/CXIndexDataConsumer.h b/clang/tools/libclang/CXIndexDataConsumer.h index 04c64ca..3be37a2 100644 --- a/clang/tools/libclang/CXIndexDataConsumer.h +++ b/clang/tools/libclang/CXIndexDataConsumer.h @@ -11,10 +11,11 @@ #include "CXCursor.h" #include "Index_Internal.h" -#include "clang/Index/IndexDataConsumer.h" #include "clang/AST/DeclGroup.h" #include "clang/AST/DeclObjC.h" +#include "clang/Index/IndexDataConsumer.h" #include "llvm/ADT/DenseSet.h" +#include <optional> namespace clang { class FileEntry; @@ -363,8 +364,8 @@ public: void enteredMainFile(const FileEntry *File); void ppIncludedFile(SourceLocation hashLoc, StringRef filename, - Optional<FileEntryRef> File, bool isImport, bool isAngled, - bool isModuleImport); + std::optional<FileEntryRef> File, bool isImport, + bool isAngled, bool isModuleImport); void importedModule(const ImportDecl *ImportD); void importedPCH(const FileEntry *File); diff --git a/clang/tools/libclang/Indexing.cpp b/clang/tools/libclang/Indexing.cpp index 206dd48..752b7fb 100644 --- a/clang/tools/libclang/Indexing.cpp +++ b/clang/tools/libclang/Indexing.cpp @@ -31,6 +31,7 @@ #include "llvm/Support/MemoryBuffer.h" #include <cstdio> #include <mutex> +#include <optional> #include <utility> using namespace clang; @@ -262,8 +263,9 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override { bool isImport = (IncludeTok.is(tok::identifier) && IncludeTok.getIdentifierInfo()->getPPKeywordID() == tok::pp_import); diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp index 6fe4a3d..6ccde51 100644 --- a/clang/unittests/Basic/FileManagerTest.cpp +++ b/clang/unittests/Basic/FileManagerTest.cpp @@ -14,6 +14,7 @@ #include "llvm/Support/VirtualFileSystem.h" #include "llvm/Testing/Support/Error.h" #include "gtest/gtest.h" +#include <optional> using namespace llvm; using namespace clang; @@ -542,7 +543,7 @@ TEST_F(FileManagerTest, getBypassFile) { EXPECT_EQ(FE.getSize(), 10); // Bypass the file. - llvm::Optional<FileEntryRef> BypassRef = + std::optional<FileEntryRef> BypassRef = Manager.getBypassFile(File->getLastRef()); ASSERT_TRUE(BypassRef); EXPECT_EQ("/tmp/test", BypassRef->getName()); diff --git a/clang/unittests/Lex/PPCallbacksTest.cpp b/clang/unittests/Lex/PPCallbacksTest.cpp index 43f7b4a..a8d3aa3 100644 --- a/clang/unittests/Lex/PPCallbacksTest.cpp +++ b/clang/unittests/Lex/PPCallbacksTest.cpp @@ -6,7 +6,6 @@ // //===--------------------------------------------------------------===// -#include "clang/Lex/Preprocessor.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" #include "clang/Basic/Diagnostic.h" @@ -19,12 +18,14 @@ #include "clang/Lex/HeaderSearch.h" #include "clang/Lex/HeaderSearchOptions.h" #include "clang/Lex/ModuleLoader.h" +#include "clang/Lex/Preprocessor.h" #include "clang/Lex/PreprocessorOptions.h" #include "clang/Parse/Parser.h" #include "clang/Sema/Sema.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/Path.h" #include "gtest/gtest.h" +#include <optional> using namespace clang; @@ -36,8 +37,9 @@ public: void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, - Optional<FileEntryRef> File, StringRef SearchPath, - StringRef RelativePath, const Module *Imported, + std::optional<FileEntryRef> File, + StringRef SearchPath, StringRef RelativePath, + const Module *Imported, SrcMgr::CharacteristicKind FileType) override { this->HashLoc = HashLoc; this->IncludeTok = IncludeTok; @@ -56,7 +58,7 @@ public: SmallString<16> FileName; bool IsAngled; CharSourceRange FilenameRange; - Optional<FileEntryRef> File; + std::optional<FileEntryRef> File; SmallString<16> SearchPath; SmallString<16> RelativePath; const Module* Imported; |