summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2016-10-17 08:33:59 +0000
committerHaojian Wu <hokein@google.com>2016-10-17 08:33:59 +0000
commitada286202e2ba878163787f31b26d952de30797a (patch)
tree0fb0d3c2c07c913300b6277652c315a4a65f8ac9 /clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h
parent73fc15a9891f59ce46f65e19f2b89b589c154b20 (diff)
downloadbcm5719-llvm-ada286202e2ba878163787f31b26d952de30797a.tar.gz
bcm5719-llvm-ada286202e2ba878163787f31b26d952de30797a.zip
Recommit "[ClangTidy] Add UsingInserter and NamespaceAliaser"
Summary: This adds helper classes to add using declaractions and namespace aliases to function bodies. These help making function calls to deeply nested functions concise (e.g. when calling helpers in a refactoring) Patch by Julian Bangert! Reviewers: alexfh, hokein Subscribers: beanz, mgorny, cfe-commits Differential Revision: https://reviews.llvm.org/D24997 llvm-svn: 284368
Diffstat (limited to 'clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h')
-rw-r--r--clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h
new file mode 100644
index 00000000000..e56d69d3d79
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/utils/NamespaceAliaser.h
@@ -0,0 +1,52 @@
+//===---------- NamespaceAliaser.h - clang-tidy ---------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Stmt.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceManager.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/StringMap.h"
+#include <map>
+
+namespace clang {
+namespace tidy {
+namespace utils {
+
+// This class creates function-level namespace aliases.
+class NamespaceAliaser {
+public:
+ explicit NamespaceAliaser(const SourceManager &SourceMgr);
+ // Adds a namespace alias for \p Namespace valid near \p
+ // Statement. Picks the first available name from \p Abbreviations.
+ // Returns ``llvm::None`` if an alias already exists or there is an error.
+ llvm::Optional<FixItHint>
+ createAlias(ASTContext &Context, const Stmt &Statement,
+ llvm::StringRef Namespace,
+ const std::vector<std::string> &Abbreviations);
+
+ // Get an alias name for \p Namespace valid at \p Statement. Returns \p
+ // Namespace if there is no alias.
+ std::string getNamespaceName(ASTContext &Context, const Stmt &Statement,
+ llvm::StringRef Namespace) const;
+
+private:
+ const SourceManager &SourceMgr;
+ llvm::DenseMap<const FunctionDecl *, llvm::StringMap<std::string>>
+ AddedAliases;
+};
+
+} // namespace utils
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_NAMESPACEALIASER_H
OpenPOWER on IntegriCloud