summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2012-12-04 11:54:27 +0000
committerDaniel Jasper <djasper@google.com>2012-12-04 11:54:27 +0000
commit9f501295bdfdd28ca9c3dd811c693b442af6d3b1 (patch)
treeb7ad7173f9bb522a114975d1bb200a168c535e16
parent64bc1ab3498634a1f8d82529d759eebd2901a571 (diff)
downloadbcm5719-llvm-9f501295bdfdd28ca9c3dd811c693b442af6d3b1.tar.gz
bcm5719-llvm-9f501295bdfdd28ca9c3dd811c693b442af6d3b1.zip
Add parameterCountIs() matcher.
llvm-svn: 169257
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h13
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp8
2 files changed, 21 insertions, 0 deletions
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index a70dd5c378b..71ce10f8932 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1974,6 +1974,19 @@ AST_MATCHER_P(FunctionDecl, hasAnyParameter,
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:
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index ad072aa7ce3..f3d377b771f 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -1238,6 +1238,14 @@ TEST(Matcher, ArgumentCount) {
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")))));
OpenPOWER on IntegriCloud