clang-tools 6.0.0

NamespaceAliaser.h
Go to the documentation of this file.
1 //===---------- NamespaceAliaser.h - clang-tidy ---------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
11 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
12
13 #include "clang/AST/ASTContext.h"
14 #include "clang/AST/Stmt.h"
15 #include "clang/Basic/Diagnostic.h"
16 #include "clang/Basic/SourceManager.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/StringMap.h"
19 #include <map>
20
21 namespace clang {
22 namespace tidy {
23 namespace utils {
24
25 // This class creates function-level namespace aliases.
26 class NamespaceAliaser {
27 public:
28 explicit NamespaceAliaser(const SourceManager &SourceMgr);
29 // Adds a namespace alias for \p Namespace valid near \p
30 // Statement. Picks the first available name from \p Abbreviations.
31 // Returns ``llvm::None`` if an alias already exists or there is an error.
32 llvm::Optional<FixItHint>
33 createAlias(ASTContext &Context, const Stmt &Statement,
34 llvm::StringRef Namespace,
35 const std::vector<std::string> &Abbreviations);
36
37 // Get an alias name for \p Namespace valid at \p Statement. Returns \p
38 // Namespace if there is no alias.
39 std::string getNamespaceName(ASTContext &Context, const Stmt &Statement,
40 llvm::StringRef Namespace) const;
41
42 private:
43 const SourceManager &SourceMgr;
44 llvm::DenseMap<const FunctionDecl *, llvm::StringMap<std::string>>
45 AddedAliases;
46 };
47
48 } // namespace utils
49 } // namespace tidy
50 } // namespace clang
51
52 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
clang::tidy::utils::NamespaceAliaser::NamespaceAliaser
NamespaceAliaser(const SourceManager &SourceMgr)
Definition: NamespaceAliaser.cpp:22
clang::tidy::utils::NamespaceAliaser::getNamespaceName
std::string getNamespaceName(ASTContext &Context, const Stmt &Statement, llvm::StringRef Namespace) const
Definition: NamespaceAliaser.cpp:82
clang
Definition: AndroidTidyModule.cpp:28
clang::tidy::utils::NamespaceAliaser
Definition: NamespaceAliaser.h:26
clang::tidy::utils::NamespaceAliaser::createAlias
llvm::Optional< FixItHint > createAlias(ASTContext &Context, const Stmt &Statement, llvm::StringRef Namespace, const std::vector< std::string > &Abbreviations)
Definition: NamespaceAliaser.cpp:31