brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 986bf37 Raw
60 lines · c
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDUSINGDECLSCHECK_H10#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDUSINGDECLSCHECK_H11 12#include "../ClangTidyCheck.h"13#include "../utils/FileExtensionsUtils.h"14#include "llvm/ADT/SmallPtrSet.h"15#include <vector>16 17namespace clang::tidy::misc {18 19/// Finds unused using declarations.20///21/// For the user-facing documentation see:22/// https://clang.llvm.org/extra/clang-tidy/checks/misc/unused-using-decls.html23class UnusedUsingDeclsCheck : public ClangTidyCheck {24public:25  UnusedUsingDeclsCheck(StringRef Name, ClangTidyContext *Context);26  void registerMatchers(ast_matchers::MatchFinder *Finder) override;27  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;28  void onEndOfTranslationUnit() override;29  bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {30    return LangOpts.CPlusPlus;31  }32 33private:34  void removeFromFoundDecls(const Decl *D);35 36  struct UsingDeclContext {37    explicit UsingDeclContext(const UsingDecl *FoundUsingDecl)38        : FoundUsingDecl(FoundUsingDecl) {}39    // A set saves all UsingShadowDecls introduced by a UsingDecl. A UsingDecl40    // can introduce multiple UsingShadowDecls in some cases (such as41    // 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 = false;49  };50 51  std::vector<UsingDeclContext> Contexts;52  llvm::SmallPtrSet<const Decl *, 32> UsingTargetDeclsCache;53 54  FileExtensionsSet HeaderFileExtensions;55};56 57} // namespace clang::tidy::misc58 59#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_UNUSEDUSINGDECLSCHECK_H60