clang-tools  14.0.0git
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 {
15 namespace tidy {
16 namespace readability {
17 
18 /// Find and remove redundant calls to smart pointer's `.get()` method.
19 ///
20 /// Examples:
21 ///
22 /// \code
23 /// ptr.get()->Foo() ==> ptr->Foo()
24 /// *ptr.get() ==> *ptr
25 /// *ptr->get() ==> **ptr
26 /// \endcode
28 public:
30  : ClangTidyCheck(Name, Context),
31  IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
32  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
33  return LangOpts.CPlusPlus;
34  }
35  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
36  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
37  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
38  llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
39  return TK_IgnoreUnlessSpelledInSource;
40  }
41 
42 private:
43  const bool IgnoreMacros;
44 };
45 
46 } // namespace readability
47 } // namespace tidy
48 } // namespace clang
49 
50 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::readability::RedundantSmartptrGetCheck
Find and remove redundant calls to smart pointer's .get() method.
Definition: RedundantSmartptrGetCheck.h:27
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
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:113
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:141
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidyCheck.h:416
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:32
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:72
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
clang::tidy::readability::RedundantSmartptrGetCheck::getCheckTraversalKind
llvm::Optional< TraversalKind > getCheckTraversalKind() const override
Definition: RedundantSmartptrGetCheck.h:38
clang::tidy::readability::RedundantSmartptrGetCheck::RedundantSmartptrGetCheck
RedundantSmartptrGetCheck(StringRef Name, ClangTidyContext *Context)
Definition: RedundantSmartptrGetCheck.h:29
clang::tidy::readability::RedundantSmartptrGetCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: RedundantSmartptrGetCheck.cpp:118