[clang-tools-extra] Use value_or instead of getValueOr (NFC)

This commit is contained in:
Kazu Hirata 2022-06-19 00:13:38 -07:00
parent 06decd0b41
commit 5dd171dcb5
19 changed files with 32 additions and 38 deletions

View file

@ -104,7 +104,7 @@ public:
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()) {

View file

@ -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

View file

@ -213,7 +213,7 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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

View file

@ -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;
}
}

View file

@ -84,7 +84,7 @@ public:
// - 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);

View file

@ -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));

View file

@ -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())

View file

@ -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;

View file

@ -362,7 +362,7 @@ private:
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));
});

View file

@ -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("")));
});
}

View file

@ -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 different 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!

View file

@ -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;
}

View file

@ -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());

View file

@ -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);

View file

@ -125,7 +125,7 @@ public:
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;

View file

@ -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(

View file

@ -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 differ 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.

View file

@ -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(

View file

@ -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);
}
}