[cfe-dev] RecursiveASTVisitor tutorial + counting nodes in AST?

James Dennett james.dennett at gmail.com
Wed Oct 1 10:54:25 PDT 2014

On Wed, Oct 1, 2014 at 10:05 AM, Aaron W. Hsu <arcfide at sacrideo.us> wrote:

> Dear Clang Dev:
> I've worked through the tutorial on using the RecursiveASTVisitor and
> it's working quite well. Things are making sense more or less. However,
> I've not quite understood the best way to get extra data back out of a
> visitor once you have traversed an AST. In this case, let's take the
> RecursiveASTVisitor tutorial code and modify it so that it counts the
> number of nodes in the AST for a file. How would I do this? I can store
> a count field in the visitor and use that, which works fine, but I don't
> know how to get access to the visitor after Tool.run() completes. What's
> the best way to do this?

Your visitor can hold a pointer/reference to whatever mutable state it
wishes to update.  You might need to wire that up through a few levels to
get it to the visitor's constructor.

-- James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141001/2cce3399/attachment.html>

More information about the cfe-dev mailing list