gpt4 book ai didi

clang - Clang AST 节点何时会有多个父节点?

转载 作者:行者123 更新时间:2023-12-04 10:34:19 30 4
gpt4 key购买 nike

类 clang::ASTContext 有一个方法:

DynTypedNodeList getParents(const NodeT &Node)

它返回给定 AST 节点的父节点列表。

通常 AST 作为树将是树结构,但出于某些原因(也许是性能原因)Clang 允许一个节点有多个父节点。

在什么情况下(什么 C++ 源代码模式), getParents() 会返回多个父级?

最佳答案

原答案(错误)

AST 是一棵树,每个节点都有一个父节点。 getParents但是,不仅返回父级,还返回父级的父级等等。因此,实际上,该函数应该更好地命名为 getAncestors .

更新答案

原来的答案确实不正确和getParents对于绝大多数 AST 节点,只返回一个节点。这是来自 clang-tidy 的评论涵盖该主题:

The case that a Stmt has multiple parents is rare but does actually occur in the parts of the AST that we're interested in. Specifically, InitListExpr nodes cause ASTContext::getParent() to return multiple parents for certain nodes in their subtree because RecursiveASTVisitor visits both the syntactic and semantic forms of InitListExpr, and the parent-child relationships are different between the two forms.



也许还有其他节点,但我找不到相关信息。

关于clang - Clang AST 节点何时会有多个父节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60262846/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com