UnusedUsingDeclsCheck.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //===--- UnusedUsingDeclsCheck.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_MISC_UNUSED_USING_DECLS_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
  10. #include "../ClangTidyCheck.h"
  11. #include "../utils/FileExtensionsUtils.h"
  12. #include "llvm/ADT/SmallPtrSet.h"
  13. #include <vector>
  14. namespace clang::tidy::misc {
  15. /// Finds unused using declarations.
  16. ///
  17. /// For the user-facing documentation see:
  18. /// http://clang.llvm.org/extra/clang-tidy/checks/misc/unused-using-decls.html
  19. class UnusedUsingDeclsCheck : public ClangTidyCheck {
  20. public:
  21. UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context);
  22. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  23. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  24. void onEndOfTranslationUnit() override;
  25. private:
  26. void removeFromFoundDecls(const Decl *D);
  27. struct UsingDeclContext {
  28. explicit UsingDeclContext(const UsingDecl *FoundUsingDecl)
  29. : FoundUsingDecl(FoundUsingDecl), IsUsed(false) {}
  30. // A set saves all UsingShadowDecls introduced by a UsingDecl. A UsingDecl
  31. // can introduce multiple UsingShadowDecls in some cases (such as
  32. // overloaded functions).
  33. llvm::SmallPtrSet<const Decl *, 4> UsingTargetDecls;
  34. // The original UsingDecl.
  35. const UsingDecl *FoundUsingDecl;
  36. // The source range of the UsingDecl.
  37. CharSourceRange UsingDeclRange;
  38. // Whether the UsingDecl is used.
  39. bool IsUsed;
  40. };
  41. std::vector<UsingDeclContext> Contexts;
  42. const StringRef RawStringHeaderFileExtensions;
  43. utils::FileExtensionsSet HeaderFileExtensions;
  44. };
  45. } // namespace clang::tidy::misc
  46. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H