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