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 10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H 11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H 12 13 #include "../ClangTidyCheck.h" 14 15 namespace clang { 16 namespace tidy { 17 namespace misc { 18 19 /// Finds symbol which have confusable identifiers, i.e. identifiers that look 20 /// the same visually but have a different Unicode representation. 21 /// If symbols are confusable but don't live in conflicting namespaces, they are 22 /// not reported. 23 class ConfusableIdentifierCheck : public ClangTidyCheck { 24 public: 25 ConfusableIdentifierCheck(StringRef Name, ClangTidyContext *Context); 26 ~ConfusableIdentifierCheck(); 27 28 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 29 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 30 31 private: 32 std::string skeleton(StringRef); 33 llvm::StringMap<llvm::SmallVector<const NamedDecl *>> Mapper; 34 }; 35 36 } // namespace misc 37 } // namespace tidy 38 } // namespace clang 39 40 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H 41