clang-tools  17.0.0git
NamespaceAliaser.h
Go to the documentation of this file.
1 //===---------- NamespaceAliaser.h - clang-tidy ---------------------------===//
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_NAMESPACEALIASER_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
11 
12 #include "clang/AST/ASTContext.h"
13 #include "clang/AST/Stmt.h"
14 #include "clang/Basic/Diagnostic.h"
15 #include "clang/Basic/SourceManager.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/StringMap.h"
18 #include <map>
19 #include <optional>
20 
21 namespace clang::tidy::utils {
22 
23 // This class creates function-level namespace aliases.
25 public:
26  explicit NamespaceAliaser(const SourceManager &SourceMgr);
27  // Adds a namespace alias for \p Namespace valid near \p
28  // Statement. Picks the first available name from \p Abbreviations.
29  // Returns ``std::nullopt`` if an alias already exists or there is an error.
30  std::optional<FixItHint>
31  createAlias(ASTContext &Context, const Stmt &Statement,
32  llvm::StringRef Namespace,
33  const std::vector<std::string> &Abbreviations);
34 
35  // Get an alias name for \p Namespace valid at \p Statement. Returns \p
36  // Namespace if there is no alias.
37  std::string getNamespaceName(ASTContext &Context, const Stmt &Statement,
38  llvm::StringRef Namespace) const;
39 
40 private:
41  const SourceManager &SourceMgr;
42  llvm::DenseMap<const FunctionDecl *, llvm::StringMap<std::string>>
43  AddedAliases;
44 };
45 
46 } // namespace clang::tidy::utils
47 
48 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
clang::tidy::utils::NamespaceAliaser::NamespaceAliaser
NamespaceAliaser(const SourceManager &SourceMgr)
Definition: NamespaceAliaser.cpp:20
clang::tidy::utils::NamespaceAliaser::createAlias
std::optional< FixItHint > createAlias(ASTContext &Context, const Stmt &Statement, llvm::StringRef Namespace, const std::vector< std::string > &Abbreviations)
Definition: NamespaceAliaser.cpp:29
clang::tidy::utils::NamespaceAliaser::getNamespaceName
std::string getNamespaceName(ASTContext &Context, const Stmt &Statement, llvm::StringRef Namespace) const
Definition: NamespaceAliaser.cpp:80
clang::tidy::utils::NamespaceAliaser
Definition: NamespaceAliaser.h:24
clang::tidy::utils
Definition: Aliasing.cpp:14