r259648 - Provide match function to look over an entire TU again.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 3 06:29:55 PST 2016
Author: djasper
Date: Wed Feb 3 08:29:55 2016
New Revision: 259648
URL: http://llvm.org/viewvc/llvm-project?rev=259648&view=rev
Log:
Provide match function to look over an entire TU again.
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h?rev=259648&r1=259647&r2=259648&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h Wed Feb 3 08:29:55 2016
@@ -241,6 +241,11 @@ match(MatcherT Matcher, const ast_type_t
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 &Nod
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
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=259648&r1=259647&r2=259648&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Wed Feb 3 08:29:55 2016
@@ -5050,6 +5050,15 @@ TEST(MatchFinder, InterceptsEndOfTransla
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
More information about the cfe-commits
mailing list