Skip to content

Commit be8c143

Browse files
committedSep 10, 2014
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 llvm-svn: 217489
1 parent b6bbf34 commit be8c143

File tree

5 files changed

+50
-76
lines changed

5 files changed

+50
-76
lines changed
 

‎clang-tools-extra/clang-tidy/ClangTidyModule.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616
namespace clang {
1717
namespace tidy {
1818

19-
ClangTidyCheckFactories::~ClangTidyCheckFactories() {
20-
for (const auto &Factory : Factories)
21-
delete Factory.second;
22-
}
23-
24-
void ClangTidyCheckFactories::addCheckFactory(StringRef Name,
25-
CheckFactoryBase *Factory) {
26-
Factories[Name] = Factory;
19+
void ClangTidyCheckFactories::addCheckFactory(
20+
StringRef Name, std::unique_ptr<CheckFactoryBase> Factory) {
21+
Factories[Name] = std::move(Factory);
2722
}
2823

2924
void ClangTidyCheckFactories::createChecks(

‎clang-tools-extra/clang-tidy/ClangTidyModule.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,17 @@ class ClangTidyModule {
7474
/// this object.
7575
class ClangTidyCheckFactories {
7676
public:
77-
ClangTidyCheckFactories() {}
78-
~ClangTidyCheckFactories();
79-
8077
/// \brief Register \p Factory with the name \p Name.
81-
///
82-
/// The \c ClangTidyCheckFactories object takes ownership of the \p Factory.
83-
void addCheckFactory(StringRef Name, CheckFactoryBase *Factory);
78+
void addCheckFactory(StringRef Name,
79+
std::unique_ptr<CheckFactoryBase> Factory);
80+
81+
/// \brief Registers the \c CheckType with the name \p Name by adding a
82+
/// corresponding \c ClangTidyCheckFactory.
83+
template<typename CheckType>
84+
void registerCheck(StringRef Name) {
85+
addCheckFactory(Name,
86+
llvm::make_unique<ClangTidyCheckFactory<CheckType>>());
87+
}
8488

8589
/// \brief Create instances of all checks matching \p CheckRegexString and
8690
/// store them in \p Checks.
@@ -89,7 +93,7 @@ class ClangTidyCheckFactories {
8993
void createChecks(GlobList &Filter,
9094
std::vector<std::unique_ptr<ClangTidyCheck>> &Checks);
9195

92-
typedef std::map<std::string, CheckFactoryBase *> FactoryMap;
96+
typedef std::map<std::string, std::unique_ptr<CheckFactoryBase>> FactoryMap;
9397
FactoryMap::const_iterator begin() const { return Factories.begin(); }
9498
FactoryMap::const_iterator end() const { return Factories.end(); }
9599
bool empty() const { return Factories.empty(); }

‎clang-tools-extra/clang-tidy/google/GoogleTidyModule.cpp

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,26 @@ namespace tidy {
2929
class GoogleModule : public ClangTidyModule {
3030
public:
3131
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
32-
CheckFactories.addCheckFactory(
33-
"google-build-explicit-make-pair",
34-
new ClangTidyCheckFactory<build::ExplicitMakePairCheck>());
35-
CheckFactories.addCheckFactory(
36-
"google-build-namespaces",
37-
new ClangTidyCheckFactory<build::UnnamedNamespaceInHeaderCheck>());
38-
CheckFactories.addCheckFactory(
39-
"google-build-using-namespace",
40-
new ClangTidyCheckFactory<build::UsingNamespaceDirectiveCheck>());
41-
CheckFactories.addCheckFactory(
42-
"google-explicit-constructor",
43-
new ClangTidyCheckFactory<ExplicitConstructorCheck>());
44-
CheckFactories.addCheckFactory(
45-
"google-runtime-int",
46-
new ClangTidyCheckFactory<runtime::IntegerTypesCheck>());
47-
CheckFactories.addCheckFactory(
48-
"google-runtime-operator",
49-
new ClangTidyCheckFactory<runtime::OverloadedUnaryAndCheck>());
50-
CheckFactories.addCheckFactory(
51-
"google-runtime-member-string-references",
52-
new ClangTidyCheckFactory<runtime::StringReferenceMemberCheck>());
53-
CheckFactories.addCheckFactory(
54-
"google-runtime-memset",
55-
new ClangTidyCheckFactory<runtime::MemsetZeroLengthCheck>());
56-
CheckFactories.addCheckFactory(
57-
"google-readability-casting",
58-
new ClangTidyCheckFactory<readability::AvoidCStyleCastsCheck>());
59-
CheckFactories.addCheckFactory(
60-
"google-readability-function",
61-
new ClangTidyCheckFactory<readability::NamedParameterCheck>());
32+
CheckFactories.registerCheck<build::ExplicitMakePairCheck>(
33+
"google-build-explicit-make-pair");
34+
CheckFactories.registerCheck<build::UnnamedNamespaceInHeaderCheck>(
35+
"google-build-namespaces");
36+
CheckFactories.registerCheck<build::UsingNamespaceDirectiveCheck>(
37+
"google-build-using-namespace");
38+
CheckFactories.registerCheck<ExplicitConstructorCheck>(
39+
"google-explicit-constructor");
40+
CheckFactories.registerCheck<runtime::IntegerTypesCheck>(
41+
"google-runtime-int");
42+
CheckFactories.registerCheck<runtime::OverloadedUnaryAndCheck>(
43+
"google-runtime-operator");
44+
CheckFactories.registerCheck<runtime::StringReferenceMemberCheck>(
45+
"google-runtime-member-string-references");
46+
CheckFactories.registerCheck<runtime::MemsetZeroLengthCheck>(
47+
"google-runtime-memset");
48+
CheckFactories.registerCheck<readability::AvoidCStyleCastsCheck>(
49+
"google-readability-casting");
50+
CheckFactories.registerCheck<readability::NamedParameterCheck>(
51+
"google-readability-function");
6252
}
6353
};
6454

‎clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,11 @@ namespace tidy {
2121
class LLVMModule : public ClangTidyModule {
2222
public:
2323
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
24-
CheckFactories.addCheckFactory(
25-
"llvm-header-guard", new ClangTidyCheckFactory<LLVMHeaderGuardCheck>());
26-
CheckFactories.addCheckFactory(
27-
"llvm-include-order", new ClangTidyCheckFactory<IncludeOrderCheck>());
28-
CheckFactories.addCheckFactory(
29-
"llvm-namespace-comment",
30-
new ClangTidyCheckFactory<NamespaceCommentCheck>());
31-
CheckFactories.addCheckFactory(
32-
"llvm-twine-local",
33-
new ClangTidyCheckFactory<TwineLocalCheck>());
24+
CheckFactories.registerCheck<LLVMHeaderGuardCheck>("llvm-header-guard");
25+
CheckFactories.registerCheck<IncludeOrderCheck>("llvm-include-order");
26+
CheckFactories.registerCheck<NamespaceCommentCheck>(
27+
"llvm-namespace-comment");
28+
CheckFactories.registerCheck<TwineLocalCheck>("llvm-twine-local");
3429
}
3530
};
3631

‎clang-tools-extra/clang-tidy/misc/MiscTidyModule.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,17 @@ namespace tidy {
2424
class MiscModule : public ClangTidyModule {
2525
public:
2626
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
27-
CheckFactories.addCheckFactory(
28-
"misc-argument-comment",
29-
new ClangTidyCheckFactory<ArgumentCommentCheck>());
30-
CheckFactories.addCheckFactory(
31-
"misc-bool-pointer-implicit-conversion",
32-
new ClangTidyCheckFactory<BoolPointerImplicitConversion>());
33-
CheckFactories.addCheckFactory(
34-
"misc-redundant-smartptr-get",
35-
new ClangTidyCheckFactory<RedundantSmartptrGet>());
36-
CheckFactories.addCheckFactory(
37-
"misc-swapped-arguments",
38-
new ClangTidyCheckFactory<SwappedArgumentsCheck>());
39-
CheckFactories.addCheckFactory(
40-
"misc-undelegated-constructor",
41-
new ClangTidyCheckFactory<UndelegatedConstructorCheck>());
42-
CheckFactories.addCheckFactory(
43-
"misc-unused-raii",
44-
new ClangTidyCheckFactory<UnusedRAIICheck>());
45-
CheckFactories.addCheckFactory(
46-
"misc-use-override",
47-
new ClangTidyCheckFactory<UseOverride>());
27+
CheckFactories.registerCheck<ArgumentCommentCheck>("misc-argument-comment");
28+
CheckFactories.registerCheck<BoolPointerImplicitConversion>(
29+
"misc-bool-pointer-implicit-conversion");
30+
CheckFactories.registerCheck<RedundantSmartptrGet>(
31+
"misc-redundant-smartptr-get");
32+
CheckFactories.registerCheck<SwappedArgumentsCheck>(
33+
"misc-swapped-arguments");
34+
CheckFactories.registerCheck<UndelegatedConstructorCheck>(
35+
"misc-undelegated-constructor");
36+
CheckFactories.registerCheck<UnusedRAIICheck>("misc-unused-raii");
37+
CheckFactories.registerCheck<UseOverride>("misc-use-override");
4838
}
4939
};
5040

0 commit comments

Comments
 (0)
Please sign in to comment.