我正在研究clang libtooling,我需要赋值操作的左侧,
所以我曾经VisitBinaryOperator(BinaryOperator *B)
得到左手边,我对它做了一些研究并通过以下方式实现
bool VisitBinaryOperator(BinaryOperator *B)
{
if(B->isAssignmentOp())
{
Expr *E = B->getLHS();
if(const clang::DeclRefExpr *lhs = dyn_cast<clang::DeclRefExpr>(E))
{
cout<< "Count 1\n";
}
}
return true;
}
这是我的示例程序
#define abc ab
int ab[5];
int b[10];
int main()
{
b[0] = 0;
b[1] = b[0];
abc[1] = 0;
}
对于这个程序VisitBinaryOperator
函数应该进入 if 条件,因为 b[0],b[1],abc[1] 在 main 函数中被引用。
但控制不仅仅进入内部,而且我也无法调试它。
请让我知道这个问题的答案。