clang-tools 6.0.0

MakeSmartPtrCheck.h
Go to the documentation of this file.
1 //===--- MakeSmartPtrCheck.h - clang-tidy------------------------*- C++ -*-===//
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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
12
13 #include "../ClangTidy.h"
14 #include "../utils/IncludeInserter.h"
15 #include "clang/ASTMatchers/ASTMatchFinder.h"
16 #include "clang/ASTMatchers/ASTMatchersInternal.h"
17 #include "llvm/ADT/StringRef.h"
18 #include <string>
19
20 namespace clang {
21 namespace tidy {
22 namespace modernize {
23
24 /// Base class for MakeSharedCheck and MakeUniqueCheck.
25 class MakeSmartPtrCheck : public ClangTidyCheck {
26 public:
27 MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
28 StringRef MakeSmartPtrFunctionName);
29 void registerMatchers(ast_matchers::MatchFinder *Finder) final;
30 void registerPPCallbacks(clang::CompilerInstance &Compiler) override;
31 void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
32 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
33
34 protected:
35 using SmartPtrTypeMatcher = ast_matchers::internal::BindableMatcher<QualType>;
36
37 /// Returns matcher that match with different smart pointer types.
38 ///
39 /// Requires to bind pointer type (qualType) with PointerType string declared
40 /// in this class.
41 virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
42
43 static const char PointerType[];
44 static const char ConstructorCall[];
45 static const char ResetCall[];
46 static const char NewExpression[];
47
48 private:
49 std::unique_ptr<utils::IncludeInserter> Inserter;
50 const utils::IncludeSorter::IncludeStyle IncludeStyle;
51 const std::string MakeSmartPtrFunctionHeader;
52 const std::string MakeSmartPtrFunctionName;
53 const bool IgnoreMacros;
54
55 void checkConstruct(SourceManager &SM, const CXXConstructExpr *Construct,
56 const QualType *Type, const CXXNewExpr *New);
57 void checkReset(SourceManager &SM, const CXXMemberCallExpr *Member,
58 const CXXNewExpr *New);
59
60 /// Returns true when the fixes for replacing CXXNewExpr are generated.
61 bool replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New,
62 SourceManager &SM);
63 void insertHeader(DiagnosticBuilder &Diag, FileID FD);
64 };
65
66 } // namespace modernize
67 } // namespace tidy
68 } // namespace clang
69
70 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
clang::tidy::modernize::MakeSmartPtrCheck::SmartPtrTypeMatcher
ast_matchers::internal::BindableMatcher< QualType > SmartPtrTypeMatcher
Definition: MakeSmartPtrCheck.h:35
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::utils::IncludeSorter::IncludeStyle
IncludeStyle
Supported include styles.
Definition: IncludeSorter.h:27
clang::tidy::modernize::MakeSmartPtrCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) final
Override this to register AST matchers with Finder.
Definition: MakeSmartPtrCheck.cpp:72
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::modernize::MakeSmartPtrCheck::registerPPCallbacks
void registerPPCallbacks(clang::CompilerInstance &Compiler) override
Definition: MakeSmartPtrCheck.cpp:64
clang::tidy::modernize::MakeSmartPtrCheck::getSmartPointerTypeMatcher
virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const =0
Returns matcher that match with different smart pointer types.
clang::tidy::modernize::MakeSmartPtrCheck::ConstructorCall
static const char ConstructorCall[]
Definition: MakeSmartPtrCheck.h:44
clang::tidy::modernize::MakeSmartPtrCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) final
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: MakeSmartPtrCheck.cpp:104
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:99
clang::tidy::modernize::MakeSmartPtrCheck::PointerType
static const char PointerType[]
Definition: MakeSmartPtrCheck.h:43
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::modernize::MakeSmartPtrCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: MakeSmartPtrCheck.cpp:57
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:104
clang::tidy::modernize::MakeSmartPtrCheck
Base class for MakeSharedCheck and MakeUniqueCheck.
Definition: MakeSmartPtrCheck.h:25
clang::tidy::modernize::MakeSmartPtrCheck::MakeSmartPtrCheck
MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, StringRef MakeSmartPtrFunctionName)
Definition: MakeSmartPtrCheck.cpp:45
clang::tidy::modernize::MakeSmartPtrCheck::NewExpression
static const char NewExpression[]
Definition: MakeSmartPtrCheck.h:46
clang::tidy::modernize::MakeSmartPtrCheck::ResetCall
static const char ResetCall[]
Definition: MakeSmartPtrCheck.h:45