clang-tools
20.0.0git
llvm-project
clang-tools-extra
clang-tidy
readability
RedundantSmartptrGetCheck.h
Go to the documentation of this file.
1
//===--- RedundantSmartptrGetCheck.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_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
11
12
#include "../ClangTidyCheck.h"
13
14
namespace
clang::tidy::readability
{
15
16
/// Find and remove redundant calls to smart pointer's `.get()` method.
17
///
18
/// Examples:
19
///
20
/// \code
21
/// ptr.get()->Foo() ==> ptr->Foo()
22
/// *ptr.get() ==> *ptr
23
/// *ptr->get() ==> **ptr
24
/// \endcode
25
class
RedundantSmartptrGetCheck
:
public
ClangTidyCheck
{
26
public
:
27
RedundantSmartptrGetCheck
(StringRef
Name
,
ClangTidyContext
*Context)
28
:
ClangTidyCheck
(
Name
, Context),
29
IgnoreMacros(
Options
.getLocalOrGlobal(
"IgnoreMacros"
, true)) {}
30
bool
isLanguageVersionSupported
(
const
LangOptions &LangOpts)
const override
{
31
return
LangOpts.CPlusPlus;
32
}
33
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
34
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
35
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
36
std::optional<TraversalKind>
getCheckTraversalKind
()
const override
{
37
return
TK_IgnoreUnlessSpelledInSource;
38
}
39
40
private
:
41
const
bool
IgnoreMacros;
42
};
43
44
}
// namespace clang::tidy::readability
45
46
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
Name
llvm::SmallString< 256U > Name
Definition:
ChainedComparisonCheck.cpp:42
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:53
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition:
ClangTidyCheck.h:490
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:69
clang::tidy::readability::RedundantSmartptrGetCheck
Find and remove redundant calls to smart pointer's .get() method.
Definition:
RedundantSmartptrGetCheck.h:25
clang::tidy::readability::RedundantSmartptrGetCheck::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:
RedundantSmartptrGetCheck.cpp:111
clang::tidy::readability::RedundantSmartptrGetCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
RedundantSmartptrGetCheck.cpp:139
clang::tidy::readability::RedundantSmartptrGetCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Override this to disable registering matchers and PP callbacks if an invalid language version is bein...
Definition:
RedundantSmartptrGetCheck.h:30
clang::tidy::readability::RedundantSmartptrGetCheck::RedundantSmartptrGetCheck
RedundantSmartptrGetCheck(StringRef Name, ClangTidyContext *Context)
Definition:
RedundantSmartptrGetCheck.h:27
clang::tidy::readability::RedundantSmartptrGetCheck::getCheckTraversalKind
std::optional< TraversalKind > getCheckTraversalKind() const override
Definition:
RedundantSmartptrGetCheck.h:36
clang::tidy::readability::RedundantSmartptrGetCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
RedundantSmartptrGetCheck.cpp:116
clang::tidy::readability
Definition:
AvoidConstParamsInDecls.cpp:17
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition:
ClangTidyOptions.h:126
Generated on Sun Nov 24 2024 20:58:51 for clang-tools by
1.9.6