'how do I prune a visitation of a subtree in Clang when using RecursiveASTVisitor?
In Clang I am using RecursiveASTVisitor to visit the AST nodes of a C++ translation unit. This is basically working, but now I want to visit AST nodes that are instantiated from function and class templates.
I understand that if I want to visit the template instantiations I should have my visitor define shouldVisitTemplateInstantiations() to return true; this seems to be working. However visiting the template patterns themselves is a huge distraction, as I just want the instantiated code.
How do I not visit the template patterns, or if I must, how do I prune the traversal of the subtree when I end up in one (such as when I end up in a FunctionTemplateDecl)?
The comment at RecursiveASTVisitor says:
/// Most users only need to override Visit*. Advanced
/// users may override Traverse* and WalkUpFrom* to implement custom
/// traversal strategies. Returning false from one of these overridden
/// functions will abort the entire traversal.
I am intercepting the visitation at VisitDecl(). It seems that returning false from VisitDecl() is not the thing to do, as I do not want to "abort the entire traversal", just the traversal of the subtree that I am on, namely the template (pattern) body. Trying that now, it really does seem to abort the whole traversal.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
