r244662 - Add an AST matcher to match member intializers of a CXXCtorInitializer.
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 11 13:42:00 PDT 2015
Author: aaronballman
Date: Tue Aug 11 15:42:00 2015
New Revision: 244662
URL: http://llvm.org/viewvc/llvm-project?rev=244662&view=rev
Log:
Add an AST matcher to match member intializers of a CXXCtorInitializer.
Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=244662&r1=244661&r2=244662&view=diff
==============================================================================
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Tue Aug 11 15:42:00 2015
@@ -1512,6 +1512,23 @@ constructorDecl(hasAnyConstructorInitial
</pre></td></tr>
+<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('isMemberInitializer0')"><a name="isMemberInitializer0Anchor">isMemberInitializer</a></td><td></td></tr>
+<tr><td colspan="4" class="doc" id="isMemberInitializer0"><pre>Matches a constructor initializer if it is initializing a direct member, as opposed to a base.
+
+Given
+ struct B {};
+ struct D : B {
+ int I;
+ D(int i) : I(i) {}
+ };
+ struct E : B {
+ E() : B() {}
+ };
+constructorDecl(hasAnyConstructorInitializer(isMemberInitializer()))
+ will match D(int), but not match E().
+</pre></td></tr>
+
+
<tr><td>Matcher<<a href="http://clang.llvm.org/doxygen/classclang_1_1CXXCtorInitializer.html">CXXCtorInitializer</a>></td><td class="name" onclick="toggle('isWritten0')"><a name="isWritten0Anchor">isWritten</a></td><td></td></tr>
<tr><td colspan="4" class="doc" id="isWritten0"><pre>Matches a constructor initializer if it is explicitly written in
code (as opposed to implicitly added by the compiler).
Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=244662&r1=244661&r2=244662&view=diff
==============================================================================
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Aug 11 15:42:00 2015
@@ -2652,6 +2652,26 @@ AST_MATCHER(CXXCtorInitializer, isBaseIn
return Node.isBaseInitializer();
}
+/// \brief Matches a constructor initializer if it is initializing a member, as
+/// opposed to a base.
+///
+/// Given
+/// \code
+/// struct B {};
+/// struct D : B {
+/// int I;
+/// D(int i) : I(i) {}
+/// };
+/// struct E : B {
+/// E() : B() {}
+/// };
+/// \endcode
+/// constructorDecl(hasAnyConstructorInitializer(isMemberInitializer()))
+/// will match D(int), but not match E().
+AST_MATCHER(CXXCtorInitializer, isMemberInitializer) {
+ return Node.isMemberInitializer();
+}
+
/// \brief Matches any argument of a call expression or a constructor call
/// expression.
///
Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=244662&r1=244661&r2=244662&view=diff
==============================================================================
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Tue Aug 11 15:42:00 2015
@@ -262,6 +262,7 @@ RegistryMaps::RegistryMaps() {
REGISTER_MATCHER(isIntegral);
REGISTER_MATCHER(isInTemplateInstantiation);
REGISTER_MATCHER(isListInitialization);
+ REGISTER_MATCHER(isMemberInitializer);
REGISTER_MATCHER(isMoveConstructor);
REGISTER_MATCHER(isOverride);
REGISTER_MATCHER(isPrivate);
Modified: cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp?rev=244662&r1=244661&r2=244662&view=diff
==============================================================================
--- cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp (original)
+++ cfe/trunk/unittests/ASTMatchers/ASTMatchersTest.cpp Tue Aug 11 15:42:00 2015
@@ -2097,6 +2097,12 @@ TEST(HasAnyConstructorInitializer, IsBas
EXPECT_TRUE(notMatches(Code, constructorDecl(allOf(
hasAnyConstructorInitializer(allOf(isBaseInitializer(), isWritten())),
hasName("D")))));
+ EXPECT_TRUE(matches(Code, constructorDecl(allOf(
+ hasAnyConstructorInitializer(allOf(isMemberInitializer(), isWritten())),
+ hasName("D")))));
+ EXPECT_TRUE(notMatches(Code, constructorDecl(allOf(
+ hasAnyConstructorInitializer(allOf(isMemberInitializer(), isWritten())),
+ hasName("E")))));
}
TEST(Matcher, NewExpression) {
More information about the cfe-commits
mailing list