[cfe-dev] Finding default value for function argument with clang-c API

Jacob Carlborg doob at me.com
Mon Jan 6 13:00:48 PST 2014


On 2014-01-06 17:10, Milian Wolff wrote:
> Hello again.
>
> When encountering a CXCursor_ParmDecl, how can I figure out if it has a
> default value and what that value is? E.g.:
>
> void foo(int i = 42);
>
> Here I'd like to know that "i" is 42 by default. A string representation of
> the default value would be sufficient to me, but even that doesn't seem to be
> accessible. I could find some range for where the "= 42" is, but then I cannot
> find any function in the C-API of clang to get a string representation of that
> range.

I think you should just continue traversal the AST using 
clang_visitChildren. Also have a look at clang_Cursor_getArgument, you 
might need that as well.

-- 
/Jacob Carlborg




More information about the cfe-dev mailing list