[clang-tidy] Implement storeOptions for checks missing it.

Just adds the storeOptions for Checks that weren't already storing their options.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82223
This commit is contained in:
Nathan James
2020-06-21 19:01:11 +01:00
parent 448bbc512f
commit db90d31570
27 changed files with 82 additions and 26 deletions
@@ -30,8 +30,7 @@ static constexpr llvm::StringLiteral LoopIncrementName =
TooSmallLoopVariableCheck::TooSmallLoopVariableCheck(StringRef Name,
ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
MagnitudeBitsUpperLimit(Options.get<unsigned>(
"MagnitudeBitsUpperLimit", 16)) {}
MagnitudeBitsUpperLimit(Options.get("MagnitudeBitsUpperLimit", 16U)) {}
void TooSmallLoopVariableCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
@@ -29,6 +29,12 @@ InitVariablesCheck::InitVariablesCheck(StringRef Name,
utils::IncludeSorter::IS_LLVM)),
MathHeader(Options.get("MathHeader", "math.h")) {}
void InitVariablesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IncludeStyle", IncludeStyle,
utils::IncludeSorter::getMapping());
Options.store(Opts, "MathHeader", MathHeader);
}
void InitVariablesCheck::registerMatchers(MatchFinder *Finder) {
std::string BadDecl = "badDecl";
Finder->addMatcher(
@@ -102,7 +108,6 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
}
}
}
} // namespace cppcoreguidelines
} // namespace tidy
} // namespace clang
@@ -24,6 +24,7 @@ namespace cppcoreguidelines {
class InitVariablesCheck : public ClangTidyCheck {
public:
InitVariablesCheck(StringRef Name, ClangTidyContext *Context);
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
@@ -29,6 +29,13 @@ NarrowingConversionsCheck::NarrowingConversionsCheck(StringRef Name,
Options.get("WarnOnFloatingPointNarrowingConversion", true)),
PedanticMode(Options.get("PedanticMode", false)) {}
void NarrowingConversionsCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "WarnOnFloatingPointNarrowingConversion",
WarnOnFloatingPointNarrowingConversion);
Options.store(Opts, "PedanticMode", PedanticMode);
}
void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
// ceil() and floor() are guaranteed to return integers, even though the type
// is not integral.
@@ -442,7 +449,6 @@ void NarrowingConversionsCheck::check(const MatchFinder::MatchResult &Result) {
return handleImplicitCast(*Result.Context, *Cast);
llvm_unreachable("must be binary operator or cast expression");
}
} // namespace cppcoreguidelines
} // namespace tidy
} // namespace clang
@@ -25,6 +25,8 @@ class NarrowingConversionsCheck : public ClangTidyCheck {
public:
NarrowingConversionsCheck(StringRef Name, ClangTidyContext *Context);
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -48,6 +48,14 @@ NonPrivateMemberVariablesInClassesCheck::
IgnorePublicMemberVariables(
Options.get("IgnorePublicMemberVariables", false)) {}
void NonPrivateMemberVariablesInClassesCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoreClassesWithAllMemberVariablesBeingPublic",
IgnoreClassesWithAllMemberVariablesBeingPublic);
Options.store(Opts, "IgnorePublicMemberVariables",
IgnorePublicMemberVariables);
}
void NonPrivateMemberVariablesInClassesCheck::registerMatchers(
MatchFinder *Finder) {
// We can ignore structs/classes with all member variables being public.
@@ -33,6 +33,7 @@ public:
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -23,7 +23,9 @@ ThrowByValueCatchByReferenceCheck::ThrowByValueCatchByReferenceCheck(
CheckAnonymousTemporaries(Options.get("CheckThrowTemporaries", true)),
WarnOnLargeObject(Options.get("WarnOnLargeObject", false)),
// Cannot access `ASTContext` from here so set it to an extremal value.
MaxSize(Options.get("MaxSize", std::numeric_limits<uint64_t>::max())) {}
MaxSizeOptions(
Options.get("MaxSize", std::numeric_limits<uint64_t>::max())),
MaxSize(MaxSizeOptions) {}
void ThrowByValueCatchByReferenceCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(cxxThrowExpr().bind("throw"), this);
@@ -33,6 +35,8 @@ void ThrowByValueCatchByReferenceCheck::registerMatchers(MatchFinder *Finder) {
void ThrowByValueCatchByReferenceCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "CheckThrowTemporaries", true);
Options.store(Opts, "WarnOnLargeObjects", WarnOnLargeObject);
Options.store(Opts, "MaxSize", MaxSizeOptions);
}
void ThrowByValueCatchByReferenceCheck::check(
@@ -45,6 +45,7 @@ private:
bool isFunctionOrCatchVar(const DeclRefExpr *declRefExpr);
const bool CheckAnonymousTemporaries;
const bool WarnOnLargeObject;
const uint64_t MaxSizeOptions; // The raw value read from the options.
uint64_t MaxSize; // No `const` because we have to set it in two steps.
};
@@ -578,6 +578,10 @@ AvoidBindCheck::AvoidBindCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
PermissiveParameterList(Options.get("PermissiveParameterList", false)) {}
void AvoidBindCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "PermissiveParameterList", PermissiveParameterList);
}
void AvoidBindCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
callExpr(
@@ -27,6 +27,7 @@ public:
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus14;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -476,7 +476,7 @@ LoopConvertCheck::RangeDescriptor::RangeDescriptor()
LoopConvertCheck::LoopConvertCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context), TUInfo(new TUTrackingInfo),
MaxCopySize(std::stoull(Options.get("MaxCopySize", "16"))),
MaxCopySize(Options.get("MaxCopySize", 16ULL)),
MinConfidence(Options.get("MinConfidence", getConfidenceMapping(),
Confidence::CL_Reasonable)),
NamingStyle(Options.get("NamingStyle", getStyleMapping(),
@@ -111,10 +111,9 @@ RawStringLiteralCheck::RawStringLiteralCheck(StringRef Name,
DisallowedChars.set(static_cast<unsigned char>(C));
}
void RawStringLiteralCheck::storeOptions(ClangTidyOptions::OptionMap &Options) {
ClangTidyCheck::storeOptions(Options);
this->Options.store(Options, "ReplaceShorterLiterals",
ReplaceShorterLiterals);
void RawStringLiteralCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "DelimiterStem", DelimiterStem);
Options.store(Opts, "ReplaceShorterLiterals", ReplaceShorterLiterals);
}
void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
@@ -321,7 +321,7 @@ UseAutoCheck::UseAutoCheck(StringRef Name, ClangTidyContext *Context)
void UseAutoCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "MinTypeNameLength", MinTypeNameLength);
Options.store(Opts, "RemoveStars", RemoveStars ? 1 : 0);
Options.store(Opts, "RemoveStars", RemoveStars);
}
void UseAutoCheck::registerMatchers(MatchFinder *Finder) {
@@ -22,6 +22,10 @@ UseBoolLiteralsCheck::UseBoolLiteralsCheck(StringRef Name,
: ClangTidyCheck(Name, Context),
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
void UseBoolLiteralsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
}
void UseBoolLiteralsCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
traverse(
@@ -25,6 +25,7 @@ public:
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -160,6 +160,7 @@ void UseEmplaceCheck::check(const MatchFinder::MatchResult &Result) {
}
void UseEmplaceCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoreImplicitConstructors", IgnoreImplicitConstructors);
Options.store(Opts, "ContainersWithPushBack",
utils::options::serializeStringList(ContainersWithPushBack));
Options.store(Opts, "SmartPointers",
@@ -22,7 +22,7 @@ UseTransparentFunctorsCheck::UseTransparentFunctorsCheck(
void UseTransparentFunctorsCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "SafeMode", SafeMode ? 1 : 0);
Options.store(Opts, "SafeMode", SafeMode);
}
void UseTransparentFunctorsCheck::registerMatchers(MatchFinder *Finder) {
@@ -20,6 +20,10 @@ UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
}
void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(typedefDecl(unless(isInstantiated())).bind("typedef"),
this);
@@ -111,7 +115,6 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
std::string Replacement = Using + Name + " = " + Type;
Diag << FixItHint::CreateReplacement(ReplaceRange, Replacement);
}
} // namespace modernize
} // namespace tidy
} // namespace clang
@@ -32,9 +32,7 @@ public:
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
return LangOpts.CPlusPlus11;
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override {
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
};
@@ -67,11 +67,14 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, ClangTidyContext *Context)
Options.get("IgnoreAllFloatingPointValues", false)),
IgnoreBitFieldsWidths(Options.get("IgnoreBitFieldsWidths", true)),
IgnorePowersOf2IntegerValues(
Options.get("IgnorePowersOf2IntegerValues", false)) {
Options.get("IgnorePowersOf2IntegerValues", false)),
RawIgnoredIntegerValues(
Options.get("IgnoredIntegerValues", DefaultIgnoredIntegerValues)),
RawIgnoredFloatingPointValues(Options.get(
"IgnoredFloatingPointValues", DefaultIgnoredFloatingPointValues)) {
// Process the set of ignored integer values.
const std::vector<std::string> IgnoredIntegerValuesInput =
utils::options::parseStringList(
Options.get("IgnoredIntegerValues", DefaultIgnoredIntegerValues));
utils::options::parseStringList(RawIgnoredIntegerValues);
IgnoredIntegerValues.resize(IgnoredIntegerValuesInput.size());
llvm::transform(IgnoredIntegerValuesInput, IgnoredIntegerValues.begin(),
[](const std::string &Value) { return std::stoll(Value); });
@@ -80,8 +83,7 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, ClangTidyContext *Context)
if (!IgnoreAllFloatingPointValues) {
// Process the set of ignored floating point values.
const std::vector<std::string> IgnoredFloatingPointValuesInput =
utils::options::parseStringList(Options.get(
"IgnoredFloatingPointValues", DefaultIgnoredFloatingPointValues));
utils::options::parseStringList(RawIgnoredFloatingPointValues);
IgnoredFloatingPointValues.reserve(IgnoredFloatingPointValuesInput.size());
IgnoredDoublePointValues.reserve(IgnoredFloatingPointValuesInput.size());
for (const auto &InputValue : IgnoredFloatingPointValuesInput) {
@@ -107,9 +109,14 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, ClangTidyContext *Context)
}
void MagicNumbersCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoredIntegerValues", DefaultIgnoredIntegerValues);
Options.store(Opts, "IgnoreAllFloatingPointValues",
IgnoreAllFloatingPointValues);
Options.store(Opts, "IgnoreBitFieldsWidths", IgnoreBitFieldsWidths);
Options.store(Opts, "IgnorePowersOf2IntegerValues",
IgnorePowersOf2IntegerValues);
Options.store(Opts, "IgnoredIntegerValues", RawIgnoredIntegerValues);
Options.store(Opts, "IgnoredFloatingPointValues",
DefaultIgnoredFloatingPointValues);
RawIgnoredFloatingPointValues);
}
void MagicNumbersCheck::registerMatchers(MatchFinder *Finder) {
@@ -86,6 +86,8 @@ private:
const bool IgnoreAllFloatingPointValues;
const bool IgnoreBitFieldsWidths;
const bool IgnorePowersOf2IntegerValues;
const std::string RawIgnoredIntegerValues;
const std::string RawIgnoredFloatingPointValues;
constexpr static unsigned SensibleNumberOfMagicValueExceptions = 16;
@@ -26,6 +26,11 @@ RedundantDeclarationCheck::RedundantDeclarationCheck(StringRef Name,
: ClangTidyCheck(Name, Context),
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
void RedundantDeclarationCheck::storeOptions(
ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "IgnoreMacros", IgnoreMacros);
}
void RedundantDeclarationCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(
namedDecl(anyOf(varDecl(unless(isDefinition())),
@@ -81,7 +86,6 @@ void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
}
diag(Prev->getLocation(), "previously declared here", DiagnosticIDs::Note);
}
} // namespace readability
} // namespace tidy
} // namespace clang
@@ -22,6 +22,7 @@ namespace readability {
class RedundantDeclarationCheck : public ClangTidyCheck {
public:
RedundantDeclarationCheck(StringRef Name, ClangTidyContext *Context);
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
@@ -25,7 +25,7 @@ public:
StaticAccessedThroughInstanceCheck(StringRef Name, ClangTidyContext *Context)
: ClangTidyCheck(Name, Context),
NameSpecifierNestingThreshold(
Options.get("NameSpecifierNestingThreshold", 3)) {}
Options.get("NameSpecifierNestingThreshold", 3U)) {}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
@@ -266,6 +266,10 @@ private:
};
} // namespace
void HeaderGuardCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
}
void HeaderGuardCheck::registerPPCallbacks(const SourceManager &SM,
Preprocessor *PP,
Preprocessor *ModuleExpanderPP) {
@@ -285,7 +289,6 @@ bool HeaderGuardCheck::shouldSuggestToAddHeaderGuard(StringRef FileName) {
std::string HeaderGuardCheck::formatEndIf(StringRef HeaderGuard) {
return "endif // " + HeaderGuard.str();
}
} // namespace utils
} // namespace tidy
} // namespace clang
@@ -34,6 +34,7 @@ public:
HeaderFileExtensions,
utils::defaultFileExtensionDelimiters());
}
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
Preprocessor *ModuleExpanderPP) override;