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/lib/Frontend | |
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/lib/Frontend')
-rw-r--r-- | clang/lib/Frontend/CompilerInstance.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Frontend/DependencyFile.cpp | 10 | ||||
-rw-r--r-- | clang/lib/Frontend/DependencyGraph.cpp | 23 | ||||
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Frontend/ModuleDependencyCollector.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Frontend/PrecompiledPreamble.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Frontend/PrintPreprocessedOutput.cpp | 21 | ||||
-rw-r--r-- | clang/lib/Frontend/Rewrite/InclusionRewriter.cpp | 21 | ||||
-rw-r--r-- | clang/lib/Frontend/VerifyDiagnosticConsumer.cpp | 3 |
9 files changed, 51 insertions, 52 deletions
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) { |