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

Manuel Klimek klimek at google.com
Mon May 23 15:03:03 PDT 2011

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))),
// 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())),
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/)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110523/c3bdb52e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ast-matchers.patch
Type: text/x-patch
Size: 244373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110523/c3bdb52e/attachment.bin>

More information about the cfe-commits mailing list