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

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Jan 4 12:26:56 PST 2013


On Dec 27, 2012, at 3:10 AM, Peter Conn <conn.peter at gmail.com> wrote:

> 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?

I'm assuming clang_equalCursors() did not return the expected value ?
We should look into that first if that is the case.

> 
> Thanks, Peter
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list