2016-04-19 21:48:39 +08:00
|
|
|
//===--- UnusedUsingDeclsCheck.h - clang-tidy--------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
|
|
|
|
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
|
|
|
|
|
|
|
|
#include "../ClangTidy.h"
|
2016-05-20 16:34:32 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
|
|
|
#include <vector>
|
2016-04-19 21:48:39 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace tidy {
|
|
|
|
namespace misc {
|
|
|
|
|
|
|
|
/// Finds unused using declarations.
|
|
|
|
///
|
|
|
|
/// For the user-facing documentation see:
|
|
|
|
/// http://clang.llvm.org/extra/clang-tidy/checks/misc-unused-using-decls.html
|
|
|
|
class UnusedUsingDeclsCheck : public ClangTidyCheck {
|
|
|
|
public:
|
|
|
|
UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context)
|
|
|
|
: ClangTidyCheck(Name, Context) {}
|
|
|
|
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
|
|
|
|
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
|
|
|
|
void onEndOfTranslationUnit() override;
|
|
|
|
|
|
|
|
private:
|
2016-05-09 21:37:12 +08:00
|
|
|
void removeFromFoundDecls(const Decl *D);
|
|
|
|
|
2016-05-20 16:34:32 +08:00
|
|
|
struct UsingDeclContext {
|
|
|
|
explicit UsingDeclContext(const UsingDecl *FoundUsingDecl)
|
|
|
|
: FoundUsingDecl(FoundUsingDecl), IsUsed(false) {}
|
2016-06-03 16:05:11 +08:00
|
|
|
// A set saves all UsingShadowDecls introduced by a UsingDecl. A UsingDecl
|
|
|
|
// can introduce multiple UsingShadowDecls in some cases (such as
|
|
|
|
// overloaded functions).
|
2016-05-20 16:34:32 +08:00
|
|
|
llvm::SmallPtrSet<const Decl *, 4> UsingTargetDecls;
|
2016-06-03 16:05:11 +08:00
|
|
|
// The original UsingDecl.
|
2016-05-20 16:34:32 +08:00
|
|
|
const UsingDecl *FoundUsingDecl;
|
2016-06-03 16:05:11 +08:00
|
|
|
// The source range of the UsingDecl.
|
2016-05-20 16:34:32 +08:00
|
|
|
CharSourceRange UsingDeclRange;
|
2016-06-03 16:05:11 +08:00
|
|
|
// Whether the UsingDecl is used.
|
2016-05-20 16:34:32 +08:00
|
|
|
bool IsUsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<UsingDeclContext> Contexts;
|
2016-04-19 21:48:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace misc
|
|
|
|
} // namespace tidy
|
|
|
|
} // namespace clang
|
|
|
|
|
|
|
|
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSED_USING_DECLS_H
|