我正在使用 clang 8.0.1 开发我的反射工具。现在我需要用所有完全限定的名称打印 Expr。
我已经尝试了将 FullyQualifiedName 位设置为 true 的内置 prettyPrint 函数。但它仍然给出不正确的结果。
对于这段代码:
namespace math {
struct Transform {
float val;
[[custom_attr(&Transform::public_val)]]
void foo();
};
}
它给了我
&Transform::public_val
代替
&math::Transform::public_val
而对于
static_cast<float (*)(const Transform&)>(Transform::static_overload)
作为 custom_attr 的值,它给了我
static_cast<float (*)(const math::Transform &)>(Transform::static_overload)
(仅Transform::static_over
)
这是我的打印代码:
std::string get_string(const Expr *expr, const ASTContext &Context) {
PrintingPolicy print_policy(Context.getLangOpts());
print_policy.FullyQualifiedName = 1;
print_policy.SuppressScope = 0;
print_policy.SuppressUnwrittenScope = 0;
std::string expr_string;
llvm::raw_string_ostream stream(expr_string);
expr->printPretty(stream, nullptr, print_policy);
stream.flush();
return expr_string;
}