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

Stefan Seefeld seefeld at sympatico.ca
Wed Feb 16 08:59:11 PST 2011

On 2011-02-15 17:02, Douglas Gregor wrote:
> On Feb 15, 2011, at 1:44 PM, Stefan Seefeld wrote:
>> (The reason I'd very much prefer to keep this away from libclang is because these associations tend to be a matter of customization, and hard to support on a low level. Consider this:
>> // E docs
>> enum E {
>>   e0,    //<  e0 docs
>>   e1}; //<  e1 docs
>> I think the meaning (and logical attachment) of the comments is rather obvious. Yet, this is tricky to implement: Sometimes the comments precede the declaration they are associated with, sometimes they follow them. Sometimes they are even outside the parent cursor's range.
>> To support that inside libclang, one would have to parse the comment, using specific rules and markup. I'd rather leave such markup choices to the user who embeds documentation into his code.
> Because it's tricky to implement, it's a good candidate for going straight into Clang so that nobody has to do this work again. But, it's up to you.

A first implementation of the approach seems to work reasonably well.

There are a some shortcomings, though. For example:

struct Foo
   // some docs
   int member;

When visiting the FieldDecl for 'member', the cursor's range starts with 
'member'. To recognize that the comment in the preceding line belongs to 
it, I need a extend the cursor's range to the entire declaration 
(instead of just the single declarator).
Is that possible ? Right now, clang_getLexicalParent() brings me to the 
ClassDecl for 'Foo'.
Is there a reason declarations aren't represented as cursors ? Or is 
there another way to get information (such as the extent) about a 
declaration ?



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

More information about the cfe-dev mailing list