ConfusableIdentifierCheck.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //===--- ConfusableIdentifierCheck.h - clang-tidy
  2. //-------------------------------*- C++ -*-===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H
  10. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H
  11. #include "../ClangTidyCheck.h"
  12. namespace clang::tidy::misc {
  13. /// Finds symbol which have confusable identifiers, i.e. identifiers that look
  14. /// the same visually but have a different Unicode representation.
  15. /// If symbols are confusable but don't live in conflicting namespaces, they are
  16. /// not reported.
  17. class ConfusableIdentifierCheck : public ClangTidyCheck {
  18. public:
  19. ConfusableIdentifierCheck(StringRef Name, ClangTidyContext *Context);
  20. ~ConfusableIdentifierCheck();
  21. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  22. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  23. private:
  24. std::string skeleton(StringRef);
  25. llvm::StringMap<llvm::SmallVector<const NamedDecl *>> Mapper;
  26. };
  27. } // namespace clang::tidy::misc
  28. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H