[cfe-dev] How to write a matcher?

Richard legalize at xmission.com
Tue Mar 11 09:42:42 PDT 2014


In article <lfmm58$e8i$1 at ger.gmane.org>,
    Stephen Kelly <steveire at gmail.com> writes:

> I want to write a tool to remove c_str() calls in lines like
> 
>  std::cout << s.c_str();

I would start with remove-cstr-calls which already gives you an
example of how to write a refactoring tool that matches c_str calls.

Have you looked at that?

You may also find this work in progress I wrote helpful:
<https://github.com/LegalizeAdulthood/remove-void-args>

> There isn't really enough information about what matchers mean, and how to 
> use them. 

Yes, they could use some improved documentation.  All we really have
right now is the AST matchers reference page.

> How does one *actually* go about doing it?

That is the focus of the presentation I'm preparing for C++ Now! 2014.
I wrote the remove-void-args tool based on the remove-cstr-calls.  In
my experiments I never needed to actually run through the parsing and
AST matching code in the debugger, but I did make extensive use of
clang to dump the AST.

I didn't know about clang-query at the time, so I haven't updated the
tutorial to reflect this.

I'm also working on a patch to update the packaging to include
additional files in the package to make things available to
refactoring tool authors like clang-query and FileCheck.
-- 
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
     The Computer Graphics Museum <http://ComputerGraphicsMuseum.org>
         The Terminals Wiki <http://terminals.classiccmp.org>
  Legalize Adulthood! (my blog) <http://LegalizeAdulthood.wordpress.com>



More information about the cfe-dev mailing list