clang-tools 3.8.0

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 "LoopConvertCheck.h"
14 #include "MakeUniqueCheck.h"
15 #include "PassByValueCheck.h"
16 #include "RedundantVoidArgCheck.h"
17 #include "ReplaceAutoPtrCheck.h"
18 #include "ShrinkToFitCheck.h"
19 #include "UseAutoCheck.h"
20 #include "UseDefaultCheck.h"
21 #include "UseNullptrCheck.h"
22 #include "UseOverrideCheck.h"
23
24 using namespace clang::ast_matchers;
25
26 namespace clang {
27 namespace tidy {
28 namespace modernize {
29
30 class ModernizeModule : public ClangTidyModule {
31 public:
32 void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
33 CheckFactories.registerCheck<LoopConvertCheck>("modernize-loop-convert");
34 CheckFactories.registerCheck<MakeUniqueCheck>("modernize-make-unique");
35 CheckFactories.registerCheck<PassByValueCheck>("modernize-pass-by-value");
36 CheckFactories.registerCheck<RedundantVoidArgCheck>(
37 "modernize-redundant-void-arg");
38 CheckFactories.registerCheck<ReplaceAutoPtrCheck>(
39 "modernize-replace-auto-ptr");
40 CheckFactories.registerCheck<ShrinkToFitCheck>("modernize-shrink-to-fit");
41 CheckFactories.registerCheck<UseAutoCheck>("modernize-use-auto");
42 CheckFactories.registerCheck<UseDefaultCheck>("modernize-use-default");
43 CheckFactories.registerCheck<UseNullptrCheck>("modernize-use-nullptr");
44 CheckFactories.registerCheck<UseOverrideCheck>("modernize-use-override");
45 }
46
47 ClangTidyOptions getModuleOptions() override {
48 ClangTidyOptions Options;
49 auto &Opts = Options.CheckOptions;
50 // For types whose size in bytes is above this threshold, we prefer taking a
51 // const-reference than making a copy.
52 Opts["modernize-loop-convert.MaxCopySize"] = "16";
53
54 Opts["modernize-loop-convert.MinConfidence"] = "reasonable";
55 Opts["modernize-loop-convert.NamingStyle"] = "CamelCase";
56 Opts["modernize-pass-by-value.IncludeStyle"] = "llvm"; // Also: "google".
57 Opts["modernize-replace-auto-ptr.IncludeStyle"] = "llvm"; // Also: "google".
58
59 // Comma-separated list of macros that behave like NULL.
60 Opts["modernize-use-nullptr.NullMacros"] = "NULL";
61 return Options;
62 }
63 };
64
65 // Register the ModernizeTidyModule using this statically initialized variable.
66 static ClangTidyModuleRegistry::Add<ModernizeModule> X("modernize-module",
67 "Add modernize checks.");
68
69 } // namespace modernize
70
71 // This anchor is used to force the linker to link in the generated object file
72 // and thus register the ModernizeModule.
73 volatile int ModernizeModuleAnchorSource = 0;
74
75 } // namespace tidy
76 } // namespace clang
UseAutoCheck.h
clang::tidy::modernize::X
static ClangTidyModuleRegistry::Add< ModernizeModule > X("modernize-module","Add modernize checks.")
clang::tidy::modernize::ReplaceAutoPtrCheck
Transforms the deprecated std::auto_ptr into the C++11 std::unique_ptr.
Definition: ReplaceAutoPtrCheck.h:44
UseNullptrCheck.h
clang::tidy::modernize::UseOverrideCheck
Use C++11'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:58
clang::tidy::modernize::PassByValueCheck
Definition: PassByValueCheck.h:22
clang::tidy::modernize::MakeUniqueCheck
Replace the pattern:
Definition: MakeUniqueCheck.h:28
PassByValueCheck.h
clang::tidy::ClangTidyOptions
Contains options for clang-tidy.
Definition: ClangTidyOptions.h:49
clang::tidy::modernize::ModernizeModule
Definition: ModernizeTidyModule.cpp:30
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:85
clang::tidy::modernize::UseDefaultCheck
Replace default bodies of special member functions with '= default;'.
Definition: UseDefaultCheck.h:38
UseDefaultCheck.h
UseOverrideCheck.h
clang::tidy::ClangTidyModule
A clang-tidy module groups a number of ClangTidyChecks and gives them a prefixed name.
Definition: ClangTidyModule.h:83
clang::tidy::modernize::RedundantVoidArgCheck
Find and remove redundant void argument lists.
Definition: RedundantVoidArgCheck.h:32
clang::tidy::modernize::LoopConvertCheck
Definition: LoopConvertCheck.h:20
clang::tidy::modernize::ModernizeModule::getModuleOptions
ClangTidyOptions getModuleOptions() override
Gets default options for checks defined in this module.
Definition: ModernizeTidyModule.cpp:47
clang::tidy::modernize::UseAutoCheck
Definition: UseAutoCheck.h:19
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:32
RedundantVoidArgCheck.h
LoopConvertCheck.h
MakeUniqueCheck.h
clang::tidy::ModernizeModuleAnchorSource
volatile int ModernizeModuleAnchorSource
Definition: ModernizeTidyModule.cpp:73
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