[cfe-dev] Start of source range for Decl nodes.

Douglas Gregor dgregor at apple.com
Fri Mar 4 08:21:40 PST 2011


On Mar 4, 2011, at 8:06 AM, Stefan Seefeld wrote:

> On 2011-03-04 10:30, Douglas Gregor wrote:
>> On Mar 1, 2011, at 10:44 AM, Enea Zaffanella wrote:
>> 
>>> Assuming that the goal of obtaining precise source location info should
>>> be achieved by all means, now the question is: which is best place where
>>> this additional source location (the start of the range) for the Decl
>>> hierarchy should be stored?
>>> Would it be OK to store them at the top of the hierarchy?
>>> Are there better places?
>> I'd rather that we only add this information to those AST nodes that need it.
>> 
>> Also, the source range for a DeclaratorDecl (and anything else that stares with declaration specifiers) gets messy when there are multiple declarations, e.g.,
>> 
>>   static struct Point { int x, y; } p1, *p2, get_point(int x, int y);
>> 
>> Who claims the "static" keyword? Point? p1? Everyone?
>> 
>> If this occurred inside a DeclStmt, we'd have a DeclGroup to help us sort through this. At namespace scope, we don't have the equivalent notion.
> 
> Doug,
> 
> you may remember my request for something similar, via libclang.

Yes, this is a longstanding representational issue. Discussions of how to deal with it go back more than 2 years, but nobody's actually gone ahead and fixed the problems.

> To be 
> able to extract inline documentation from source code, I also need to 
> find the source range not only for a particular declarator, but also the 
> entire declaration.

Nailing down what this actually means is fairly important for the discussion of representation. What's the source range for the entire declaration of "p2" in my example? Does it include the unrelated declarator p1? Does it include get_point?

> Right now there is no way to get to that via 
> libclang, as declarations aren't represented by cursors.


The source range provided by libclang covers the declarator for each declaration, but not the specifiers common to all of the declarators.

  - Doug



More information about the cfe-dev mailing list