clang-tools
17.0.0git
llvm-project
clang-tools-extra
clang-tidy
misc
ConfusableIdentifierCheck.h
Go to the documentation of this file.
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
#include <unordered_map>
15
16
namespace
clang::tidy::misc
{
17
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
();
26
27
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
28
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
29
30
struct
ContextInfo
{
31
const
DeclContext *
PrimaryContext
;
32
const
DeclContext *
NonTransparentContext
;
33
llvm::SmallVector<const DeclContext *>
PrimaryContexts
;
34
llvm::SmallVector<const CXXRecordDecl *>
Bases
;
35
};
36
37
private
:
38
struct
Entry {
39
const
NamedDecl *Declaration;
40
const
ContextInfo
*
Info
;
41
};
42
43
const
ContextInfo *getContextInfo(
const
DeclContext *DC);
44
45
llvm::StringMap<llvm::SmallVector<Entry>> Mapper;
46
std::unordered_map<const DeclContext *, ContextInfo> ContextInfos;
47
};
48
49
}
// namespace clang::tidy::misc
50
51
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_CONFUSABLE_IDENTIFIER_CHECK_H
Info
FunctionInfo Info
Definition:
FunctionSizeCheck.cpp:119
Name
Token Name
Definition:
MacroToEnumCheck.cpp:87
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:53
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:69
clang::tidy::misc::ConfusableIdentifierCheck
Finds symbol which have confusable identifiers, i.e.
Definition:
ConfusableIdentifierCheck.h:22
clang::tidy::misc::ConfusableIdentifierCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
ClangTidyChecks that register ASTMatchers should do the actual work in here.
Definition:
ConfusableIdentifierCheck.cpp:173
clang::tidy::misc::ConfusableIdentifierCheck::~ConfusableIdentifierCheck
~ConfusableIdentifierCheck()
clang::tidy::misc::ConfusableIdentifierCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Override this to register AST matchers with Finder.
Definition:
ConfusableIdentifierCheck.cpp:197
clang::tidy::misc
Definition:
ConfusableIdentifierCheck.cpp:24
clang::tidy::misc::ConfusableIdentifierCheck::ContextInfo
Definition:
ConfusableIdentifierCheck.h:30
clang::tidy::misc::ConfusableIdentifierCheck::ContextInfo::PrimaryContexts
llvm::SmallVector< const DeclContext * > PrimaryContexts
Definition:
ConfusableIdentifierCheck.h:33
clang::tidy::misc::ConfusableIdentifierCheck::ContextInfo::NonTransparentContext
const DeclContext * NonTransparentContext
Definition:
ConfusableIdentifierCheck.h:32
clang::tidy::misc::ConfusableIdentifierCheck::ContextInfo::PrimaryContext
const DeclContext * PrimaryContext
Definition:
ConfusableIdentifierCheck.h:31
clang::tidy::misc::ConfusableIdentifierCheck::ContextInfo::Bases
llvm::SmallVector< const CXXRecordDecl * > Bases
Definition:
ConfusableIdentifierCheck.h:34
Generated on Fri Jun 9 2023 08:16:25 for clang-tools by
1.9.6