Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:20

0001 //===--- MakeSmartPtrCheck.h - clang-tidy------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "../utils/IncludeInserter.h"
0014 #include "clang/ASTMatchers/ASTMatchFinder.h"
0015 #include "clang/ASTMatchers/ASTMatchersInternal.h"
0016 #include "llvm/ADT/StringRef.h"
0017 #include <string>
0018 
0019 namespace clang::tidy::modernize {
0020 
0021 /// Base class for MakeSharedCheck and MakeUniqueCheck.
0022 class MakeSmartPtrCheck : public ClangTidyCheck {
0023 public:
0024   MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
0025                     StringRef MakeSmartPtrFunctionName);
0026   void registerMatchers(ast_matchers::MatchFinder *Finder) final;
0027   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
0028                            Preprocessor *ModuleExpanderPP) override;
0029   void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
0030   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
0031 
0032 protected:
0033   using SmartPtrTypeMatcher = ast_matchers::internal::BindableMatcher<QualType>;
0034 
0035   /// Returns matcher that match with different smart pointer types.
0036   ///
0037   /// Requires to bind pointer type (qualType) with PointerType string declared
0038   /// in this class.
0039   virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
0040 
0041   /// Returns whether the C++ version is compatible with current check.
0042   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
0043 
0044   static const char PointerType[];
0045 
0046 private:
0047   utils::IncludeInserter Inserter;
0048   const StringRef MakeSmartPtrFunctionHeader;
0049   const StringRef MakeSmartPtrFunctionName;
0050   const bool IgnoreMacros;
0051   const bool IgnoreDefaultInitialization;
0052 
0053   void checkConstruct(SourceManager &SM, ASTContext *Ctx,
0054                       const CXXConstructExpr *Construct, const QualType *Type,
0055                       const CXXNewExpr *New);
0056   void checkReset(SourceManager &SM, ASTContext *Ctx,
0057                   const CXXMemberCallExpr *Reset, const CXXNewExpr *New);
0058 
0059   /// Returns true when the fixes for replacing CXXNewExpr are generated.
0060   bool replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New,
0061                   SourceManager &SM, ASTContext *Ctx);
0062   void insertHeader(DiagnosticBuilder &Diag, FileID FD);
0063 };
0064 
0065 } // namespace clang::tidy::modernize
0066 
0067 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H