[cfe-commits] r169257 - in /cfe/trunk: include/clang/ASTMatchers/ASTMatchers.h unittests/ASTMatchers/ASTMatchersTest.cpp
Daniel Jasper
djasper at google.com
Tue Dec 4 03:54:27 PST 2012
Author: djasper
Date: Tue Dec 4 05:54:27 2012
New Revision: 169257
URL: http://llvm.org/viewvc/llvm-project?rev=169257&view=rev
Log:
Add parameterCountIs() matcher.
Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=169257&r1=169256&r2=169257&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Dec 4 05:54:27 2012
@@ -1974,6 +1974,19 @@
return false;
}
+/// \brief Matches \c FunctionDecls that have a specific parameter count.
+///
+/// Given
+/// \code
+/// void f(int i) {}
+/// void g(int i, int j) {}
+/// \endcode
+/// functionDecl(parameterCountIs(2))
+/// matches g(int i, int j) {}
+AST_MATCHER_P(FunctionDecl, parameterCountIs, unsigned, N) {
+ return Node.getNumParams() == N;
+}
+
/// \brief Matches the return type of a function declaration.
///
/// Given:
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=169257&r1=169256&r2=169257&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Tue Dec 4 05:54:27 2012
@@ -1238,6 +1238,14 @@
EXPECT_TRUE(notMatches("void x(int, int) { x(0, 0); }", Call1Arg));
}
+TEST(Matcher, ParameterCount) {
+ DeclarationMatcher Function1Arg = functionDecl(parameterCountIs(1));
+ EXPECT_TRUE(matches("void f(int i) {}", Function1Arg));
+ EXPECT_TRUE(matches("class X { void f(int i) {} };", Function1Arg));
+ EXPECT_TRUE(notMatches("void f() {}", Function1Arg));
+ EXPECT_TRUE(notMatches("void f(int i, int j, int k) {}", Function1Arg));
+}
+
TEST(Matcher, References) {
DeclarationMatcher ReferenceClassX = varDecl(
hasType(references(recordDecl(hasName("X")))));
More information about the cfe-commits
mailing list