summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2016-02-03 14:29:55 +0000
committerDaniel Jasper <djasper@google.com>2016-02-03 14:29:55 +0000
commit739ae643463efde42581c7286c2568fbb26d7c7b (patch)
tree59c4fbfdd97c6d8c7eeaa2045fb1898d863e3b9a
parent0826bf2211c1064d2aac48c401539c1e719dda81 (diff)
downloadbcm5719-llvm-739ae643463efde42581c7286c2568fbb26d7c7b.tar.gz
bcm5719-llvm-739ae643463efde42581c7286c2568fbb26d7c7b.zip
Provide match function to look over an entire TU again.
llvm-svn: 259648
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchFinder.h15
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp10
2 files changed, 24 insertions, 1 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchFinder.h b/clang/include/clang/ASTMatchers/ASTMatchFinder.h
index 92ec92c299c..042408859c9 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchFinder.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchFinder.h
@@ -241,6 +241,11 @@ match(MatcherT Matcher, const ast_type_traits::DynTypedNode &Node,
ASTContext &Context);
/// @}
+/// \brief Returns the results of matching \p Matcher on the translation unit of
+/// \p Context and collects the \c BoundNodes of all callback invocations.
+template <typename MatcherT>
+SmallVector<BoundNodes, 1> match(MatcherT Matcher, ASTContext &Context);
+
/// \brief Returns the first result of type \c NodeT bound to \p BoundTo.
///
/// Returns \c NULL if there is no match, or if the matching node cannot be
@@ -288,6 +293,16 @@ match(MatcherT Matcher, const NodeT &Node, ASTContext &Context) {
return match(Matcher, ast_type_traits::DynTypedNode::create(Node), Context);
}
+template <typename MatcherT>
+SmallVector<BoundNodes, 1>
+match(MatcherT Matcher, ASTContext &Context) {
+ internal::CollectMatchesCallback Callback;
+ MatchFinder Finder;
+ Finder.addMatcher(Matcher, &Callback);
+ Finder.matchAST(Context);
+ return std::move(Callback.Nodes);
+}
+
} // end namespace ast_matchers
} // end namespace clang
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index 8a58afcaa41..38582c88701 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -5050,6 +5050,15 @@ TEST(MatchFinder, InterceptsEndOfTranslationUnit) {
EXPECT_TRUE(VerifyCallback.Called);
}
+TEST(Matcher, matchOverEntireASTContext) {
+ std::unique_ptr<ASTUnit> AST =
+ clang::tooling::buildASTFromCode("struct { int *foo; };");
+ ASSERT_TRUE(AST.get());
+ auto PT = selectFirst<PointerType>(
+ "x", match(pointerType().bind("x"), AST->getASTContext()));
+ EXPECT_NE(nullptr, PT);
+}
+
TEST(EqualsBoundNodeMatcher, QualType) {
EXPECT_TRUE(matches(
"int i = 1;", varDecl(hasType(qualType().bind("type")),
@@ -5276,7 +5285,6 @@ TEST(ObjCMessageExprMatcher, SimpleExprs) {
objcMessageExpr(matchesSelector("uppercase*"),
argumentCountIs(0)
)));
-
}
} // end namespace ast_matchers
OpenPOWER on IntegriCloud