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?
Aaron W. Hsu
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.
After some consideration on what you said about threading data through
to reach the visitor's constructor and changing to a different use of
newFrontendActionFactory, to use newASTConsumer instead of
createASTConsumer, I've been able to get things working correctly. Thank
you. The solution was to thread through the pointer to the integer
holding the count through an explicitly created frontendaction that
passed that pointer through to the consumer constructor when called,
which in turn passes that through to the visitor.
Aaron W. Hsu