blob: 2a41a8f63f981695e6b617fe40dc5fa416c82a2e [file] [log] [blame]
Daniel Jasper727fd1a2016-04-19 13:48:39 +00001//===--- UnusedUsingDeclsCheck.h - clang-tidy--------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
11#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
12
13#include "../ClangTidy.h"
Haojian Wu1cea6e52016-05-20 08:34:32 +000014#include "llvm/ADT/SmallPtrSet.h"
15#include <vector>
Daniel Jasper727fd1a2016-04-19 13:48:39 +000016
17namespace clang {
18namespace tidy {
19namespace misc {
20
21/// Finds unused using declarations.
22///
23/// For the user-facing documentation see:
24/// http://clang.llvm.org/extra/clang-tidy/checks/misc-unused-using-decls.html
25class UnusedUsingDeclsCheck : public ClangTidyCheck {
26public:
27 UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context)
28 : ClangTidyCheck(Name, Context) {}
29 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
30 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
31 void onEndOfTranslationUnit() override;
32
33private:
Haojian Wu769eb0d2016-05-09 13:37:12 +000034 void removeFromFoundDecls(const Decl *D);
35
Haojian Wu1cea6e52016-05-20 08:34:32 +000036 struct UsingDeclContext {
37 explicit UsingDeclContext(const UsingDecl *FoundUsingDecl)
38 : FoundUsingDecl(FoundUsingDecl), IsUsed(false) {}
Haojian Wud80c7c42016-06-03 08:05:11 +000039 // A set saves all UsingShadowDecls introduced by a UsingDecl. A UsingDecl
40 // can introduce multiple UsingShadowDecls in some cases (such as
41 // overloaded functions).
Haojian Wu1cea6e52016-05-20 08:34:32 +000042 llvm::SmallPtrSet<const Decl *, 4> UsingTargetDecls;
Haojian Wud80c7c42016-06-03 08:05:11 +000043 // The original UsingDecl.
Haojian Wu1cea6e52016-05-20 08:34:32 +000044 const UsingDecl *FoundUsingDecl;
Haojian Wud80c7c42016-06-03 08:05:11 +000045 // The source range of the UsingDecl.
Haojian Wu1cea6e52016-05-20 08:34:32 +000046 CharSourceRange UsingDeclRange;
Haojian Wud80c7c42016-06-03 08:05:11 +000047 // Whether the UsingDecl is used.
Haojian Wu1cea6e52016-05-20 08:34:32 +000048 bool IsUsed;
49 };
50
51 std::vector<UsingDeclContext> Contexts;
Daniel Jasper727fd1a2016-04-19 13:48:39 +000052};
53
54} // namespace misc
55} // namespace tidy
56} // namespace clang
57
58#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H