clang-tools 19.0.0git
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
19namespace clang::tidy::modernize {
20
21/// Base class for MakeSharedCheck and MakeUniqueCheck.
23public:
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;
31
32protected:
33 using SmartPtrTypeMatcher = ast_matchers::internal::BindableMatcher<QualType>;
34
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.
40
41 /// Returns whether the C++ version is compatible with current check.
42 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
43
44 static const char PointerType[];
45
46private:
48 const StringRef MakeSmartPtrFunctionHeader;
49 const StringRef MakeSmartPtrFunctionName;
50 const bool IgnoreMacros;
51 const bool IgnoreDefaultInitialization;
52
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);
58
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);
63};
64
65} // namespace clang::tidy::modernize
66
67#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
llvm::SmallString< 256U > Name
NodeType Type
Base class for all clang-tidy checks.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Base class for MakeSharedCheck and MakeUniqueCheck.
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.
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Returns whether the C++ version is compatible with current check.
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
void registerMatchers(ast_matchers::MatchFinder *Finder) final
Override this to register AST matchers with Finder.
ast_matchers::internal::BindableMatcher< QualType > SmartPtrTypeMatcher
Produces fixes to insert specified includes to source files, if not yet present.
llvm::StringMap< ClangTidyValue > OptionMap