在使用 Clang LibTooling 的 RecursiveASTVisitor 时,如何告诉库中止对当前访问的 AST 节点下的子树的扫描?
RecursiveASTVisitor 在 AST 上使用深度优先遍历,很容易中止某些子树并继续遍历。
例如(请阅读代码中的注释):
virtual bool VisitCXXRecordDecl(CXXRecordDecl *decl) {
//some code to tell the lib not to traverse the subtree
//under the currently visited node i.e. decl
//but still continue the traversal
//so that the scan process will skip all AST nodes under any
//CXXRecordDecl in the AST
}
我认为从 Visit*** 方法返回 false 会达到这个目标,但它确实告诉 lib 一起结束遍历,而不是跳过子树。
由于目标只是标题中描述的目标,因此不考虑 ASTMatchers。