clang-tools 10.0.0

MakeSmartPtrCheck.h
Go to the documentation of this file.
1 //===--- MakeSmartPtrCheck.h - clang-tidy------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
11
12 #include "../ClangTidyCheck.h"
13 #include "../utils/IncludeInserter.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.
24 class MakeSmartPtrCheck : public ClangTidyCheck {
25 public:
26 MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
27 StringRef MakeSmartPtrFunctionName);
28 void registerMatchers(ast_matchers::MatchFinder *Finder) final;
29 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
30 Preprocessor *ModuleExpanderPP) 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 /// 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
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, ASTContext *Ctx,
56 const CXXConstructExpr *Construct, const QualType *Type,
57 const CXXNewExpr *New);
58 void checkReset(SourceManager &SM, ASTContext *Ctx,
59 const CXXMemberCallExpr *Member, const CXXNewExpr *New);
60
61 /// Returns true when the fixes for replacing CXXNewExpr are generated.
62 bool replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New,
63 SourceManager &SM, ASTContext *Ctx);
64 void insertHeader(DiagnosticBuilder &Diag, FileID FD);
65 };
66
67 } // namespace modernize
68 } // namespace tidy
69 } // namespace clang
70
71 #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
clang::tidy::modernize::MakeSmartPtrCheck::isLanguageVersionSupported
virtual bool isLanguageVersionSupported(const LangOptions &LangOpts) const
Returns whether the C++ version is compatible with current check.
Definition: MakeSmartPtrCheck.cpp:63
clang::tidy::utils::IncludeSorter::IncludeStyle
IncludeStyle
Supported include styles.
Definition: IncludeSorter.h:26
clang::tidy::modernize::MakeSmartPtrCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) final
Override this to register AST matchers with Finder.
Definition: MakeSmartPtrCheck.cpp:78
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::modernize::MakeSmartPtrCheck::getSmartPointerTypeMatcher
virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const =0
Returns matcher that match with different smart pointer types.
clang::tidy::modernize::MakeSmartPtrCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition: MakeSmartPtrCheck.cpp:68
Ctx
Context Ctx
Definition: TUScheduler.cpp:237
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:110
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
clang::tidy::modernize::MakeSmartPtrCheck::PointerType
static const char PointerType[]
Definition: MakeSmartPtrCheck.h:46
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
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:56
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77
clang::tidy::modernize::MakeSmartPtrCheck
Base class for MakeSharedCheck and MakeUniqueCheck.
Definition: MakeSmartPtrCheck.h:24
clang::tidy::modernize::MakeSmartPtrCheck::MakeSmartPtrCheck
MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context, StringRef MakeSmartPtrFunctionName)
Definition: MakeSmartPtrCheck.cpp:44
Type
NodeType Type
Definition: HTMLGenerator.cpp:73