[cfe-dev] C++ namespaces support

Chris Lattner clattner at apple.com
Tue Mar 25 17:01:11 PDT 2008

On Mar 24, 2008, at 6:20 PM, Argiris Kirtzidis wrote:
> Hi,
> The attached patch adds support for parsing C++ namespaces and  
> resolving name lookups based on them.

Wow, this is really cool!

Two high level thoughts before the details:

+/// NamespaceDecl - Represent a C++ namespace.
+class NamespaceDecl : public ScopedDecl {
+  llvm::SmallVector<ScopedDecl *, 16> Decls;
+  SourceLocation LBracLoc, RBracLoc;
+  // The Scope that is associated with this namespace
+  Scope *NSScope;

"Scope" is an artifact of the parser, which is transiently live when  
parsing is happening.  Is it possible to move this to Sema instead of  
being in the AST?

+++ include/clang/Parse/Parser.h	(working copy)
@@ -16,6 +16,7 @@

  #include "clang/Lex/Preprocessor.h"
  #include "clang/Parse/Action.h"
+#include <stack>

  namespace clang {
    class DeclSpec;
@@ -49,6 +50,7 @@
    enum { ScopeCacheSize = 16 };
    unsigned NumCachedScopes;
    Scope *ScopeCache[ScopeCacheSize];
+  std::stack<Scope*> ScopeStack;

Why do you need an explicit stack of scopes here?  Aren't the current  
scope chains enough?


More information about the cfe-dev mailing list