[clang-tools-extra] 5dd171d - [clang-tools-extra] Use value_or instead of getValueOr (NFC)
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 19 00:13:49 PDT 2022
Author: Kazu Hirata
Date: 2022-06-19T00:13:38-07:00
New Revision: 5dd171dcb55bddac652c18b33a0532a9a011a801
URL: https://github.com/llvm/llvm-project/commit/5dd171dcb55bddac652c18b33a0532a9a011a801
DIFF: https://github.com/llvm/llvm-project/commit/5dd171dcb55bddac652c18b33a0532a9a011a801.diff
LOG: [clang-tools-extra] Use value_or instead of getValueOr (NFC)
Added:
Modified:
clang-tools-extra/clang-tidy/ClangTidy.cpp
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdServer.cpp
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/IncludeFixer.cpp
clang-tools-extra/clangd/JSONTransport.cpp
clang-tools-extra/clangd/Quality.cpp
clang-tools-extra/clangd/TidyProvider.cpp
clang-tools-extra/clangd/index/MemIndex.cpp
clang-tools-extra/clangd/index/Merge.cpp
clang-tools-extra/clangd/index/dex/Dex.cpp
clang-tools-extra/pseudo/lib/Forest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 57b19bd30c1c3..f7ffcdbc692b8 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -104,7 +104,7 @@ class ErrorReporter {
DiagPrinter),
SourceMgr(Diags, Files), Context(Context), ApplyFixes(ApplyFixes),
TotalFixes(0), AppliedFixes(0), WarningsAsErrors(0) {
- DiagOpts->ShowColors = Context.getOptions().UseColor.getValueOr(
+ DiagOpts->ShowColors = Context.getOptions().UseColor.value_or(
llvm::sys::Process::StandardOutHasColors());
DiagPrinter->BeginSourceFile(LangOpts);
if (DiagOpts->ShowColors && !llvm::sys::Process::StandardOutIsDisplayed()) {
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index e315318a655fd..dc38b4e190cc1 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -204,13 +204,13 @@ void ClangTidyCheck::OptionsView::diagnoseBadEnumOption(
StringRef ClangTidyCheck::OptionsView::get(StringRef LocalName,
StringRef Default) const {
- return get(LocalName).getValueOr(Default);
+ return get(LocalName).value_or(Default);
}
StringRef
ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName,
StringRef Default) const {
- return getLocalOrGlobal(LocalName).getValueOr(Default);
+ return getLocalOrGlobal(LocalName).value_or(Default);
}
} // namespace tidy
} // namespace clang
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index 77e41990b1da4..abf528d655972 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -213,7 +213,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
template <typename T>
std::enable_if_t<std::is_integral<T>::value, T> get(StringRef LocalName,
T Default) const {
- return get<T>(LocalName).getValueOr(Default);
+ return get<T>(LocalName).value_or(Default);
}
/// Read a named option from the ``Context`` and parse it as an
@@ -258,7 +258,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
template <typename T>
std::enable_if_t<std::is_integral<T>::value, T>
getLocalOrGlobal(StringRef LocalName, T Default) const {
- return getLocalOrGlobal<T>(LocalName).getValueOr(Default);
+ return getLocalOrGlobal<T>(LocalName).value_or(Default);
}
/// Read a named option from the ``Context`` and parse it as an
@@ -297,7 +297,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
template <typename T>
std::enable_if_t<std::is_enum<T>::value, T>
get(StringRef LocalName, T Default, bool IgnoreCase = false) const {
- return get<T>(LocalName, IgnoreCase).getValueOr(Default);
+ return get<T>(LocalName, IgnoreCase).value_or(Default);
}
/// Read a named option from the ``Context`` and parse it as an
@@ -339,7 +339,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
std::enable_if_t<std::is_enum<T>::value, T>
getLocalOrGlobal(StringRef LocalName, T Default,
bool IgnoreCase = false) const {
- return getLocalOrGlobal<T>(LocalName, IgnoreCase).getValueOr(Default);
+ return getLocalOrGlobal<T>(LocalName, IgnoreCase).value_or(Default);
}
/// Stores an option with the check-local name \p LocalName with
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 1e62d1c5f5eda..a12a4d6692c77 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -207,7 +207,7 @@ std::vector<OptionsSource>
ConfigOptionsProvider::getRawOptions(llvm::StringRef FileName) {
std::vector<OptionsSource> RawOptions =
DefaultOptionsProvider::getRawOptions(FileName);
- if (ConfigOptions.InheritParentConfig.getValueOr(false)) {
+ if (ConfigOptions.InheritParentConfig.value_or(false)) {
LLVM_DEBUG(llvm::dbgs()
<< "Getting options for file " << FileName << "...\n");
assert(FS && "FS must be set.");
@@ -276,7 +276,7 @@ void FileOptionsBaseProvider::addRawFileOptions(
CachedOptions[Path] = *Result;
CurOptions.push_back(*Result);
- if (!Result->first.InheritParentConfig.getValueOr(false))
+ if (!Result->first.InheritParentConfig.value_or(false))
break;
}
}
diff --git a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
index d482e49e0f6d9..eb787154e4e4a 100644
--- a/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
+++ b/clang-tools-extra/clang-tidy/NoLintDirectiveHandler.cpp
@@ -84,7 +84,7 @@ class NoLintToken {
// - Negative globs ignored (which would effectively disable the suppression).
NoLintToken(NoLintType Type, size_t Pos, const Optional<std::string> &Checks)
: Type(Type), Pos(Pos), ChecksGlob(std::make_unique<CachedGlobList>(
- Checks.getValueOr("*"),
+ Checks.value_or("*"),
/*KeepNegativeGlobs=*/false)) {
if (Checks)
this->Checks = trimWhitespace(*Checks);
diff --git a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
index 9a53f2bade77a..cced230300db0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ReservedIdentifierCheck.cpp
@@ -132,7 +132,7 @@ getFailureInfoImpl(StringRef Name, bool IsInGlobalNamespace,
auto InProgressFixup = [&] {
return Info
.map([](const FailureInfo &Info) { return StringRef(Info.Fixup); })
- .getValueOr(Name);
+ .value_or(Name);
};
if (auto Fixup = getDoubleUnderscoreFixup(InProgressFixup(), LangOpts))
AppendFailure(DoubleUnderscoreTag, std::move(*Fixup));
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 7992fa0c990af..bd283d0c175b3 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -283,7 +283,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
return false;
std::string ArraySizeExpr;
- if (const auto* ArraySize = New->getArraySize().getValueOr(nullptr)) {
+ if (const auto *ArraySize = New->getArraySize().value_or(nullptr)) {
ArraySizeExpr = Lexer::getSourceText(CharSourceRange::getTokenRange(
ArraySize->getSourceRange()),
SM, getLangOpts())
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index c102b74114d2a..242790f1e5291 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -279,7 +279,7 @@ IdentifierNamingCheck::FileStyle IdentifierNamingCheck::getFileStyleFromOptions(
!IgnoredRegexpStr.empty() || HPTOpt)
Styles[I].emplace(std::move(CaseOptional), std::move(Prefix),
std::move(Postfix), IgnoredRegexpStr.str(),
- HPTOpt.getValueOr(IdentifierNamingCheck::HPT_Off));
+ HPTOpt.value_or(IdentifierNamingCheck::HPT_Off));
}
bool IgnoreMainLike = Options.get("IgnoreMainLikeFunctions", false);
return {std::move(Styles), std::move(HNOption), IgnoreMainLike};
@@ -1045,7 +1045,7 @@ std::string IdentifierNamingCheck::fixupWithStyle(
Name.consume_back(Style.Suffix);
std::string Fixed = fixupWithCase(
Type, Name, D, Style, HNOption,
- Style.Case.getValueOr(IdentifierNamingCheck::CaseType::CT_AnyCase));
+ Style.Case.value_or(IdentifierNamingCheck::CaseType::CT_AnyCase));
std::string HungarianPrefix;
using HungarianPrefixType = IdentifierNamingCheck::HungarianPrefixType;
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 49c882e6c8d4b..e481b59a22864 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -362,7 +362,7 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
Context handlerContext() const {
return Context::current().derive(
kCurrentOffsetEncoding,
- Server.Opts.Encoding.getValueOr(OffsetEncoding::UTF16));
+ Server.Opts.Encoding.value_or(OffsetEncoding::UTF16));
}
// We run cancelable requests in a context that does two things:
@@ -786,7 +786,7 @@ void ClangdLSPServer::onWorkspaceSymbol(
const WorkspaceSymbolParams &Params,
Callback<std::vector<SymbolInformation>> Reply) {
Server->workspaceSymbols(
- Params.query, Params.limit.getValueOr(Opts.CodeComplete.Limit),
+ Params.query, Params.limit.value_or(Opts.CodeComplete.Limit),
[Reply = std::move(Reply),
this](llvm::Expected<std::vector<SymbolInformation>> Items) mutable {
if (!Items)
@@ -1110,7 +1110,7 @@ void ClangdLSPServer::onGoToDefinition(const TextDocumentPositionParams &Params,
for (auto &S : *Symbols) {
if (Location *Toggle = getToggle(Params, S))
return Reply(std::vector<Location>{std::move(*Toggle)});
- Defs.push_back(S.Definition.getValueOr(S.PreferredDeclaration));
+ Defs.push_back(S.Definition.value_or(S.PreferredDeclaration));
}
Reply(std::move(Defs));
});
diff --git a/clang-tools-extra/clangd/ClangdServer.cpp b/clang-tools-extra/clangd/ClangdServer.cpp
index 69a0f63972aae..eff596dd65d79 100644
--- a/clang-tools-extra/clangd/ClangdServer.cpp
+++ b/clang-tools-extra/clangd/ClangdServer.cpp
@@ -538,7 +538,7 @@ void ClangdServer::prepareRename(PathRef File, Position Pos,
// prepareRename is latency-sensitive: we don't query the index, as we
// only need main-file references
auto Results =
- clangd::rename({Pos, NewName.getValueOr("__clangd_rename_placeholder"),
+ clangd::rename({Pos, NewName.value_or("__clangd_rename_placeholder"),
InpAST->AST, File, /*FS=*/nullptr,
/*Index=*/nullptr, RenameOpts});
if (!Results) {
@@ -815,7 +815,7 @@ void ClangdServer::workspaceSymbols(
"getWorkspaceSymbols", /*Path=*/"",
[Query = Query.str(), Limit, CB = std::move(CB), this]() mutable {
CB(clangd::getWorkspaceSymbols(Query, Limit, Index,
- WorkspaceRoot.getValueOr("")));
+ WorkspaceRoot.value_or("")));
});
}
diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp
index 09e516919c807..276e7a3704d4c 100644
--- a/clang-tools-extra/clangd/CodeComplete.cpp
+++ b/clang-tools-extra/clangd/CodeComplete.cpp
@@ -192,7 +192,7 @@ struct CompletionCandidate {
// 0 indicates it's not part of any overload set.
size_t overloadSet(const CodeCompleteOptions &Opts, llvm::StringRef FileName,
IncludeInserter *Inserter) const {
- if (!Opts.BundleOverloads.getValueOr(false))
+ if (!Opts.BundleOverloads.value_or(false))
return 0;
// Depending on the index implementation, we can see
diff erent header
@@ -648,7 +648,7 @@ getQueryScopes(CodeCompletionContext &CCContext, const Sema &CCSema,
}
const CXXScopeSpec *SemaSpecifier =
- CCContext.getCXXScopeSpecifier().getValueOr(nullptr);
+ CCContext.getCXXScopeSpecifier().value_or(nullptr);
// Case 1: unqualified completion.
if (!SemaSpecifier) {
// Case 2 (exception): sema saw no qualifier, but there appears to be one!
diff --git a/clang-tools-extra/clangd/IncludeFixer.cpp b/clang-tools-extra/clangd/IncludeFixer.cpp
index 7fcb01e6e957a..c419d20f29d2d 100644
--- a/clang-tools-extra/clangd/IncludeFixer.cpp
+++ b/clang-tools-extra/clangd/IncludeFixer.cpp
@@ -240,7 +240,7 @@ std::vector<Fix> IncludeFixer::fix(DiagnosticsEngine::Level DiagLevel,
if (Info.getNumArgs() > 0)
if (auto Header = getArgStr(Info, 0))
return only(insertHeader(("<" + *Header + ">").str(),
- getArgStr(Info, 1).getValueOr("")));
+ getArgStr(Info, 1).value_or("")));
break;
}
diff --git a/clang-tools-extra/clangd/JSONTransport.cpp b/clang-tools-extra/clangd/JSONTransport.cpp
index e04377b1a41d3..254e54ad5c23d 100644
--- a/clang-tools-extra/clangd/JSONTransport.cpp
+++ b/clang-tools-extra/clangd/JSONTransport.cpp
@@ -53,7 +53,7 @@ llvm::json::Object encodeError(llvm::Error E) {
}
llvm::Error decodeError(const llvm::json::Object &O) {
- llvm::StringRef Msg = O.getString("message").getValueOr("Unspecified error");
+ llvm::StringRef Msg = O.getString("message").value_or("Unspecified error");
if (auto Code = O.getInteger("code"))
return llvm::make_error<LSPError>(Msg.str(), ErrorCode(*Code));
return error(Msg.str());
diff --git a/clang-tools-extra/clangd/Quality.cpp b/clang-tools-extra/clangd/Quality.cpp
index 0f7c2d3da1c6c..42eee14d28f42 100644
--- a/clang-tools-extra/clangd/Quality.cpp
+++ b/clang-tools-extra/clangd/Quality.cpp
@@ -492,7 +492,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
if (S.ContextWords)
OS << llvm::formatv(
"\tMatching context word: {0}\n",
- wordMatching(S.Name, S.ContextWords).getValueOr("<none>"));
+ wordMatching(S.Name, S.ContextWords).value_or("<none>"));
OS << llvm::formatv("\tForbidden: {0}\n", S.Forbidden);
OS << llvm::formatv("\tNeedsFixIts: {0}\n", S.NeedsFixIts);
OS << llvm::formatv("\tIsInstanceMember: {0}\n", S.IsInstanceMember);
diff --git a/clang-tools-extra/clangd/TidyProvider.cpp b/clang-tools-extra/clangd/TidyProvider.cpp
index 0f0b152be4748..32a4d6a306536 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -125,7 +125,7 @@ class DotClangTidyTree {
for (const DotClangTidyCache *Cache : Caches)
if (auto Config = Cache->get(FS, FreshTime)) {
OptionStack.push_back(std::move(Config));
- if (!OptionStack.back()->InheritParentConfig.getValueOr(false))
+ if (!OptionStack.back()->InheritParentConfig.value_or(false))
break;
}
unsigned Order = 1u;
diff --git a/clang-tools-extra/clangd/index/MemIndex.cpp b/clang-tools-extra/clangd/index/MemIndex.cpp
index 2ca60c99d2a2c..fe0ee873018b3 100644
--- a/clang-tools-extra/clangd/index/MemIndex.cpp
+++ b/clang-tools-extra/clangd/index/MemIndex.cpp
@@ -68,8 +68,7 @@ void MemIndex::lookup(const LookupRequest &Req,
bool MemIndex::refs(const RefsRequest &Req,
llvm::function_ref<void(const Ref &)> Callback) const {
trace::Span Tracer("MemIndex refs");
- uint32_t Remaining =
- Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
+ uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
for (const auto &ReqID : Req.IDs) {
auto SymRefs = Refs.find(ReqID);
if (SymRefs == Refs.end())
@@ -89,8 +88,7 @@ bool MemIndex::refs(const RefsRequest &Req,
void MemIndex::relations(
const RelationsRequest &Req,
llvm::function_ref<void(const SymbolID &, const Symbol &)> Callback) const {
- uint32_t Remaining =
- Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
+ uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
for (const SymbolID &Subject : Req.Subjects) {
LookupRequest LookupReq;
auto It = Relations.find(
diff --git a/clang-tools-extra/clangd/index/Merge.cpp b/clang-tools-extra/clangd/index/Merge.cpp
index ddb7865d679cb..997bbfb6672a1 100644
--- a/clang-tools-extra/clangd/index/Merge.cpp
+++ b/clang-tools-extra/clangd/index/Merge.cpp
@@ -126,8 +126,7 @@ bool MergedIndex::refs(const RefsRequest &Req,
llvm::function_ref<void(const Ref &)> Callback) const {
trace::Span Tracer("MergedIndex refs");
bool More = false;
- uint32_t Remaining =
- Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
+ uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
// We don't want duplicated refs from the static/dynamic indexes,
// and we can't reliably deduplicate them because offsets may
diff er slightly.
// We consider the dynamic index authoritative and report all its refs,
@@ -167,8 +166,7 @@ MergedIndex::indexedFiles() const {
void MergedIndex::relations(
const RelationsRequest &Req,
llvm::function_ref<void(const SymbolID &, const Symbol &)> Callback) const {
- uint32_t Remaining =
- Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
+ uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
// Return results from both indexes but avoid duplicates.
// We might return stale relations from the static index;
// we don't currently have a good way of identifying them.
diff --git a/clang-tools-extra/clangd/index/dex/Dex.cpp b/clang-tools-extra/clangd/index/dex/Dex.cpp
index 18779077b2c43..2d778c13157f2 100644
--- a/clang-tools-extra/clangd/index/dex/Dex.cpp
+++ b/clang-tools-extra/clangd/index/dex/Dex.cpp
@@ -300,8 +300,7 @@ void Dex::lookup(const LookupRequest &Req,
bool Dex::refs(const RefsRequest &Req,
llvm::function_ref<void(const Ref &)> Callback) const {
trace::Span Tracer("Dex refs");
- uint32_t Remaining =
- Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
+ uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
for (const auto &ID : Req.IDs)
for (const auto &Ref : Refs.lookup(ID)) {
if (!static_cast<int>(Req.Filter & Ref.Kind))
@@ -318,8 +317,7 @@ void Dex::relations(
const RelationsRequest &Req,
llvm::function_ref<void(const SymbolID &, const Symbol &)> Callback) const {
trace::Span Tracer("Dex relations");
- uint32_t Remaining =
- Req.Limit.getValueOr(std::numeric_limits<uint32_t>::max());
+ uint32_t Remaining = Req.Limit.value_or(std::numeric_limits<uint32_t>::max());
for (const SymbolID &Subject : Req.Subjects) {
LookupRequest LookupReq;
auto It = Relations.find(
diff --git a/clang-tools-extra/pseudo/lib/Forest.cpp b/clang-tools-extra/pseudo/lib/Forest.cpp
index 073a651947ac4..dce3c3a7b70a9 100644
--- a/clang-tools-extra/pseudo/lib/Forest.cpp
+++ b/clang-tools-extra/pseudo/lib/Forest.cpp
@@ -78,7 +78,7 @@ std::string ForestNode::dumpRecursive(const Grammar &G,
assert(Children[0]->startTokenIndex() == P->startTokenIndex() &&
EndOfElement(0) == End);
return Dump(Children[0], End,
- /*ElidedParent=*/ElidedParent.getValueOr(P->symbol()),
+ /*ElidedParent=*/ElidedParent.value_or(P->symbol()),
LineDec);
}
}
More information about the cfe-commits
mailing list