Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:36:20

0001 //===--- ConfusableIdentifierCheck.h - clang-tidy
0002 //-------------------------------*- C++ -*-===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H
0011 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H
0012 
0013 #include "../ClangTidyCheck.h"
0014 #include <unordered_map>
0015 
0016 namespace clang::tidy::misc {
0017 
0018 /// Finds symbol which have confusable identifiers, i.e. identifiers that look
0019 /// the same visually but have a different Unicode representation.
0020 /// If symbols are confusable but don't live in conflicting namespaces, they are
0021 /// not reported.
0022 class ConfusableIdentifierCheck : public ClangTidyCheck {
0023 public:
0024   ConfusableIdentifierCheck(StringRef Name, ClangTidyContext *Context);
0025   ~ConfusableIdentifierCheck();
0026 
0027   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0028   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0029   void onEndOfTranslationUnit() override;
0030   std::optional<TraversalKind> getCheckTraversalKind() const override {
0031     return TK_IgnoreUnlessSpelledInSource;
0032   }
0033 
0034   struct ContextInfo {
0035     const DeclContext *PrimaryContext;
0036     const DeclContext *NonTransparentContext;
0037     llvm::SmallVector<const DeclContext *> PrimaryContexts;
0038     llvm::SmallVector<const CXXRecordDecl *> Bases;
0039   };
0040 
0041 private:
0042   struct Entry {
0043     const NamedDecl *Declaration;
0044     const ContextInfo *Info;
0045   };
0046 
0047   const ContextInfo *getContextInfo(const DeclContext *DC);
0048 
0049   llvm::StringMap<llvm::SmallVector<Entry>> Mapper;
0050   std::unordered_map<const DeclContext *, ContextInfo> ContextInfos;
0051 };
0052 
0053 } // namespace clang::tidy::misc
0054 
0055 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H