[cfe-dev] Cleaning up the representation of Decls in the AST

Ted Kremenek kremenek at apple.com
Sat Aug 23 17:47:05 PDT 2008


On Aug 23, 2008, at 5:29 PM, Neil Booth wrote:

> Ted Kremenek wrote:-
>
>> - RecordDecls would represent their fields as a group of DeclGroups.
>>  This enables us to accurately represent:
>>
>> struct x {
>>   struct y { int z; } a, b;
>>   int c;
>> };
>>
>> A field_iterator interface can provide the necessary abstraction to
>> clients that just want to iterate over the FieldDecls of a struct.
>
> This example has a different meaning in C and C++.  Would they
> be represented the same?

Hi Neil,

I think I know what you are referring to, but could you please  
elaborate a little more?  Are you referring to the visibility of  
fields?  The main solution that DeclGroup would solve is faithfully  
representing multi-variable declarations that also include a type  
declaration.  This seems complementary to capturing visibility.  For  
example, the "group of DeclGroups" could also be interspersed with  
"visibility" markers (with SourceLocation information).  An iterator  
mechanism could be provided for clients iterate over private/protected/ 
public fields, etc.

>  How would one walk file-scope struct/
> union/enum declarations for C?

We can currently iterate over all file-scope declarations using  
TranslationUnit (which contains references to all top-level  
declarations).  This same interface could be preserved by (a)  
providing a new iterator mechanism to iterate over top-level  
DeclGroups and (b) layering a revised iterator mechanism for iterating  
over the top-level Decls over the iterating mechanism for top-level  
DeclGroups.

Does this address your question, or were you asking about something  
else?

Ted



More information about the cfe-dev mailing list