[cfe-dev] Running ASTMatcher over main file only

James Dennett james.dennett at gmail.com
Sat Oct 12 10:47:42 PDT 2013


On Fri, Oct 11, 2013 at 8:50 AM, Kirk Fertitta
<kirk at pacificmindworks.com> wrote:
> Is there a way to run a matcher directly on just the main source file only,
> as opposed to all of the includes? I know I can discriminate in my callback,
> but didn’t know if the “penalty” for traversing so much code was negligible
> or somehow avoidable.
>
> Any advice is much appreciated.

You don't have to traverse it all.  You can implement your own
TraverseDecl that (roughly) checks which file a Decl is in, returning
true early if it's not in a file of interest and calling the default
RecursiveASTVisitor::TraverseDecl otherwise.

-- James




More information about the cfe-dev mailing list