RedundantSmartptrGetCheck.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::readability {
  12. /// Find and remove redundant calls to smart pointer's `.get()` method.
  13. ///
  14. /// Examples:
  15. ///
  16. /// \code
  17. /// ptr.get()->Foo() ==> ptr->Foo()
  18. /// *ptr.get() ==> *ptr
  19. /// *ptr->get() ==> **ptr
  20. /// \endcode
  21. class RedundantSmartptrGetCheck : public ClangTidyCheck {
  22. public:
  23. RedundantSmartptrGetCheck(StringRef Name, ClangTidyContext *Context)
  24. : ClangTidyCheck(Name, Context),
  25. IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
  26. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  27. return LangOpts.CPlusPlus;
  28. }
  29. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  30. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  31. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  32. std::optional<TraversalKind> getCheckTraversalKind() const override {
  33. return TK_IgnoreUnlessSpelledInSource;
  34. }
  35. private:
  36. const bool IgnoreMacros;
  37. };
  38. } // namespace clang::tidy::readability
  39. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_REDUNDANTSMARTPTRGETCHECK_H