[clang-tools-extra] r217489 - Unique-ptrify ClangTidyCheckFactories. Add a more convenient alternative to
Alexander Kornienko
alexfh at google.com
Wed Sep 10 04:06:43 PDT 2014
Author: alexfh
Date: Wed Sep 10 06:06:43 2014
New Revision: 217489
URL: http://llvm.org/viewvc/llvm-project?rev=217489&view=rev
Log:
Unique-ptrify ClangTidyCheckFactories. Add a more convenient alternative to
addCheckFactory: registerCheck.
Reviewers: djasper
Reviewed By: djasper
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D5288
Modified:
clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp?rev=217489&r1=217488&r2=217489&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModule.cpp Wed Sep 10 06:06:43 2014
@@ -16,14 +16,9 @@
namespace clang {
namespace tidy {
-ClangTidyCheckFactories::~ClangTidyCheckFactories() {
- for (const auto &Factory : Factories)
- delete Factory.second;
-}
-
-void ClangTidyCheckFactories::addCheckFactory(StringRef Name,
- CheckFactoryBase *Factory) {
- Factories[Name] = Factory;
+void ClangTidyCheckFactories::addCheckFactory(
+ StringRef Name, std::unique_ptr<CheckFactoryBase> Factory) {
+ Factories[Name] = std::move(Factory);
}
void ClangTidyCheckFactories::createChecks(
Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h?rev=217489&r1=217488&r2=217489&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyModule.h Wed Sep 10 06:06:43 2014
@@ -74,13 +74,17 @@ public:
/// this object.
class ClangTidyCheckFactories {
public:
- ClangTidyCheckFactories() {}
- ~ClangTidyCheckFactories();
-
/// \brief Register \p Factory with the name \p Name.
- ///
- /// The \c ClangTidyCheckFactories object takes ownership of the \p Factory.
- void addCheckFactory(StringRef Name, CheckFactoryBase *Factory);
+ void addCheckFactory(StringRef Name,
+ std::unique_ptr<CheckFactoryBase> Factory);
+
+ /// \brief Registers the \c CheckType with the name \p Name by adding a
+ /// corresponding \c ClangTidyCheckFactory.
+ template<typename CheckType>
+ void registerCheck(StringRef Name) {
+ addCheckFactory(Name,
+ llvm::make_unique<ClangTidyCheckFactory<CheckType>>());
+ }
/// \brief Create instances of all checks matching \p CheckRegexString and
/// store them in \p Checks.
@@ -89,7 +93,7 @@ public:
void createChecks(GlobList &Filter,
std::vector<std::unique_ptr<ClangTidyCheck>> &Checks);
- typedef std::map<std::string, CheckFactoryBase *> FactoryMap;
+ typedef std::map<std::string, std::unique_ptr<CheckFactoryBase>> FactoryMap;
FactoryMap::const_iterator begin() const { return Factories.begin(); }
FactoryMap::const_iterator end() const { return Factories.end(); }
bool empty() const { return Factories.empty(); }
Modified: clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp?rev=217489&r1=217488&r2=217489&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/GoogleTidyModule.cpp Wed Sep 10 06:06:43 2014
@@ -29,36 +29,26 @@ namespace tidy {
class GoogleModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
- CheckFactories.addCheckFactory(
- "google-build-explicit-make-pair",
- new ClangTidyCheckFactory<build::ExplicitMakePairCheck>());
- CheckFactories.addCheckFactory(
- "google-build-namespaces",
- new ClangTidyCheckFactory<build::UnnamedNamespaceInHeaderCheck>());
- CheckFactories.addCheckFactory(
- "google-build-using-namespace",
- new ClangTidyCheckFactory<build::UsingNamespaceDirectiveCheck>());
- CheckFactories.addCheckFactory(
- "google-explicit-constructor",
- new ClangTidyCheckFactory<ExplicitConstructorCheck>());
- CheckFactories.addCheckFactory(
- "google-runtime-int",
- new ClangTidyCheckFactory<runtime::IntegerTypesCheck>());
- CheckFactories.addCheckFactory(
- "google-runtime-operator",
- new ClangTidyCheckFactory<runtime::OverloadedUnaryAndCheck>());
- CheckFactories.addCheckFactory(
- "google-runtime-member-string-references",
- new ClangTidyCheckFactory<runtime::StringReferenceMemberCheck>());
- CheckFactories.addCheckFactory(
- "google-runtime-memset",
- new ClangTidyCheckFactory<runtime::MemsetZeroLengthCheck>());
- CheckFactories.addCheckFactory(
- "google-readability-casting",
- new ClangTidyCheckFactory<readability::AvoidCStyleCastsCheck>());
- CheckFactories.addCheckFactory(
- "google-readability-function",
- new ClangTidyCheckFactory<readability::NamedParameterCheck>());
+ CheckFactories.registerCheck<build::ExplicitMakePairCheck>(
+ "google-build-explicit-make-pair");
+ CheckFactories.registerCheck<build::UnnamedNamespaceInHeaderCheck>(
+ "google-build-namespaces");
+ CheckFactories.registerCheck<build::UsingNamespaceDirectiveCheck>(
+ "google-build-using-namespace");
+ CheckFactories.registerCheck<ExplicitConstructorCheck>(
+ "google-explicit-constructor");
+ CheckFactories.registerCheck<runtime::IntegerTypesCheck>(
+ "google-runtime-int");
+ CheckFactories.registerCheck<runtime::OverloadedUnaryAndCheck>(
+ "google-runtime-operator");
+ CheckFactories.registerCheck<runtime::StringReferenceMemberCheck>(
+ "google-runtime-member-string-references");
+ CheckFactories.registerCheck<runtime::MemsetZeroLengthCheck>(
+ "google-runtime-memset");
+ CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>(
+ "google-readability-casting");
+ CheckFactories.registerCheck<readability::NamedParameterCheck>(
+ "google-readability-function");
}
};
Modified: clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp?rev=217489&r1=217488&r2=217489&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/llvm/LLVMTidyModule.cpp Wed Sep 10 06:06:43 2014
@@ -21,16 +21,11 @@ namespace tidy {
class LLVMModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
- CheckFactories.addCheckFactory(
- "llvm-header-guard", new ClangTidyCheckFactory<LLVMHeaderGuardCheck>());
- CheckFactories.addCheckFactory(
- "llvm-include-order", new ClangTidyCheckFactory<IncludeOrderCheck>());
- CheckFactories.addCheckFactory(
- "llvm-namespace-comment",
- new ClangTidyCheckFactory<NamespaceCommentCheck>());
- CheckFactories.addCheckFactory(
- "llvm-twine-local",
- new ClangTidyCheckFactory<TwineLocalCheck>());
+ CheckFactories.registerCheck<LLVMHeaderGuardCheck>("llvm-header-guard");
+ CheckFactories.registerCheck<IncludeOrderCheck>("llvm-include-order");
+ CheckFactories.registerCheck<NamespaceCommentCheck>(
+ "llvm-namespace-comment");
+ CheckFactories.registerCheck<TwineLocalCheck>("llvm-twine-local");
}
};
Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=217489&r1=217488&r2=217489&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Wed Sep 10 06:06:43 2014
@@ -24,27 +24,17 @@ namespace tidy {
class MiscModule : public ClangTidyModule {
public:
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
- CheckFactories.addCheckFactory(
- "misc-argument-comment",
- new ClangTidyCheckFactory<ArgumentCommentCheck>());
- CheckFactories.addCheckFactory(
- "misc-bool-pointer-implicit-conversion",
- new ClangTidyCheckFactory<BoolPointerImplicitConversion>());
- CheckFactories.addCheckFactory(
- "misc-redundant-smartptr-get",
- new ClangTidyCheckFactory<RedundantSmartptrGet>());
- CheckFactories.addCheckFactory(
- "misc-swapped-arguments",
- new ClangTidyCheckFactory<SwappedArgumentsCheck>());
- CheckFactories.addCheckFactory(
- "misc-undelegated-constructor",
- new ClangTidyCheckFactory<UndelegatedConstructorCheck>());
- CheckFactories.addCheckFactory(
- "misc-unused-raii",
- new ClangTidyCheckFactory<UnusedRAIICheck>());
- CheckFactories.addCheckFactory(
- "misc-use-override",
- new ClangTidyCheckFactory<UseOverride>());
+ CheckFactories.registerCheck<ArgumentCommentCheck>("misc-argument-comment");
+ CheckFactories.registerCheck<BoolPointerImplicitConversion>(
+ "misc-bool-pointer-implicit-conversion");
+ CheckFactories.registerCheck<RedundantSmartptrGet>(
+ "misc-redundant-smartptr-get");
+ CheckFactories.registerCheck<SwappedArgumentsCheck>(
+ "misc-swapped-arguments");
+ CheckFactories.registerCheck<UndelegatedConstructorCheck>(
+ "misc-undelegated-constructor");
+ CheckFactories.registerCheck<UnusedRAIICheck>("misc-unused-raii");
+ CheckFactories.registerCheck<UseOverride>("misc-use-override");
}
};
More information about the cfe-commits
mailing list