libclang - how to find an implementation using CXCursor

Hi List,

I have implemented the functionality of ‘Goto Declaration’ using the following pseudo code:

First, we obtain the cursor using ‘location’ and TU:

What about clang_getCursorDefinition. The documentation sounds like
this is what you're looking for but I might be wrong.

http://clang.llvm.org/doxygen/group__CINDEX__CURSOR__XREF.html

Thanks, that was what I was looking for

What about clang_getCursorDefinition. The documentation sounds like
this is what you’re looking for but I might be wrong.

http://clang.llvm.org/doxygen/group__CINDEX__CURSOR__XREF.html

Thanks, that was what I was looking for

I celebrated too soon…
It worked on some cases, e.g.:
I issued the ‘find implementation’ from the source file where the implementation actually exists and it worked. But when I issued ‘Find Implementation’ from another source, it failed.

The logic to find the definition of a function is implemented like this:

  • Load the TU of the current file opened in the editor
  • Get the cursor at a given location
  • Assuming that the returned cursor is valid but not a definition (clang_isCursorDefinition() == 0) call to ‘clang_getCursorDefinition’ using the previously cursor as the input

At this point, the returned cursor is ‘InvalidFirst’
My guess is that libclang fails to find the implementation since it does not exists in the current TU

So the question is: how do I find a function definition which exists in another TU (but is associated to the same Index)

And in General are there any good practices to work with multiple translation units?

Off-topic question:
It seems to me that my questions are ‘user’ questions (as in ‘user of libclang’) but not really related to LLVM development… is this the correct mailing list?