我有一个匹配构造函数中的 uninit 双字段的问题。鉴于下面的代码
class un_init_double {
public:
un_init_double() {
init_param_ = 0;
}
bool compare(un_init_double& other) {
if (other.un_init_param_ == un_init_param_) {
return true;
}
return false;
}
private:
double un_init_param_;
double init_param_;
};
我想匹配未在构造函数中调用二元运算符 = 的 un_init_param_ 字段。但我找不到这样做的方法。
我在 clang-query 中输入以下命令
clang-query> match cxxRecordDecl(
has(fieldDecl(hasType(asString("double"))).bind("double_field")), has(cxxConstructorDecl(hasDescendant(binaryOperator(hasEitherOperand(memberExpr()))))))
但是如何指定 memberExpr 与 prew 部分 fieldDecl 相关?换句话说,如何指定fieldDecl和memberExpr的连接?
我找到了匹配 init_param_ 的方法,但是如何找到没有匹配的字段?
clang-query> match cxxRecordDecl(has(cxxConstructorDecl(hasDescendant(binaryOperator(hasEitherOperand(memberExpr(hasDeclaration(fieldDecl(hasType(asString("double"))))).bind("member")))))))
Match #1:
~/code_test/ast_matcher/test.cc:9:7: note: "member" binds here
init_param_ = 0;
^~~~~~~~~~~
~/code_test/ast_matcher/test.cc:6:1: note: "root" binds here
class un_init_double {
^~~~~~~~~~~~~~~~~~~~~~
1 match.
clang-query>