From: Manuel Klimek Date: Tue, 27 May 2014 07:45:18 +0000 (+0000) Subject: Allow hasBody on CXXForRangeStmt nodes and update the docs. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=30ab174eabf7af6ed7e00eaa3753c56d69e8f050;p=clang Allow hasBody on CXXForRangeStmt nodes and update the docs. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209647 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/docs/LibASTMatchersReference.html b/docs/LibASTMatchersReference.html index f701f11d15..3b862cd861 100644 --- a/docs/LibASTMatchersReference.html +++ b/docs/LibASTMatchersReference.html @@ -631,6 +631,15 @@ Example matches x() +Matcher<Stmt>exprWithCleanupsMatcher<ExprWithCleanups>... +
Matches expressions that introduce cleanups to be run at the end
+of the sub-expression's evaluation.
+
+Example matches std::string()
+  const std::string str = std::string();
+
+ + Matcher<Stmt>floatLiteralMatcher<FloatingLiteral>...
Matches float literals of all sizes encodings, e.g.
 1.0, 1.0f, 1.0L and 1e10.
@@ -1357,12 +1366,6 @@ Example matches f(0, 0) (matcher = callExpr(argumentCountIs(2)))
 
-Matcher<CXXConstructorDecl>isImplicit -
Matches a constructor declaration that has been implicitly added
-by the compiler (eg. implicit defaultcopy constructors).
-
- - Matcher<CXXCtorInitializer>isWritten
Matches a constructor initializer if it is explicitly written in
 code (as opposed to implicitly added by the compiler).
@@ -1605,6 +1608,12 @@ Decl has pointer identity in the AST.
 
+Matcher<Decl>isImplicit +
Matches a declaration that has been implicitly added
+by the compiler (eg. implicit defaultcopy constructors).
+
+ + Matcher<Decl>isPrivate
Matches private C++ declarations.
 
@@ -2393,6 +2402,19 @@ with withInitializer matching (1)
 
+Matcher<CXXForRangeStmt>hasBodyMatcher<Stmt> InnerMatcher +
Matches a 'for', 'while', or 'do while' statement that has
+a given body.
+
+Given
+  for (;;) {}
+hasBody(compoundStmt())
+  matches 'for (;;) {}'
+with compoundStmt()
+  matching '{}'
+
+ + Matcher<CXXForRangeStmt>hasLoopVariableMatcher<VarDecl> InnerMatcher
Matches the initialization statement of a for loop.
 
@@ -2403,6 +2425,16 @@ matches 'int x' in
 
+Matcher<CXXForRangeStmt>hasRangeInitMatcher<Expr> InnerMatcher +
Matches the range initialization statement of a for loop.
+
+Example:
+    forStmt(hasRangeInit(anything()))
+matches 'a' in
+    for (int x : a) { }
+
+ + Matcher<CXXMemberCallExpr>onImplicitObjectArgumentMatcher<Expr> InnerMatcher

 
diff --git a/include/clang/ASTMatchers/ASTMatchers.h b/include/clang/ASTMatchers/ASTMatchers.h
index 2bee8e61b8..30f0264aaf 100644
--- a/include/clang/ASTMatchers/ASTMatchers.h
+++ b/include/clang/ASTMatchers/ASTMatchers.h
@@ -2430,9 +2430,11 @@ AST_MATCHER_P(ArraySubscriptExpr, hasBase,
 ///   matches 'for (;;) {}'
 /// with compoundStmt()
 ///   matching '{}'
-AST_POLYMORPHIC_MATCHER_P(
-    hasBody, AST_POLYMORPHIC_SUPPORTED_TYPES_3(DoStmt, ForStmt, WhileStmt),
-    internal::Matcher, InnerMatcher) {
+AST_POLYMORPHIC_MATCHER_P(hasBody,
+                          AST_POLYMORPHIC_SUPPORTED_TYPES_4(DoStmt, ForStmt,
+                                                            WhileStmt,
+                                                            CXXForRangeStmt),
+                          internal::Matcher, InnerMatcher) {
   const Stmt *const Statement = Node.getBody();
   return (Statement != nullptr &&
           InnerMatcher.matches(*Statement, Finder, Builder));
diff --git a/unittests/ASTMatchers/ASTMatchersTest.cpp b/unittests/ASTMatchers/ASTMatchersTest.cpp
index 4b36467915..4ce56fd023 100644
--- a/unittests/ASTMatchers/ASTMatchersTest.cpp
+++ b/unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -2432,6 +2432,8 @@ TEST(HasBody, FindsBodyOfForWhileDoLoops) {
               whileStmt(hasBody(compoundStmt()))));
   EXPECT_TRUE(matches("void f() { do {} while(true); }",
               doStmt(hasBody(compoundStmt()))));
+  EXPECT_TRUE(matches("void f() { int p[2]; for (auto x : p) {} }",
+              forRangeStmt(hasBody(compoundStmt()))));
 }
 
 TEST(HasAnySubstatement, MatchesForTopLevelCompoundStatement) {
diff --git a/unittests/ASTMatchers/Dynamic/ParserTest.cpp b/unittests/ASTMatchers/Dynamic/ParserTest.cpp
index a4b493295e..4e3239ff5a 100644
--- a/unittests/ASTMatchers/Dynamic/ParserTest.cpp
+++ b/unittests/ASTMatchers/Dynamic/ParserTest.cpp
@@ -257,7 +257,7 @@ TEST(ParserTest, Errors) {
             "1:1: Matcher does not support binding.",
             ParseWithError("isArrow().bind(\"foo\")"));
   EXPECT_EQ("Input value has unresolved overloaded type: "
-            "Matcher",
+            "Matcher",
             ParseMatcherWithError("hasBody(stmt())"));
 }