是否有任何简单可靠的方法(a.k.a.而不是正则表达式)将函数指针声明的QualType
作为字符串但附加了名称?我试图利用QualType::getAsString(const PrintingPolicy &Policy)
,但不幸的是,没有选择配置。
EG
int (*)(void)
----> int (*whatever_name_here)(void)
你可以创建VarDecl
并打印出来。
假设ctx
是你的ASTContext
而type
是你的QualType
,这是你可以做的:
// Create identifier.
IdentifierInfo id = ctx.Idents.get("whatever_name_here");
// Create variable declaration.
VarDecl *vd = VarDecl::Create(ctx, ctx.getTranslationUnitDecl(),
SourceLocation(), SourceLocation(), &id, type, nullptr, StorageClass:SC_None);
// Print it.
vd->print(/* put your llvm::raw_stream here */, ctx.getPrintingPolicy());