diff options
| -rw-r--r-- | clang-tools-extra/clang-tidy/ClangTidyModule.cpp | 11 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/ClangTidyModule.h | 18 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp | 50 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp | 15 | ||||
| -rw-r--r-- | clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp | 32 |
5 files changed, 50 insertions, 76 deletions
diff --git a/clang-tools-extra/clang-tidy/ClangTidyModule.cpp b/clang-tools-extra/clang-tidy/ClangTidyModule.cpp index 759fb26af2f..77f85098ed7 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyModule.cpp @@ -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( diff --git a/clang-tools-extra/clang-tidy/ClangTidyModule.h b/clang-tools-extra/clang-tidy/ClangTidyModule.h index c9c51438a00..9580ce9a99b 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyModule.h +++ b/clang-tools-extra/clang-tidy/ClangTidyModule.h @@ -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(); } diff --git a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp index c945e74ae3d..34c17bbf5cf 100644 --- a/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp @@ -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"); } }; diff --git a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp index a8ef6299028..1eb82c58f59 100644 --- a/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp @@ -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"); } }; diff --git a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp index 8cf70d30492..489f5b31dd7 100644 --- a/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp @@ -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"); } }; |

