[clang-tools-extra] a25487f - [clang-tidy] Use Options priority in enum options where it was missing
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 10 04:27:21 PDT 2020
Author: Nathan James
Date: 2020-07-10T12:27:08+01:00
New Revision: a25487fd8cb91f99cfc1db1d4159184ac2a816a9
URL: https://github.com/llvm/llvm-project/commit/a25487fd8cb91f99cfc1db1d4159184ac2a816a9
DIFF: https://github.com/llvm/llvm-project/commit/a25487fd8cb91f99cfc1db1d4159184ac2a816a9.diff
LOG: [clang-tidy] Use Options priority in enum options where it was missing
Added:
Modified:
clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
index 7ddf054a21a9..780a3569afdb 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp
@@ -76,16 +76,25 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
}
+static ClangTidyOptions::OptionMap::const_iterator
+findPriorityOption(const ClangTidyOptions::OptionMap &Options, StringRef NamePrefix,
+ StringRef LocalName) {
+ auto IterLocal = Options.find((NamePrefix + LocalName).str());
+ auto IterGlobal = Options.find(LocalName.str());
+ if (IterLocal == Options.end())
+ return IterGlobal;
+ if (IterGlobal == Options.end())
+ return IterLocal;
+ if (IterLocal->second.Priority >= IterGlobal->second.Priority)
+ return IterLocal;
+ return IterGlobal;
+}
+
llvm::Expected<std::string>
ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const {
- auto IterLocal = CheckOptions.find(NamePrefix + LocalName.str());
- auto IterGlobal = CheckOptions.find(LocalName.str());
- if (IterLocal != CheckOptions.end() &&
- (IterGlobal == CheckOptions.end() ||
- IterLocal->second.Priority >= IterGlobal->second.Priority))
- return IterLocal->second.Value;
- if (IterGlobal != CheckOptions.end())
- return IterGlobal->second.Value;
+ auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName);
+ if (Iter != CheckOptions.end())
+ return Iter->second.Value;
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
}
@@ -124,14 +133,9 @@ bool ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName,
template <>
llvm::Expected<bool>
ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName) const {
- auto IterLocal = CheckOptions.find(NamePrefix + LocalName.str());
- auto IterGlobal = CheckOptions.find(LocalName.str());
- if (IterLocal != CheckOptions.end() &&
- (IterGlobal == CheckOptions.end() ||
- IterLocal->second.Priority >= IterGlobal->second.Priority))
- return getAsBool(IterLocal->second.Value, NamePrefix + LocalName);
- if (IterGlobal != CheckOptions.end())
- return getAsBool(IterGlobal->second.Value, llvm::Twine(LocalName));
+ auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName);
+ if (Iter != CheckOptions.end())
+ return getAsBool(Iter->second.Value, Iter->first);
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
}
@@ -160,9 +164,8 @@ void ClangTidyCheck::OptionsView::store(ClangTidyOptions::OptionMap &Options,
llvm::Expected<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
StringRef LocalName, ArrayRef<std::pair<StringRef, int64_t>> Mapping,
bool CheckGlobal, bool IgnoreCase) {
- auto Iter = CheckOptions.find((NamePrefix + LocalName).str());
- if (CheckGlobal && Iter == CheckOptions.end())
- Iter = CheckOptions.find(LocalName.str());
+ auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix, LocalName)
+ : CheckOptions.find((NamePrefix + LocalName).str());
if (Iter == CheckOptions.end())
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
More information about the cfe-commits
mailing list