【发布时间】:2019-11-03 17:02:54
【问题描述】:
我正在尝试获取 TypeAliasDecl 的 RHS 模板类型。
例子:
using AliasOfType = AliasedType; // AliasedType itself is a template
我可以使用 clang::ast_matchers::typeAliasDecl 在 AST 中检索 AliasOfType。我想用clang::ast_matchers:: 检索AliasedType。
clang::ast_matchers::typeAliasDecl 的 AST 转储如下所示:
TypeAliasDecl 0x4fe22cf8 AliasOfType
-SubstTemplateTypeParmType 0x4fe22cc0
|-TemplateTypeParmType 0x4fe1a840 `AliasedType` dependent depth 0 index 0
| `-TemplateTypeParm 0x4fe1a7f8 'AliasedType'
所以直观地说,我想匹配TemplateTypeParm,它有我之前的匹配作为祖先。但是,我还没有找到可以做到这一点的ast_matcher。有clang::ast_matchers::templateTypeParmType,但如果我尝试将任何内容作为缩小参数,例如:
templateTypeParmType(hasName("AliasedType"))
我尝试时遇到的错误是:
clang/ASTMatchers/ASTMatchersInternal.h:1347:13: error: ‘clang::ast_matchers::internal::Matcher< <template-parameter-1-1> >::Matcher(const clang::ast_matchers::internal::DynTypedMatcher&) [with T = clang::TemplateTypeParmType]’ is private within this context
return {Matcher<T>(std::get<Is>(Params))...};
【问题讨论】:
标签: c++ c++11 clang llvm abstract-syntax-tree