[cfe-dev] How to get argument names from clang::CallExpr?

Stephen Kelly via cfe-dev cfe-dev at lists.llvm.org
Wed Oct 23 14:50:38 PDT 2019


On 22/10/2019 08:06, Kenth Eriksson via cfe-dev wrote:
> Hi!
> 
> How can I retrieve the argument names from a clang::CallExpr? I was 
> trying something along the following lines, but the dyn_cast returns null.

What if you don't try to cast it to a `DeclRefExpr`, but you cast it to 
a `Expr` and `->dump()` it?

Note that some args are not represented by `DeclRefExpr` if they are 
literals such as IntegerLiteral or StringLiteral.

Also - are you sure you want argument names? In the code below, clang 
calls a1 and a2 arguments and p1 and p2 parameters:

void foo(int p1, int p2);

void bar()
{
    int a1 = 5;
    int a2 = 7;
    foo(a1, a2);
}

if you want parameters, you need to get the FunctionDecl from the 
callExpr and query its parameters to get their names.

Thanks,

Stephen.




More information about the cfe-dev mailing list