clang-tools 10.0.0

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
27 class RedundantSmartptrGetCheck : public ClangTidyCheck {
28 public:
29 RedundantSmartptrGetCheck(StringRef Name, ClangTidyContext *Context)
30 : ClangTidyCheck(Name, Context),
31 IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", 1) != 0) {}
32 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
33 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
34 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
35
36 private:
37 const bool IgnoreMacros;
38 };
39
40 } // namespace readability
41 } // namespace tidy
42 } // namespace clang
43
44 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:47
clang::tidy::readability::RedundantSmartptrGetCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: RedundantSmartptrGetCheck.cpp:101
clang::tidy::readability::RedundantSmartptrGetCheck::RedundantSmartptrGetCheck
RedundantSmartptrGetCheck(StringRef Name, ClangTidyContext *Context)
Definition: RedundantSmartptrGetCheck.h:29
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition: ClangTidyCheck.h:184
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:129
clang::tidy::readability::RedundantSmartptrGetCheck
Find and remove redundant calls to smart pointer&#39;s .get() method.
Definition: RedundantSmartptrGetCheck.h:27
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition: ClangTidyOptions.h:97
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
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:96
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:77