[cfe-commits] Patch: AST Matcher Framwork and an example tool

Nico Weber thakis at chromium.org
Tue May 24 08:59:33 PDT 2011

Hi Manuel,

this looks pretty cool.

However, as far as I understand, MatchFinder can only be used in stand-alone
tools using the Tooling infrastructure, because the public api is mostly
limited to NewFrontendActionFactory(). Do you think it's possible to somehow
make MatchASTConsumer public as well (maybe just give MatchFinder a
NewASTCosumer() function), so that the DSL can be used in places were
ASTConsumers are needed (such as in the "normal" rewriter infrastructure)? I
only skimmed the patch, so sorry if that's a superficial question.


On Mon, May 23, 2011 at 3:03 PM, Manuel Klimek <klimek at google.com> wrote:

> This patch implements an AST matching framework that allows to write tools
> that match on the C++ ASTs. The main interface is in ASTMatchers.h, an
> example implementation of a tool that removes redundant .c_str() calls is in
> the example RemoveCStrCalls.cpp (patch to llvm/clang produced by running
> this tool will be sent out shortly in an extra email).
> Currently we have an in-language DSL that allows to write expressions such
> as (taken from the .c_str() example):
> ConstructorCall( HasDeclaration(Method(HasName(StringConstructor))), ArgumentCountIs(2),
> // The first argument must have the form x.c_str() or p->c_str() // where
> the method is string::c_str(). We can use the copy // constructor of
> string instead (or the compiler might share // the string object). HasArgument(
> 0, Id("call", Call( Callee(Id("member", MemberExpression())), Callee(Method(HasName(StringCStrMethod))),
> On(Id("arg", Expression()))))), // The second argument is the alloc object
> which must not be // present explicitly. HasArgument( 1,
> DefaultArgument()))
> The next steps will be to build up better support for in-process
> refactorings based on the Rewriter, to build up higher-level matchers for
> common patterns, and to extend the low-level matcher library.
> (rietveld link: http://codereview.appspot.com/4552059/)
> Cheers,
> /Manuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110524/cd25c1de/attachment.html>

More information about the cfe-commits mailing list