[PATCH] Added isImplicit and isExplicit submatchers for constructorDecl.
Alexander Kornienko
alexfh at google.com
Thu Feb 13 01:34:27 PST 2014
Hi djasper, klimek,
http://llvm-reviews.chandlerc.com/D2761
Files:
include/clang/ASTMatchers/ASTMatchers.h
unittests/ASTMatchers/ASTMatchersTest.cpp
Index: include/clang/ASTMatchers/ASTMatchers.h
===================================================================
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2156,6 +2156,16 @@
return Node.isImplicit();
}
+/// \brief Matches an explicit constructor declaration.
+AST_MATCHER(CXXConstructorDecl, isExplicit) {
+ return Node.isExplicit();
+}
+
+/// \brief Matches an out-of-line constructor declaration.
+AST_MATCHER(CXXConstructorDecl, isOutOfLine) {
+ return Node.isOutOfLine();
+}
+
/// \brief Matches any argument of a call expression or a constructor call
/// expression.
///
Index: unittests/ASTMatchers/ASTMatchersTest.cpp
===================================================================
--- unittests/ASTMatchers/ASTMatchersTest.cpp
+++ unittests/ASTMatchers/ASTMatchersTest.cpp
@@ -1740,6 +1740,30 @@
constructorDecl(unless(isImplicit()))));
}
+TEST(ConstructorDeclaration, IsExplicit) {
+ EXPECT_TRUE(notMatches("class Foo { };",
+ constructorDecl(isExplicit())));
+ EXPECT_TRUE(notMatches("class Foo { }; Foo* f = new Foo();",
+ constructorDecl(isExplicit())));
+ EXPECT_TRUE(matches("class Foo { Foo() {} };",
+ constructorDecl(unless(isExplicit()))));
+ EXPECT_TRUE(matches("class Foo { Foo(int) {} };",
+ constructorDecl(unless(isExplicit()))));
+ EXPECT_TRUE(matches("class Foo { explicit Foo(int) {} };",
+ constructorDecl(isExplicit())));
+}
+
+TEST(ConstructorDeclaration, IsOutOfLine) {
+ EXPECT_TRUE(notMatches("class Foo { Foo(); };",
+ constructorDecl(isOutOfLine())));
+ EXPECT_TRUE(notMatches("class Foo { Foo() {} };",
+ constructorDecl(isOutOfLine())));
+ EXPECT_TRUE(matches("class Foo { Foo(); }; Foo::Foo() {}",
+ constructorDecl(isOutOfLine())));
+ EXPECT_TRUE(matches("class Foo { Foo() {} };",
+ constructorDecl(unless(isOutOfLine()))));
+}
+
TEST(DestructorDeclaration, MatchesVirtualDestructor) {
EXPECT_TRUE(matches("class Foo { virtual ~Foo(); };",
destructorDecl(ofClass(hasName("Foo")))));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2761.1.patch
Type: text/x-patch
Size: 2252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140213/2e0fdd7f/attachment.bin>
More information about the cfe-commits
mailing list