Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===---------- NamespaceAliaser.h - clang-tidy ---------------------------===//
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_NAMESPACEALIASER_H
0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
0011 
0012 #include "clang/AST/ASTContext.h"
0013 #include "clang/AST/Stmt.h"
0014 #include "clang/Basic/Diagnostic.h"
0015 #include "clang/Basic/SourceManager.h"
0016 #include "llvm/ADT/DenseMap.h"
0017 #include "llvm/ADT/StringMap.h"
0018 #include <map>
0019 #include <optional>
0020 
0021 namespace clang::tidy::utils {
0022 
0023 // This class creates function-level namespace aliases.
0024 class NamespaceAliaser {
0025 public:
0026   explicit NamespaceAliaser(const SourceManager &SourceMgr);
0027   // Adds a namespace alias for \p Namespace valid near \p
0028   // Statement. Picks the first available name from \p Abbreviations.
0029   // Returns ``std::nullopt`` if an alias already exists or there is an error.
0030   std::optional<FixItHint>
0031   createAlias(ASTContext &Context, const Stmt &Statement,
0032               llvm::StringRef Namespace,
0033               const std::vector<std::string> &Abbreviations);
0034 
0035   // Get an alias name for \p Namespace valid at \p Statement. Returns \p
0036   // Namespace if there is no alias.
0037   std::string getNamespaceName(ASTContext &Context, const Stmt &Statement,
0038                                llvm::StringRef Namespace) const;
0039 
0040 private:
0041   const SourceManager &SourceMgr;
0042   llvm::DenseMap<const FunctionDecl *, llvm::StringMap<std::string>>
0043       AddedAliases;
0044 };
0045 
0046 } // namespace clang::tidy::utils
0047 
0048 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H