[libc][docgen] simplify posix links (#119595)
[llvm-project.git] / clang-tools-extra / clang-tidy / misc / ConfusableIdentifierCheck.h
blobf3b0c8ed0030670ec4d5aafa57b2ed7d4e8cb7e7
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 //===----------------------------------------------------------------------===//
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
13 #include "../ClangTidyCheck.h"
14 #include <unordered_map>
16 namespace clang::tidy::misc {
18 /// Finds symbol which have confusable identifiers, i.e. identifiers that look
19 /// the same visually but have a different Unicode representation.
20 /// If symbols are confusable but don't live in conflicting namespaces, they are
21 /// not reported.
22 class ConfusableIdentifierCheck : public ClangTidyCheck {
23 public:
24 ConfusableIdentifierCheck(StringRef Name, ClangTidyContext *Context);
25 ~ConfusableIdentifierCheck();
27 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
28 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
29 void onEndOfTranslationUnit() override;
30 std::optional<TraversalKind> getCheckTraversalKind() const override {
31 return TK_IgnoreUnlessSpelledInSource;
34 struct ContextInfo {
35 const DeclContext *PrimaryContext;
36 const DeclContext *NonTransparentContext;
37 llvm::SmallVector<const DeclContext *> PrimaryContexts;
38 llvm::SmallVector<const CXXRecordDecl *> Bases;
41 private:
42 struct Entry {
43 const NamedDecl *Declaration;
44 const ContextInfo *Info;
47 const ContextInfo *getContextInfo(const DeclContext *DC);
49 llvm::StringMap<llvm::SmallVector<Entry>> Mapper;
50 std::unordered_map<const DeclContext *, ContextInfo> ContextInfos;
53 } // namespace clang::tidy::misc
55 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H