[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / clang-tools-extra / clang-tidy / modernize / MakeSmartPtrCheck.h
blob02374dc06d9be514de6c9ed113756e3f0e4806c8
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 //===----------------------------------------------------------------------===//
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
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>
19 namespace clang::tidy::modernize {
21 /// Base class for MakeSharedCheck and MakeUniqueCheck.
22 class MakeSmartPtrCheck : public ClangTidyCheck {
23 public:
24 MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
25 StringRef MakeSmartPtrFunctionName);
26 void registerMatchers(ast_matchers::MatchFinder *Finder) final;
27 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
28 Preprocessor *ModuleExpanderPP) override;
29 void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
30 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
32 protected:
33 using SmartPtrTypeMatcher = ast_matchers::internal::BindableMatcher<QualType>;
35 /// Returns matcher that match with different smart pointer types.
36 ///
37 /// Requires to bind pointer type (qualType) with PointerType string declared
38 /// in this class.
39 virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
41 /// Returns whether the C++ version is compatible with current check.
42 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
44 static const char PointerType[];
46 private:
47 utils::IncludeInserter Inserter;
48 const StringRef MakeSmartPtrFunctionHeader;
49 const StringRef MakeSmartPtrFunctionName;
50 const bool IgnoreMacros;
51 const bool IgnoreDefaultInitialization;
53 void checkConstruct(SourceManager &SM, ASTContext *Ctx,
54 const CXXConstructExpr *Construct, const QualType *Type,
55 const CXXNewExpr *New);
56 void checkReset(SourceManager &SM, ASTContext *Ctx,
57 const CXXMemberCallExpr *Reset, const CXXNewExpr *New);
59 /// Returns true when the fixes for replacing CXXNewExpr are generated.
60 bool replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New,
61 SourceManager &SM, ASTContext *Ctx);
62 void insertHeader(DiagnosticBuilder &Diag, FileID FD);
65 } // namespace clang::tidy::modernize
67 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H