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:
RedundantSmartptrGetCheck(StringRef Name,ClangTidyContext * Context)29   RedundantSmartptrGetCheck(StringRef Name, ClangTidyContext *Context)
30       : ClangTidyCheck(Name, Context),
31         IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
isLanguageVersionSupported(const LangOptions & LangOpts)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 
39 private:
40   const bool IgnoreMacros;
41 };
42 
43 } // namespace readability
44 } // namespace tidy
45 } // namespace clang
46 
47 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
48