clang-tools  4.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 "clang/ASTMatchers/ASTMatchFinder.h"
15 #include "clang/ASTMatchers/ASTMatchersInternal.h"
16 #include "llvm/ADT/StringRef.h"
17 #include <string>
18 
19 namespace clang {
20 namespace tidy {
21 namespace modernize {
22 
23 /// Base class for MakeSharedCheck and MakeUniqueCheck.
25 public:
27  std::string makeSmartPtrFunctionName);
28  void registerMatchers(ast_matchers::MatchFinder *Finder) final;
29  void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
30 
31 protected:
32  using SmartPtrTypeMatcher = ast_matchers::internal::BindableMatcher<QualType>;
33 
34  /// Returns matcher that match with different smart pointer types.
35  ///
36  /// Requires to bind pointer type (qualType) with PointerType string declared
37  /// in this class.
39 
40  static const char PointerType[];
41  static const char ConstructorCall[];
42  static const char ResetCall[];
43  static const char NewExpression[];
44 
45 private:
46  std::string makeSmartPtrFunctionName;
47 
48  void checkConstruct(SourceManager &SM, const CXXConstructExpr *Construct,
49  const QualType *Type, const CXXNewExpr *New);
50  void checkReset(SourceManager &SM, const CXXMemberCallExpr *Member,
51  const CXXNewExpr *New);
52  void replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New);
53 };
54 
55 } // namespace modernize
56 } // namespace tidy
57 } // namespace clang
58 
59 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
const std::string Name
Definition: USRFinder.cpp:164
ast_matchers::internal::BindableMatcher< QualType > SmartPtrTypeMatcher
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition: ClangTidy.cpp:262
void registerMatchers(ast_matchers::MatchFinder *Finder) final
Override this to register AST matchers with Finder.
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const =0
Returns matcher that match with different smart pointer types.
SourceManager & SM
void check(const ast_matchers::MatchFinder::MatchResult &Result) final
ClangTidyChecks that register ASTMatchers should do the actual work in here.
ClangTidyContext & Context
Definition: ClangTidy.cpp:87
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Base class for MakeSharedCheck and MakeUniqueCheck.
MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, std::string makeSmartPtrFunctionName)
const NamedDecl * Result
Definition: USRFinder.cpp:162