【发布时间】:2023-03-15 18:50:01
【问题描述】:
我对clang很陌生。所以如果这个问题听起来很傻,请原谅。
我正在尝试编写一个简单的 Clang 检查器。
我有一个简单的程序。
void function(int a)
{
printf("%d", a);
}
main()
{
static int A = 0;
//some computation
//How to get the source of the variable declaration of A here?
func(A);
}
我的尝试
void MyChecker::checkPreCall(const CallEvent &Call,
CheckerContext &C) const {
ParamVarDecl *VD = Call.parameters()[0];
//this dumps the declaration of the callee function, i.e dest
Call.parameters()[0]->dump();
if(Call.parameters()[0]->isStaticLocal()){
std::cout << "Static variable";
}
}
我试图在调用 func 时获取 A 的变量声明。然而,它得到了被调用者参数的变量声明;即目的地。如何获取源的变量声明?
【问题讨论】:
标签: clang abstract-syntax-tree