clang-tools 6.0.0

UnusedUsingDeclsCheck.h
Go to the documentation of this file.
1 //===--- 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"
14 #include "llvm/ADT/SmallPtrSet.h"
15 #include <vector>
16
17 namespace clang {
18 namespace tidy {
19 namespace 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
25 class UnusedUsingDeclsCheck : public ClangTidyCheck {
26 public:
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
33 private:
34 void removeFromFoundDecls(const Decl *D);
35
36 struct UsingDeclContext {
37 explicit UsingDeclContext(const UsingDecl *FoundUsingDecl)
38 : FoundUsingDecl(FoundUsingDecl), IsUsed(false) {}
39 // A set saves all UsingShadowDecls introduced by a UsingDecl. A UsingDecl
40 // can introduce multiple UsingShadowDecls in some cases (such as
41 // overloaded functions).
42 llvm::SmallPtrSet<const Decl *, 4> UsingTargetDecls;
43 // The original UsingDecl.
44 const UsingDecl *FoundUsingDecl;
45 // The source range of the UsingDecl.
46 CharSourceRange UsingDeclRange;
47 // Whether the UsingDecl is used.
48 bool IsUsed;
49 };
50
51 std::vector<UsingDeclContext> Contexts;
52 };
53
54 } // namespace misc
55 } // namespace tidy
56 } // namespace clang
57
58 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
Name
StringHandle Name
Definition: PreprocessorTracker.cpp:525
clang::tidy::misc::UnusedUsingDeclsCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition: UnusedUsingDeclsCheck.cpp:31
clang::tidy::misc::UnusedUsingDeclsCheck::UnusedUsingDeclsCheck
UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context)
Definition: UnusedUsingDeclsCheck.h:27
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidy.h:127
clang::tidy::misc::UnusedUsingDeclsCheck::onEndOfTranslationUnit
void onEndOfTranslationUnit() override
Definition: UnusedUsingDeclsCheck.cpp:154
clang::tidy::misc::UnusedUsingDeclsCheck
Finds unused using declarations.
Definition: UnusedUsingDeclsCheck.h:25
clang::tidy::misc::UnusedUsingDeclsCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition: UnusedUsingDeclsCheck.cpp:50
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:104