clang-tools
22.0.0git
llvm-project
clang-tools-extra
clang-tidy
modernize
ConcatNestedNamespacesCheck.h
Go to the documentation of this file.
1
//===----------------------------------------------------------------------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_CONCATNESTEDNAMESPACESCHECK_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_CONCATNESTEDNAMESPACESCHECK_H
11
12
#include "
../ClangTidyCheck.h
"
13
#include "llvm/ADT/SmallString.h"
14
#include "llvm/ADT/SmallVector.h"
15
16
namespace
clang::tidy::modernize
{
17
18
using
NamespaceName
= llvm::SmallString<40>;
19
20
class
NS
:
public
llvm::SmallVector<const NamespaceDecl *, 6> {
21
public
:
22
std::optional<SourceRange>
23
getCleanedNamespaceFrontRange
(
const
SourceManager &SM,
24
const
LangOptions &LangOpts)
const
;
25
SourceRange
getReplacedNamespaceFrontRange
()
const
;
26
SourceRange
getNamespaceBackRange
(
const
SourceManager &SM,
27
const
LangOptions &LangOpts)
const
;
28
SourceRange
getDefaultNamespaceBackRange
()
const
;
29
void
appendName
(
NamespaceName
&Str)
const
;
30
void
appendCloseComment
(
NamespaceName
&Str)
const
;
31
};
32
33
class
ConcatNestedNamespacesCheck
:
public
ClangTidyCheck
{
34
public
:
35
ConcatNestedNamespacesCheck
(StringRef Name,
ClangTidyContext
*Context)
36
:
ClangTidyCheck
(Name, Context) {}
37
bool
unsupportedNamespace
(
const
NamespaceDecl &ND,
bool
IsChild)
const
;
38
bool
singleNamedNamespaceChild
(
const
NamespaceDecl &ND)
const
;
39
bool
isLanguageVersionSupported
(
const
LangOptions &LangOpts)
const override
{
40
return
LangOpts.CPlusPlus17;
41
}
42
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
43
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
44
45
private
:
46
using
NamespaceContextVec = llvm::SmallVector<NS, 6>;
47
48
void
reportDiagnostic(
const
SourceManager &SM,
const
LangOptions &LangOpts);
49
NamespaceContextVec Namespaces;
50
};
51
}
// namespace clang::tidy::modernize
52
53
#endif
// LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_CONCATNESTEDNAMESPACESCHECK_H
ClangTidyCheck.h
ClangTidyCheck
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition
ClangTidyDiagnosticConsumer.h:70
clang::tidy::modernize::ConcatNestedNamespacesCheck::ConcatNestedNamespacesCheck
ConcatNestedNamespacesCheck(StringRef Name, ClangTidyContext *Context)
Definition
ConcatNestedNamespacesCheck.h:35
clang::tidy::modernize::ConcatNestedNamespacesCheck::singleNamedNamespaceChild
bool singleNamedNamespaceChild(const NamespaceDecl &ND) const
Definition
ConcatNestedNamespacesCheck.cpp:107
clang::tidy::modernize::ConcatNestedNamespacesCheck::unsupportedNamespace
bool unsupportedNamespace(const NamespaceDecl &ND, bool IsChild) const
Definition
ConcatNestedNamespacesCheck.cpp:95
clang::tidy::modernize::ConcatNestedNamespacesCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Definition
ConcatNestedNamespacesCheck.cpp:166
clang::tidy::modernize::ConcatNestedNamespacesCheck::isLanguageVersionSupported
bool isLanguageVersionSupported(const LangOptions &LangOpts) const override
Definition
ConcatNestedNamespacesCheck.h:39
clang::tidy::modernize::ConcatNestedNamespacesCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Definition
ConcatNestedNamespacesCheck.cpp:117
clang::tidy::modernize::NS
Definition
ConcatNestedNamespacesCheck.h:20
clang::tidy::modernize::NS::getDefaultNamespaceBackRange
SourceRange getDefaultNamespaceBackRange() const
Definition
ConcatNestedNamespacesCheck.cpp:53
clang::tidy::modernize::NS::appendName
void appendName(NamespaceName &Str) const
Definition
ConcatNestedNamespacesCheck.cpp:79
clang::tidy::modernize::NS::getReplacedNamespaceFrontRange
SourceRange getReplacedNamespaceFrontRange() const
Definition
ConcatNestedNamespacesCheck.cpp:49
clang::tidy::modernize::NS::getCleanedNamespaceFrontRange
std::optional< SourceRange > getCleanedNamespaceFrontRange(const SourceManager &SM, const LangOptions &LangOpts) const
Definition
ConcatNestedNamespacesCheck.cpp:33
clang::tidy::modernize::NS::getNamespaceBackRange
SourceRange getNamespaceBackRange(const SourceManager &SM, const LangOptions &LangOpts) const
Definition
ConcatNestedNamespacesCheck.cpp:56
clang::tidy::modernize::NS::appendCloseComment
void appendCloseComment(NamespaceName &Str) const
Definition
ConcatNestedNamespacesCheck.cpp:88
clang::tidy::modernize
Definition
AvoidBindCheck.cpp:29
clang::tidy::modernize::NamespaceName
llvm::SmallString< 40 > NamespaceName
Definition
ConcatNestedNamespacesCheck.h:18
Generated on
for clang-tools by
1.14.0