Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--- ConcatNestedNamespacesCheck.h - clang-tidy--------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_CONCATNESTEDNAMESPACESCHECK_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_CONCATNESTEDNAMESPACESCHECK_H
0011 
0012 #include "../ClangTidyCheck.h"
0013 #include "llvm/ADT/SmallString.h"
0014 #include "llvm/ADT/SmallVector.h"
0015 
0016 namespace clang::tidy::modernize {
0017 
0018 using NamespaceName = llvm::SmallString<40>;
0019 
0020 class NS : public llvm::SmallVector<const NamespaceDecl *, 6> {
0021 public:
0022   std::optional<SourceRange>
0023   getCleanedNamespaceFrontRange(const SourceManager &SM,
0024                                 const LangOptions &LangOpts) const;
0025   SourceRange getReplacedNamespaceFrontRange() const;
0026   SourceRange getNamespaceBackRange(const SourceManager &SM,
0027                                     const LangOptions &LangOpts) const;
0028   SourceRange getDefaultNamespaceBackRange() const;
0029   void appendName(NamespaceName &Str) const;
0030   void appendCloseComment(NamespaceName &Str) const;
0031 };
0032 
0033 class ConcatNestedNamespacesCheck : public ClangTidyCheck {
0034 public:
0035   ConcatNestedNamespacesCheck(StringRef Name, ClangTidyContext *Context)
0036       : ClangTidyCheck(Name, Context) {}
0037   bool unsupportedNamespace(const NamespaceDecl &ND, bool IsChild) const;
0038   bool singleNamedNamespaceChild(const NamespaceDecl &ND) const;
0039   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
0040     return LangOpts.CPlusPlus17;
0041   }
0042   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
0043   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
0044 
0045 private:
0046   using NamespaceContextVec = llvm::SmallVector<NS, 6>;
0047 
0048   void reportDiagnostic(const SourceManager &SM, const LangOptions &LangOpts);
0049   NamespaceContextVec Namespaces;
0050 };
0051 } // namespace clang::tidy::modernize
0052 
0053 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_CONCATNESTEDNAMESPACESCHECK_H