I would like to detect when a PARM_DECL has a default value, i.e.
in the case:
void foo(int x = 5);
I want to be able to tell that x has a default value. I’m not interested in the statement after the = sign, only the fact that it has a default parameter.
Is this possible with libclang?
I've asked this before on this list and apparently it is not easily possible
with libclang currently. What you can do if you just want to figure out if a
default argument is there, is to recurse manually into the cursor and see if
it has any children - if so, it has a default argument.
See also: http://clang-developers.42468.n3.nabble.com/Finding-default-value-for-function-argument-with-clang-c-API-td4036919.html
Hi, I just got the same problem as you did, and I'm using libclang python
Finally I solve it out by inspecting all children of the function cursor,
and they're all PARM_DECL kind.
Then get the tokens of each child, for each token , get it's spelling, if
the spelling equals to '=', then this parameter has a default value.
Hope this helps.