baloghadamsoftware created this revision.
baloghadamsoftware added a reviewer: klimek.
baloghadamsoftware added a subscriber: cfe-commits.
Herald added a subscriber: klimek.

A checker (will be uploaded after this patch) needs to check implicit casts. 
Existing generic matcher "has" ignores implicit casts and parenthesized 
expressions and no specific matcher for matching return value expression 
preexisted. The patch adds such a matcher (hasReturnValue) and also fixes 
hasAnyArgument which also ignored implicit casts and parenthesized expressions, 
but its documentation contained a FIXME the this should be removed once 
separate matchers for ignoring implicit casts and parenthesized expressions are 
ready. Since these checkers were already there the fix could be executed. Only 
one checker was affected which was also fixed (ignoreParenImpCasts added) and 
will be uploaded after this patch.

http://reviews.llvm.org/D17986

Files:
  include/clang/ASTMatchers/ASTMatchers.h

Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2843,18 +2843,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;
     }
@@ -4792,6 +4787,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,


Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2843,18 +2843,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;
     }
@@ -4792,6 +4787,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,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to