[cfe-dev] Attempt 3 at CXX Namespaces

Chris Lattner clattner at apple.com
Wed Mar 19 22:39:07 PDT 2008

On Mar 14, 2008, at 4:05 PM, Kevin Tew wrote:

> I'm puzzled at how to go about adding child decls too a namespace.


> I've picked up, that the parser shouldn't use AST types and only  
> make Actions.ActOn... calls.


> Currently I'm thinking something like this:
> llvm::SmallVector<DeclTy*, 16>  NamespaceChildren;
> while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
> NamespaceChildren.push_back(ParseExternalDeclaration());
> }
> Actions.ActOnNamespaceMembers(&NamespaceChildren[0],  
> NamespaceChildren.size());
> or something like this:
> while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
> Actions.ActOnNamespaceMember(ParseExternalDeclaration());
> }
> Am I on the right track?

I'd suggest calling one action when a namespace is started and one  
when finished (like you have).  The former create a Namespacedecl  
object and push it as the current context.  All decls parsed after  
that (and actions fired as a result of them) would cause the decls to  
get added to the current context (the namespace). When the namespace  
is closed, the current context is finished and removed.

This is somewhat like scope processing.  Does this make sense?


More information about the cfe-dev mailing list