[cfe-dev] RFC: visiting cursors "backwards" ?

Stefan Seefeld seefeld at sympatico.ca
Tue Feb 15 12:40:05 PST 2011

libclang allows me to traverse sibling cursors.
I have run into a use-case where I want to visit the previous sibling 
cursor. How may I do that ?

The use-case is this:

Imagine code such as:

   struct foo;
   // Documentation for 'bar'
   struct bar;

In Synopsis, I'd like to associate the comment with the following 'bar' 
declaration. Therefor, I'd like to tokenize the region between 'struct 
bar' and the previous cursor, so I can read in the comment and store it 
for later documentation extraction.

I'd like to do this non-invasively, i.e. without the need for libclang 
to be aware of even the concept of documentation. As long as it gives me 
access to "all comments preceding cursor 'X'", I can work things out.

Thus: Is there a way to locate the previous sibling cursor for any given 
cursor ? (This may be a null cursor, if the given cursor is the first 
child of its parent. That's fine, as in that case I would start from the 
parent's start location itself.)



       ...ich hab' noch einen Koffer in Berlin...

More information about the cfe-dev mailing list