[cfe-dev] libclang Discrepancy in getting the range of a Variable Declaration.

Peter Conn conn.peter at gmail.com
Thu Dec 27 03:10:32 PST 2012


Hello,

I'm using libclang to search through CXCursors to match variable references
to their definitions.

To do this, I'm storing a list of the definitions, and whenever I come
across a reference, I call 'clang_getCursorDefinition' and compare for
equality. For my equality check, I just see if the CXSourceRange's of the
two cursors are equal.

This works well unless I have a definition like:

    int n, sum = 0;

In this case, when I encounter the definition CXCursor through my tree
search (through clang_visitChildren), the range covers 'sum = 0'. But when
I call 'clang_getCursorDefinition' on a reference, the range for the
returned CXCursor covers 'int n, sum = 0'.

Is there a way to get the more precise range from a cursor referencing the
variable? Or is there a simpler way to compare for equality between a
definition cursor and a reference cursor for the same variable?

Thanks, Peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121227/8173a4bb/attachment.html>


More information about the cfe-dev mailing list