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

Milian Wolff mail at milianw.de
Tue Jan 7 08:37:02 PST 2014


On Tuesday 07 January 2014 16:59:51 Jacob Carlborg wrote:
> On 2014-01-07 12:08, Milian Wolff wrote:
> > When I'm already encountering a CXCursor_ParmDecl in my visitor,
> > clang_Cursor_getArgument would not give me anything else - would it? The
> > cursor it returns would point to the same ParmDecl I'm already trying to
> > handle.
> > 
> > Now, I could continue visitChildren recursively on the ParmDecl cursor to
> > figure out if it has any default argument. But I still cannot find any API
> > to get a stringified version of the default argument.
> > 
> > In the example above the "42" default value is represented as a
> > CXCursor_IntegerLiteral. But neither clang_getCursorSpelling nor
> > clang_getCursorDisplayName give me a string containing "42" - both return
> > a
> > null CXString...
> > 
> > So, what other function can I use to get the stringified (raw) version of
> > a
> > cursor?
> 
> Ok, I see. How about clang_getCursorExtent?

Followed by clang_tokenize of the returned range, then stringifying those 
tokens via clang_getTokenSpelling? Is that what you have in mind? I'll try 
that out and write back - thanks.

Bye
-- 
Milian Wolff
mail at milianw.de
http://milianw.de



More information about the cfe-dev mailing list