[cfe-dev] libclang - how to find an implementation using CXCursor

Eran Ifrah eran.ifrah at gmail.com
Fri May 11 09:02:58 PDT 2012


On Fri, May 11, 2012 at 6:09 PM, Eran Ifrah <eran.ifrah at gmail.com> wrote:

>
>
> On Fri, May 11, 2012 at 5:00 PM, Nikola Smiljanic <popizdeh at gmail.com>wrote:
>
>> 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?


-- 
> Eran Ifrah
> Author of the cross platform, open source C++ IDE: http://www.codelite.org
> YTubePlayer http://www.ytubeplayer.com
>
>


-- 
Eran Ifrah
Author of the cross platform, open source C++ IDE: http://www.codelite.org
YTubePlayer http://www.ytubeplayer.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120511/a8d58d40/attachment.html>


More information about the cfe-dev mailing list