[cfe-dev] Patch for C++ namespaces
Argiris Kirtzidis
akyrtzi at gmail.com
Sun Apr 20 16:52:57 PDT 2008
Chris Lattner wrote:
>> For:
>> namespace A { int x; }
>> namespace A { int y; }
>>
>> There are two NamespaceDecls created and reported at
>> ASTConsumer::HandleTopLevelDecl, but 'A' refers only to the first one
>> (the 'original' namespace).
>> And while there's no list of decls associated with NamespaceDecls
>> yet, the intention is that the 'original namespace' will contain the
>> list (y will be associated with the first NamespaceDecl).
>
> Ok.
>
>> By reporting 2 namespace decls, the AST maps to the source code
>> better, and a refactoring tool would be able to do (for example)
>> "rename all 'A' namespaces" by traversing the AST.
>>
>> If this sound reasonable, how about adding a OriginalNamespace member
>> to NamespaceDecl so that extended namespace definition decls point to
>> the 'original' one?
>
> I think we should tackle this in a more systematic way. All "merging"
> of decls should be treated the same. It really would be nice to be
> able to walk all declarations of some decl.
A unified way to walk all 'merged' declaration would be great. How about
I commit namespaces as it is (minus NamespaceScope), so that a way to
deal generally with merged decls would
consider NamespaceDecls too.
>
> The best way to implement this (in terms of space efficiency) is an
> on-the-side DenseMap<Decl*,Decl*> which would implement a linked list
> of decls. Then each decl can just have one bit that says whether it
> has an entry in the map (i.e. whether there is a 'next'). This can be
> hidden around behind an accessor, just like the attribute stuff is.
> Does this seem reasonable?
That's a good idea!
-Argiris
More information about the cfe-dev
mailing list