2016-05-03 00:56:39 +08:00
|
|
|
//===--- MakeSmartPtrCheck.h - clang-tidy------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-05-03 00:56:39 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
|
|
|
|
|
2019-03-25 20:38:26 +08:00
|
|
|
#include "../ClangTidyCheck.h"
|
2017-07-05 15:49:00 +08:00
|
|
|
#include "../utils/IncludeInserter.h"
|
2016-05-03 09:13:27 +08:00
|
|
|
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
|
|
|
#include "clang/ASTMatchers/ASTMatchersInternal.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
2016-05-03 00:56:39 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace modernize {
|
|
|
|
|
|
|
|
/// Base class for MakeSharedCheck and MakeUniqueCheck.
|
|
|
|
class MakeSmartPtrCheck : public ClangTidyCheck {
|
|
|
|
public:
|
|
|
|
MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
|
2017-07-05 15:49:00 +08:00
|
|
|
StringRef MakeSmartPtrFunctionName);
|
2016-05-03 09:13:27 +08:00
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder) final;
|
2019-03-23 02:58:12 +08:00
|
|
|
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
|
|
|
|
Preprocessor *ModuleExpanderPP) override;
|
2016-05-03 09:13:27 +08:00
|
|
|
void check(const ast_matchers::MatchFinder::MatchResult &Result) final;
|
2017-07-05 15:49:00 +08:00
|
|
|
void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
|
2016-05-03 00:56:39 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
using SmartPtrTypeMatcher = ast_matchers::internal::BindableMatcher<QualType>;
|
|
|
|
|
|
|
|
/// Returns matcher that match with different smart pointer types.
|
|
|
|
///
|
|
|
|
/// Requires to bind pointer type (qualType) with PointerType string declared
|
|
|
|
/// in this class.
|
|
|
|
virtual SmartPtrTypeMatcher getSmartPointerTypeMatcher() const = 0;
|
|
|
|
|
2018-03-21 22:39:24 +08:00
|
|
|
/// Returns whether the C++ version is compatible with current check.
|
[clang-tidy] Added virtual isLanguageVersionSupported to ClangTidyCheck
Summary:
Motivated by [[ https://bugs.llvm.org/show_bug.cgi?id=45045 | Tune inspections to a specific C++ standard. ]]
Moves the isLanguageVersionSupported virtual function from `MakeSmartPtrCheck` to the base `ClangTidyCheck` class.
This will disable registering matchers or pp callbacks on unsupported language versions for a check.
Having it as a standalone function is cleaner than manually disabling the check in the register function and should hopefully
encourage check developers to actually restrict the check based on language version.
As an added bonus this could enable automatic detection of what language version a check runs on for the purpose of documentation generation
Reviewers: aaron.ballman, gribozavr2, Eugene.Zelenko, JonasToth, alexfh, hokein
Reviewed By: gribozavr2
Subscribers: xazax.hun, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D75289
2020-02-28 21:03:30 +08:00
|
|
|
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override;
|
2018-03-21 22:39:24 +08:00
|
|
|
|
2016-05-03 00:56:39 +08:00
|
|
|
static const char PointerType[];
|
|
|
|
|
|
|
|
private:
|
2020-07-27 19:48:53 +08:00
|
|
|
utils::IncludeInserter Inserter;
|
2017-07-05 15:49:00 +08:00
|
|
|
const std::string MakeSmartPtrFunctionHeader;
|
|
|
|
const std::string MakeSmartPtrFunctionName;
|
2017-08-04 19:18:00 +08:00
|
|
|
const bool IgnoreMacros;
|
2020-10-29 10:45:09 +08:00
|
|
|
const bool IgnoreDefaultInitialization;
|
2016-10-31 23:48:01 +08:00
|
|
|
|
2018-10-09 23:58:18 +08:00
|
|
|
void checkConstruct(SourceManager &SM, ASTContext *Ctx,
|
|
|
|
const CXXConstructExpr *Construct, const QualType *Type,
|
|
|
|
const CXXNewExpr *New);
|
|
|
|
void checkReset(SourceManager &SM, ASTContext *Ctx,
|
|
|
|
const CXXMemberCallExpr *Member, const CXXNewExpr *New);
|
2017-07-05 15:49:00 +08:00
|
|
|
|
2017-08-17 18:14:52 +08:00
|
|
|
/// Returns true when the fixes for replacing CXXNewExpr are generated.
|
|
|
|
bool replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New,
|
2018-10-09 23:58:18 +08:00
|
|
|
SourceManager &SM, ASTContext *Ctx);
|
2017-07-05 15:49:00 +08:00
|
|
|
void insertHeader(DiagnosticBuilder &Diag, FileID FD);
|
2016-05-03 00:56:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace modernize
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_MAKE_SMART_PTR_H
|