clang-tools 6.0.0

ModernizeTidyModule.cpp
Go to the documentation of this file.
1 //===--- ModernizeTidyModule.cpp - clang-tidy -----------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "../ClangTidy.h"
11 #include "../ClangTidyModule.h"
12 #include "../ClangTidyModuleRegistry.h"
13 #include "AvoidBindCheck.h"
14 #include "DeprecatedHeadersCheck.h"
15 #include "LoopConvertCheck.h"
16 #include "MakeSharedCheck.h"
17 #include "MakeUniqueCheck.h"
18 #include "PassByValueCheck.h"
19 #include "RawStringLiteralCheck.h"
20 #include "RedundantVoidArgCheck.h"
21 #include "ReplaceAutoPtrCheck.h"
22 #include "ReplaceRandomShuffleCheck.h"
23 #include "ReturnBracedInitListCheck.h"
24 #include "ShrinkToFitCheck.h"
25 #include "UnaryStaticAssertCheck.h"
26 #include "UseAutoCheck.h"
27 #include "UseBoolLiteralsCheck.h"
28 #include "UseDefaultMemberInitCheck.h"
29 #include "UseEmplaceCheck.h"
30 #include "UseEqualsDefaultCheck.h"
31 #include "UseEqualsDeleteCheck.h"
32 #include "UseNoexceptCheck.h"
33 #include "UseNullptrCheck.h"
34 #include "UseOverrideCheck.h"
35 #include "UseTransparentFunctorsCheck.h"
36 #include "UseUsingCheck.h"
37
38 using namespace clang::ast_matchers;
39
40 namespace clang {
41 namespace tidy {
42 namespace modernize {
43
44 class ModernizeModule : public ClangTidyModule {
45 public:
46 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
47 CheckFactories.registerCheck<AvoidBindCheck>("modernize-avoid-bind");
48 CheckFactories.registerCheck<DeprecatedHeadersCheck>(
49 "modernize-deprecated-headers");
50 CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
51 CheckFactories.registerCheck<MakeSharedCheck>("modernize-make-shared");
52 CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
53 CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
54 CheckFactories.registerCheck<RawStringLiteralCheck>(
55 "modernize-raw-string-literal");
56 CheckFactories.registerCheck<RedundantVoidArgCheck>(
57 "modernize-redundant-void-arg");
58 CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
59 "modernize-replace-auto-ptr");
60 CheckFactories.registerCheck<ReplaceRandomShuffleCheck>(
61 "modernize-replace-random-shuffle");
62 CheckFactories.registerCheck<ReturnBracedInitListCheck>(
63 "modernize-return-braced-init-list");
64 CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
65 CheckFactories.registerCheck<UnaryStaticAssertCheck>(
66 "modernize-unary-static-assert");
67 CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
68 CheckFactories.registerCheck<UseBoolLiteralsCheck>(
69 "modernize-use-bool-literals");
70 CheckFactories.registerCheck<UseDefaultMemberInitCheck>(
71 "modernize-use-default-member-init");
72 CheckFactories.registerCheck<UseEmplaceCheck>("modernize-use-emplace");
73 CheckFactories.registerCheck<UseEqualsDefaultCheck>("modernize-use-equals-default");
74 CheckFactories.registerCheck<UseEqualsDeleteCheck>(
75 "modernize-use-equals-delete");
76 CheckFactories.registerCheck<UseNoexceptCheck>("modernize-use-noexcept");
77 CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
78 CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
79 CheckFactories.registerCheck<UseTransparentFunctorsCheck>(
80 "modernize-use-transparent-functors");
81 CheckFactories.registerCheck<UseUsingCheck>("modernize-use-using");
82 }
83
84 ClangTidyOptions getModuleOptions() override {
85 ClangTidyOptions Options;
86 auto &Opts = Options.CheckOptions;
87 // For types whose size in bytes is above this threshold, we prefer taking a
88 // const-reference than making a copy.
89 Opts["modernize-loop-convert.MaxCopySize"] = "16";
90
91 Opts["modernize-loop-convert.MinConfidence"] = "reasonable";
92 Opts["modernize-loop-convert.NamingStyle"] = "CamelCase";
93 Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google".
94 Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google".
95
96 // Comma-separated list of macros that behave like NULL.
97 Opts["modernize-use-nullptr.NullMacros"] = "NULL";
98 return Options;
99 }
100 };
101
102 // Register the ModernizeTidyModule using this statically initialized variable.
103 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
104 "Add modernize checks.");
105
106 } // namespace modernize
107
108 // This anchor is used to force the linker to link in the generated object file
109 // and thus register the ModernizeModule.
110 volatile int ModernizeModuleAnchorSource = 0;
111
112 } // namespace tidy
113 } // namespace clang
clang::ast_matchers
Definition: ClangTidyDiagnosticConsumer.h:27
UseAutoCheck.h
clang::tidy::modernize::RawStringLiteralCheck
This check replaces string literals with escaped characters to raw string literals.
Definition: RawStringLiteralCheck.h:24
clang::tidy::modernize::ReplaceAutoPtrCheck
Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr.
Definition: ReplaceAutoPtrCheck.h:44
clang::tidy::modernize::UseBoolLiteralsCheck
Finds integer literals which are cast to bool.
Definition: UseBoolLiteralsCheck.h:23
UseNullptrCheck.h
clang::tidy::modernize::UseNoexceptCheck
Replace dynamic exception specifications, with noexcept (or user-defined macro) or noexcept(false)...
Definition: UseNoexceptCheck.h:33
UseEmplaceCheck.h
RawStringLiteralCheck.h
clang::tidy::modernize::UseOverrideCheck
Use C++11&#39;s override and remove virtual where applicable.
Definition: UseOverrideCheck.h:20
clang::tidy::ClangTidyCheckFactories::registerCheck
void registerCheck(StringRef CheckName)
Registers the CheckType with the name Name.
Definition: ClangTidyModule.h:59
clang::tidy::modernize::PassByValueCheck
Definition: PassByValueCheck.h:22
clang::tidy::modernize::UseDefaultMemberInitCheck
Convert a default constructor&#39;s member initializers into default member initializers.
Definition: UseDefaultMemberInitCheck.h:25
clang::tidy::modernize::MakeUniqueCheck
Replace the pattern:
Definition: MakeUniqueCheck.h:28
DeprecatedHeadersCheck.h
clang::tidy::modernize::MakeSharedCheck
Replace the pattern:
Definition: MakeSharedCheck.h:31
PassByValueCheck.h
AvoidBindCheck.h
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:49
UseEqualsDeleteCheck.h
clang::tidy::modernize::ModernizeModule
Definition: ModernizeTidyModule.cpp:44
clang::tidy::modernize::UseEqualsDefaultCheck
Replace default bodies of special member functions with &#39;= default;&#39;.
Definition: UseEqualsDefaultCheck.h:38
clang::tidy::ClangTidyCheckFactories
A collection of ClangTidyCheckFactory instances.
Definition: ClangTidyModule.h:27
ReplaceAutoPtrCheck.h
clang::tidy::ClangTidyOptions::CheckOptions
OptionMap CheckOptions
Key-value mapping used to store check-specific options.
Definition: ClangTidyOptions.h:102
UnaryStaticAssertCheck.h
UseOverrideCheck.h
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:84
clang::tidy::modernize::RedundantVoidArgCheck
Find and remove redundant void argument lists.
Definition: RedundantVoidArgCheck.h:32
clang::tidy::modernize::AvoidBindCheck
Replace simple uses of std::bind with a lambda.
Definition: AvoidBindCheck.h:25
clang::tidy::modernize::LoopConvertCheck
Definition: LoopConvertCheck.h:20
UseUsingCheck.h
ReplaceRandomShuffleCheck.h
clang::tidy::modernize::ModernizeModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: ModernizeTidyModule.cpp:84
clang::tidy::modernize::ReplaceRandomShuffleCheck
std::random_shuffle will be removed as of C++17.
Definition: ReplaceRandomShuffleCheck.h:25
MakeSharedCheck.h
UseTransparentFunctorsCheck.h
UseNoexceptCheck.h
UseEqualsDefaultCheck.h
clang::tidy::modernize::DeprecatedHeadersCheck
This check replaces deprecated C library headers with their C++ STL alternatives. ...
Definition: DeprecatedHeadersCheck.h:36
X
static clang::FrontendPluginRegistry::Add< clang::tidy::ClangTidyPluginAction > X("clang-tidy", "clang-tidy")
UseBoolLiteralsCheck.h
clang::tidy::modernize::UseAutoCheck
Definition: UseAutoCheck.h:19
clang::tidy::modernize::UseTransparentFunctorsCheck
Prefer using transparent functors to non-transparent ones.
Definition: UseTransparentFunctorsCheck.h:23
clang
Definition: AndroidTidyModule.cpp:28
UseDefaultMemberInitCheck.h
clang::tidy::modernize::UnaryStaticAssertCheck
Replaces a static_assert declaration with an empty message with the unary version.
Definition: UnaryStaticAssertCheck.h:24
clang::tidy::modernize::ModernizeModule::addCheckFactories
void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override
Implement this function in order to register all CheckFactories belonging to this module...
Definition: ModernizeTidyModule.cpp:46
RedundantVoidArgCheck.h
clang::tidy::modernize::UseUsingCheck
Check finds typedefs and replaces it with usings.
Definition: UseUsingCheck.h:23
LoopConvertCheck.h
MakeUniqueCheck.h
clang::tidy::ModernizeModuleAnchorSource
volatile int ModernizeModuleAnchorSource
Definition: ModernizeTidyModule.cpp:110
ReturnBracedInitListCheck.h
clang::tidy::modernize::UseEqualsDeleteCheck
Mark unimplemented private special member functions with &#39;= delete&#39;.
Definition: UseEqualsDeleteCheck.h:38
clang::tidy::modernize::ReturnBracedInitListCheck
Use a braced init list for return statements rather than unnecessary repeating the return type name...
Definition: ReturnBracedInitListCheck.h:24
ShrinkToFitCheck.h
clang::tidy::modernize::ShrinkToFitCheck
Replace copy and swap tricks on shrinkable containers with the shrink_to_fit() method call...
Definition: ShrinkToFitCheck.h:25
clang::tidy::modernize::UseNullptrCheck
Definition: UseNullptrCheck.h:19
clang::tidy::modernize::UseEmplaceCheck
This check looks for cases when inserting new element into std::vector but the element is constructed...
Definition: UseEmplaceCheck.h:28