[PATCH] D17986: [ASTMatchers] New matcher hasReturnValue added
Balogh, Ádám via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 17 07:32:20 PDT 2016
baloghadamsoftware retitled this revision from "[ASTMatchers] Existing matcher hasAnyArgument fixed and new matcher hasReturnValue added" to "[ASTMatchers] New matcher hasReturnValue added".
baloghadamsoftware updated the summary for this revision.
baloghadamsoftware updated this revision to Diff 50931.
baloghadamsoftware added a comment.
Separation of new matcher and fix for existing matcher. This patch only contains the new matcher. Test added and matcher added to the registry.
http://reviews.llvm.org/D17986
Files:
include/clang/ASTMatchers/ASTMatchers.h
lib/ASTMatchers/Dynamic/Registry.cpp
unittests/ASTMatchers/ASTMatchersTest.cpp
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -5385,5 +5385,11 @@
EXPECT_TRUE(notMatches("int i = 0;", expr(nullPointerConstant())));
}
+TEST(StatementMatcher, HasReturnValue) {
+ StatementMatcher RetVal = returnStmt(hasReturnValue(binaryOperator()));
+ EXPECT_TRUE(matches("int F() { return a+b; }", RetVal));
+ EXPECT_FALSE(matches("int F() { return a; }", RetVal));
+}
+
} // end namespace ast_matchers
} // end namespace clang
Index: lib/ASTMatchers/Dynamic/Registry.cpp
===================================================================
--- lib/ASTMatchers/Dynamic/Registry.cpp
+++ lib/ASTMatchers/Dynamic/Registry.cpp
@@ -238,6 +238,7 @@
REGISTER_MATCHER(hasQualifier);
REGISTER_MATCHER(hasRangeInit);
REGISTER_MATCHER(hasReceiverType);
+ REGISTER_MATCHER(hasReturnValue);
REGISTER_MATCHER(hasRHS);
REGISTER_MATCHER(hasSelector);
REGISTER_MATCHER(hasSingleDecl);
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2859,18 +2859,13 @@
/// matches x(1, y, 42)
/// with hasAnyArgument(...)
/// matching y
-///
-/// FIXME: Currently this will ignore parentheses and implicit casts on
-/// the argument before applying the inner matcher. We'll want to remove
-/// this to allow for greater control by the user once \c ignoreImplicit()
-/// has been implemented.
AST_POLYMORPHIC_MATCHER_P(hasAnyArgument,
AST_POLYMORPHIC_SUPPORTED_TYPES(CallExpr,
CXXConstructExpr),
internal::Matcher<Expr>, InnerMatcher) {
for (const Expr *Arg : Node.arguments()) {
BoundNodesTreeBuilder Result(*Builder);
- if (InnerMatcher.matches(*Arg->IgnoreParenImpCasts(), Finder, &Result)) {
+ if (InnerMatcher.matches(*Arg, Finder, &Result)) {
*Builder = std::move(Result);
return true;
}
@@ -4841,6 +4836,26 @@
return false;
}
+/// \brief Matches the return value expression of a return statement
+///
+/// Given
+/// \code
+/// return a+b;
+/// \endcode
+/// hasReturnValue(binaryOperator())
+/// matches 'return a+b'
+/// with binaryOperator()
+/// matching 'a+b'
+AST_MATCHER_P(ReturnStmt, hasReturnValue, internal::Matcher<Expr>, InnerMatcher) {
+ BoundNodesTreeBuilder Result(*Builder);
+ if(InnerMatcher.matches(*Node.getRetValue(), Finder, &Result)) {
+ *Builder = std::move(Result);
+ return true;
+ }
+ return false;
+}
+
+
/// \brief Matches CUDA kernel call expression.
///
/// Example matches,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17986.50931.patch
Type: text/x-patch
Size: 2814 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160317/c118ae18/attachment-0001.bin>
More information about the cfe-commits
mailing list