Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 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 | |
| 20 | namespace clang { |
| 21 | namespace tidy { |
| 22 | namespace utils { |
| 23 | |
| 24 | // This class creates function-level namespace aliases. |
| 25 | class NamespaceAliaser { |
| 26 | public: |
| 27 | explicit NamespaceAliaser(const SourceManager &SourceMgr); |
| 28 | // Adds a namespace alias for \p Namespace valid near \p |
| 29 | // Statement. Picks the first available name from \p Abbreviations. |
| 30 | // Returns ``llvm::None`` if an alias already exists or there is an error. |
| 31 | llvm::Optional<FixItHint> |
| 32 | createAlias(ASTContext &Context, const Stmt &Statement, |
| 33 | llvm::StringRef Namespace, |
| 34 | const std::vector<std::string> &Abbreviations); |
| 35 | |
| 36 | // Get an alias name for \p Namespace valid at \p Statement. Returns \p |
| 37 | // Namespace if there is no alias. |
| 38 | std::string getNamespaceName(ASTContext &Context, const Stmt &Statement, |
| 39 | llvm::StringRef Namespace) const; |
| 40 | |
| 41 | private: |
| 42 | const SourceManager &SourceMgr; |
| 43 | llvm::DenseMap<const FunctionDecl *, llvm::StringMap<std::string>> |
| 44 | AddedAliases; |
| 45 | }; |
| 46 | |
| 47 | } // namespace utils |
| 48 | } // namespace tidy |
| 49 | } // namespace clang |
| 50 | |
| 51 | #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H |