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")))));
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")))));
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to