Displaying prototype tooltips in an IDE

We are using Clang as our compiler, and I want to display prototype tooltips in the IDE. I’m using libclang to get various source code browsing information.

In order to get the prototype information, I create the translation unit with clang_createTranslationUnit. Then I traverse the translation unit with clang_visitChildren. Whenever I come upon a cursor of kind CXCursor_FunctionDecl, I remember the cursor and then add any cursors of kind CXCursor_ParmDecl that follow to a parameter list. Then when I want to display the function prototype, I go thru the parameter cursor list, getting each parameter’s type and name.

This seems to work fine, except for variable argument functions. For example, for the function

void VarArgFunc(int p1, …)
{
va_list parmInfo;
va_start(parmInfo, p1);
va_end(parmInfo);
}

when traversing the translation unit with clang_visitChildren, the CXCursorVisitor callback is not called for the ‘…’ variable argument parameter. This means that I can’t tell that the function has a variable argument parameter, and when I show the prototype tooltip, it just shows “void VarArgFunc(int p1)”.

How can I detect that the function has a variable argument parameter? Is there some other better way to get this information?

Thanks

Is clang_getCursorDisplayName on the function sufficient for your purposes or you need the parameter info ?

I do need the parameter info.

clang_getCursorDisplayName returns “void VarArgFunc(int, …)”, and I want to display the name of the parameters too: “void VarArgFunc(int p1, …)”

Your suggestion did help me, however. I didn’t realize that clang_getCursorDisplayName provided the parameter types. So I can use that to figure out if the function has a variable argument or not.

Thanks for the help.

I do need the parameter info.

clang_getCursorDisplayName returns “void VarArgFunc(int, …)”, and I want to display the name of the parameters too: “void VarArgFunc(int p1, …)”

Your suggestion did help me, however. I didn’t realize that clang_getCursorDisplayName provided the parameter types. So I can use that to figure out if the function has a variable argument or not.

…or you can improve clang_getCursorDisplayName so that it adds the parameter names ? :slight_smile: