summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/docs/LibASTMatchersReference.html8
-rw-r--r--clang/include/clang/ASTMatchers/ASTMatchers.h11
-rw-r--r--clang/lib/ASTMatchers/Dynamic/Registry.cpp1
-rw-r--r--clang/unittests/ASTMatchers/ASTMatchersTest.cpp8
-rw-r--r--clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp6
5 files changed, 34 insertions, 0 deletions
diff --git a/clang/docs/LibASTMatchersReference.html b/clang/docs/LibASTMatchersReference.html
index 7f212620b18..51d30728e2c 100644
--- a/clang/docs/LibASTMatchersReference.html
+++ b/clang/docs/LibASTMatchersReference.html
@@ -1061,6 +1061,14 @@ NSString's "alloc". This matcher should match both message sends.
[[NSString alloc] initWithString:@"Hello"]
</pre></td></tr>
+<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('parenExpr0')"><a name="parenExpr0Anchor">parenExpr</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ParenExpr.html">ParenExpr</a>&gt;...</td></tr>
+<tr><td colspan="4" class="doc" id="parenExpr0"><pre>Matches parentheses used in expressions.
+
+Given
+ int foo() { return 1; }
+ int a = (foo() + 1);
+matches '(foo() + 1)'
+</pre></td></tr>
<tr><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1Stmt.html">Stmt</a>&gt;</td><td class="name" onclick="toggle('returnStmt0')"><a name="returnStmt0Anchor">returnStmt</a></td><td>Matcher&lt<a href="http://clang.llvm.org/doxygen/classclang_1_1ReturnStmt.html">ReturnStmt</a>&gt;...</td></tr>
<tr><td colspan="4" class="doc" id="returnStmt0"><pre>Matches return statements.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index f0d82275ba8..148a1e55213 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -1048,6 +1048,17 @@ const internal::VariadicDynCastAllOfMatcher<
Decl,
UnresolvedUsingTypenameDecl> unresolvedUsingTypenameDecl;
+/// \brief Matches parentheses used in expressions.
+///
+/// Example matches (foo() + 1)
+/// \code
+/// int foo() { return 1; }
+/// int a = (foo() + 1);
+/// \endcode
+const internal::VariadicDynCastAllOfMatcher<
+ Stmt,
+ ParenExpr> parenExpr;
+
/// \brief Matches constructor call expressions (including implicit ones).
///
/// Example matches string(ptr, n) and ptr within arguments of f
diff --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index e2c9a475691..9cfccdc2ab1 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -328,6 +328,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(on);
REGISTER_MATCHER(onImplicitObjectArgument);
REGISTER_MATCHER(parameterCountIs);
+ REGISTER_MATCHER(parenExpr);
REGISTER_MATCHER(parenType);
REGISTER_MATCHER(parmVarDecl);
REGISTER_MATCHER(pointee);
diff --git a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
index 1e5401d9bf3..d7f5b722df3 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -3667,6 +3667,14 @@ TEST(ExceptionHandling, SimpleCases) {
varDecl(isExceptionVariable())));
}
+TEST(ParenExpression, SimpleCases) {
+ EXPECT_TRUE(matches("int i = (3);", parenExpr()));
+ EXPECT_TRUE(matches("int i = (3 + 7);", parenExpr()));
+ EXPECT_TRUE(notMatches("int i = 3;", parenExpr()));
+ EXPECT_TRUE(notMatches("int foo() { return 1; }; int a = foo();",
+ parenExpr()));
+}
+
TEST(HasConditionVariableStatement, DoesNotMatchCondition) {
EXPECT_TRUE(notMatches(
"void x() { if(true) {} }",
diff --git a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
index 8e97566f692..a1b6a93456d 100644
--- a/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
+++ b/clang/unittests/ASTMatchers/Dynamic/RegistryTest.cpp
@@ -506,6 +506,12 @@ TEST_F(RegistryTest, HasArgs) {
EXPECT_FALSE(matches("struct X {};", Value));
}
+TEST_F(RegistryTest, ParenExpr) {
+ Matcher<Stmt> Value = constructMatcher("parenExpr").getTypedMatcher<Stmt>();
+ EXPECT_TRUE(matches("int i = (1);", Value));
+ EXPECT_FALSE(matches("int i = 1;", Value));
+}
+
} // end anonymous namespace
} // end namespace dynamic
} // end namespace ast_matchers
OpenPOWER on IntegriCloud