clang-tools  7.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.
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.
42 
43  /// Returns whether the C++ version is compatible with current check.
44  virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const;
45 
46  static const char PointerType[];
47  static const char ConstructorCall[];
48  static const char ResetCall[];
49  static const char NewExpression[];
50 
51 private:
52  std::unique_ptr<utils::IncludeInserter> Inserter;
53  const utils::IncludeSorter::IncludeStyle IncludeStyle;
54  const std::string MakeSmartPtrFunctionHeader;
55  const std::string MakeSmartPtrFunctionName;
56  const bool IgnoreMacros;
57 
58  void checkConstruct(SourceManager &SM, const CXXConstructExpr *Construct,
59  const QualType *Type, const CXXNewExpr *New);
60  void checkReset(SourceManager &SM, const CXXMemberCallExpr *Member,
61  const CXXNewExpr *New);
62 
63  /// Returns true when the fixes for replacing CXXNewExpr are generated.
64  bool replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New,
65  SourceManager &SM);
66  void insertHeader(DiagnosticBuilder &Diag, FileID FD);
67 };
68 
69 } // namespace modernize
70 } // namespace tidy
71 } // namespace clang
72 
73 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
llvm::StringRef Name
ast_matchers::internal::BindableMatcher< QualType > SmartPtrTypeMatcher
virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const
Returns whether the C++ version is compatible with current check.
IncludeStyle
Supported include styles.
Definition: IncludeSorter.h:27
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
void registerPPCallbacks(clang::CompilerInstance &Compiler) override
virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const =0
Returns matcher that match with different smart pointer types.
void check(const ast_matchers::MatchFinder::MatchResult &Result) final
ClangTidyChecks that register ASTMatchers should do the actual work in here.
std::map< std::string, std::string > OptionMap
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Base class for MakeSharedCheck and MakeUniqueCheck.
MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, StringRef MakeSmartPtrFunctionName)