r238016 - Adding new AST matcher: isConstexpr

Szabolcs Sipos szabolcs.sipos at ericsson.com
Fri May 22 04:35:50 PDT 2015


Author: eszasip
Date: Fri May 22 06:35:50 2015
New Revision: 238016

URL: http://llvm.org/viewvc/llvm-project?rev=238016&view=rev
Log:
Adding new AST matcher: isConstexpr

It matches constexpr variable and function declarations.

Modified:
    cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
    cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=238016&r1=238015&r2=238016&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Fri May 22 06:35:50 2015
@@ -2709,6 +2709,23 @@ AST_MATCHER(FunctionDecl, isDeleted) {
   return Node.isDeleted();
 }
 
+/// \brief Matches constexpr variable and function declarations.
+///
+/// Given:
+/// \code
+///   constexpr int foo = 42;
+///   constexpr int bar();
+/// \endcode
+/// varDecl(isConstexpr())
+///   matches the declaration of foo.
+/// functionDecl(isConstexpr())
+///   matches the declaration of bar.
+AST_POLYMORPHIC_MATCHER(isConstexpr,
+                        AST_POLYMORPHIC_SUPPORTED_TYPES(VarDecl,
+                                                        FunctionDecl)) {
+  return Node.isConstexpr();
+}
+
 /// \brief Matches the condition expression of an if statement, for loop,
 /// or conditional operator.
 ///

Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=238016&r1=238015&r2=238016&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Fri May 22 06:35:50 2015
@@ -1595,6 +1595,13 @@ TEST(IsDeleted, MatchesDeletedFunctionDe
                       functionDecl(hasName("Func"), isDeleted())));
 }
 
+TEST(isConstexpr, MatchesConstexprDeclarations) {
+  EXPECT_TRUE(matches("constexpr int foo = 42;",
+                      varDecl(hasName("foo"), isConstexpr())));
+  EXPECT_TRUE(matches("constexpr int bar();",
+                      functionDecl(hasName("bar"), isConstexpr())));
+}
+
 TEST(HasAnyParameter, DoesntMatchIfInnerMatcherDoesntMatch) {
   EXPECT_TRUE(notMatches("class Y {}; class X { void x(int) {} };",
       methodDecl(hasAnyParameter(hasType(recordDecl(hasName("X")))))));





More information about the cfe-commits mailing list