Hi,
Indeed, there are matchers that are not currently implemented, although their implementation would be fairly trivial. Check out the documentation about writing AST matchers: http://clang.llvm.org/docs/LibASTMatchers.html
Sorry, you’re correct, argumentCountIs wrong here, I meant parameterCountIs(). By the way, the list of available matchers is listed here: http://clang.llvm.org/docs/LibASTMatchersReference.html - try looking through the list to find if what you need it available.
As for your further requirement that the constructor not be empty, I’m fairly sure that there is no such matcher readily available for you to use, but it shouldn’t be too difficult to implement one, all the information you need is in the documentation for CXXConstructorDecl: http://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html
I have put together quickly the matcher that I believe suits your needs, just so that you can see how it works:
namespace clang {
namespace ast_matchers {
using namespace clang::ast_matchers::internal;
AST_MATCHER(CXXConstructorDecl, defaultNonTrivialCtor)
{
return Node.isThisDeclarationADefinition()
&& Node.isDefaultConstructor()
&& (Node.getNumCtorInitializers() != 0 || !Node.hasTrivialBody());
}
} // ast_matchers
} // clang
(Don’t forget to include ASTMatchers.h, ASTMatchersInternal.h and ASTMatchersMacros.h)
Meanwhile I found that you can actually put this together using existing matchers, which should be the preferred method:
constructorDecl(isDefinition(), parameterCountIs(0),
anyOf(hasAnyConstructorInitializer(anything()), has(compoundStmt(has(stmt())))));
(I did a quick test, and seems to work as intended, but you should make sure to test it thoroughly yourself.)
The matcher you put together looks good, and those macros are there for you to use when implementing matchers.
You can, of course, use AST visitors (RecursiveASTVisitor) to find the node that satisfies these conditions, but usually matchers are preferred, as a higher-level and (usually) much less messy solution. However, in some situations AST Visitors are preferred - this is your choice to make, depending on your use case.
Don’t worry about matcher performance: if you’re using MatchFinder to run your matchers, then it is guaranteed that all matchers will be executed in just one traversal of the AST, i.e. two matchers won’t need two traversals.
Hope this helps,
Gabor