summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-move
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2017-01-04 14:50:49 +0000
committerHaojian Wu <hokein@google.com>2017-01-04 14:50:49 +0000
commitd69d90753c1f0611015be54d2a56ee5567d311f6 (patch)
tree0ef278596392985cca8c16bb4d4dbbdce83c6e61 /clang-tools-extra/clang-move
parentee5104bbab1eacc1887a963ec26816c208253c79 (diff)
downloadbcm5719-llvm-d69d90753c1f0611015be54d2a56ee5567d311f6.tar.gz
bcm5719-llvm-d69d90753c1f0611015be54d2a56ee5567d311f6.zip
[clang-move] Support moving type alias declarations.
Reviewers: ioeric Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D28279 llvm-svn: 290967
Diffstat (limited to 'clang-tools-extra/clang-move')
-rw-r--r--clang-tools-extra/clang-move/ClangMove.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/clang-tools-extra/clang-move/ClangMove.cpp b/clang-tools-extra/clang-move/ClangMove.cpp
index 06a76f23a72..155c46fdf5b 100644
--- a/clang-tools-extra/clang-move/ClangMove.cpp
+++ b/clang-tools-extra/clang-move/ClangMove.cpp
@@ -166,6 +166,27 @@ private:
ClangMoveTool *MoveTool;
};
+class TypeAliasMatch : public MatchFinder::MatchCallback {
+public:
+ explicit TypeAliasMatch(ClangMoveTool *MoveTool)
+ : MoveTool(MoveTool) {}
+
+ void run(const MatchFinder::MatchResult &Result) override {
+ if (const auto *TD = Result.Nodes.getNodeAs<clang::TypedefDecl>("typedef"))
+ MoveDeclFromOldFileToNewFile(MoveTool, TD);
+ else if (const auto *TAD =
+ Result.Nodes.getNodeAs<clang::TypeAliasDecl>("type_alias")) {
+ const NamedDecl * D = TAD;
+ if (const auto * TD = TAD->getDescribedAliasTemplate())
+ D = TD;
+ MoveDeclFromOldFileToNewFile(MoveTool, D);
+ }
+ }
+
+private:
+ ClangMoveTool *MoveTool;
+};
+
class EnumDeclarationMatch : public MatchFinder::MatchCallback {
public:
explicit EnumDeclarationMatch(ClangMoveTool *MoveTool)
@@ -587,13 +608,22 @@ void ClangMoveTool::registerMatchers(ast_matchers::MatchFinder *Finder) {
.bind("function"),
MatchCallbacks.back().get());
- // Match enum definition in old.h. Enum helpers (which are definied in old.cc)
+ // Match enum definition in old.h. Enum helpers (which are defined in old.cc)
// will not be moved for now no matter whether they are used or not.
MatchCallbacks.push_back(llvm::make_unique<EnumDeclarationMatch>(this));
Finder->addMatcher(
enumDecl(InOldHeader, *HasAnySymbolNames, isDefinition(), TopLevelDecl)
.bind("enum"),
MatchCallbacks.back().get());
+
+ // Match type alias in old.h, this includes "typedef" and "using" type alias
+ // declarations. Type alias helpers (which are defined in old.cc) will not be
+ // moved for now no matter whether they are used or not.
+ MatchCallbacks.push_back(llvm::make_unique<TypeAliasMatch>(this));
+ Finder->addMatcher(namedDecl(anyOf(typedefDecl().bind("typedef"),
+ typeAliasDecl().bind("type_alias")),
+ InOldHeader, *HasAnySymbolNames, TopLevelDecl),
+ MatchCallbacks.back().get());
}
void ClangMoveTool::run(const ast_matchers::MatchFinder::MatchResult &Result) {
@@ -828,6 +858,9 @@ void ClangMoveTool::onEndOfTranslationUnit() {
case Decl::Kind::ClassTemplate:
case Decl::Kind::CXXRecord:
case Decl::Kind::Enum:
+ case Decl::Kind::Typedef:
+ case Decl::Kind::TypeAlias:
+ case Decl::Kind::TypeAliasTemplate:
return true;
default:
return false;
OpenPOWER on IntegriCloud