Parsing of namespaces:

-NamespaceDecl for the AST
-Checks for name clashes between namespaces and tag/normal declarations.

This commit doesn't implement proper name lookup for namespaces.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@50321 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index 3c7401f..d2febb9 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -29,6 +29,7 @@
 static unsigned nSUC = 0;
 static unsigned nEnumConst = 0;
 static unsigned nEnumDecls = 0;
+static unsigned nNamespaces = 0;
 static unsigned nTypedef = 0;
 static unsigned nFieldDecls = 0;
 static unsigned nInterfaceDecls = 0;
@@ -57,6 +58,7 @@
 const char *Decl::getDeclKindName() const {
   switch (DeclKind) {
   default: assert(0 && "Unknown decl kind!");
+  case Namespace:           return "Namespace";
   case Typedef:             return "Typedef";
   case Function:            return "Function";
   case Var:                 return "Var";
@@ -85,7 +87,11 @@
   fprintf(stderr, "  %d decls total.\n", 
           int(nFuncs+nVars+nParmVars+nFieldDecls+nSUC+
               nEnumDecls+nEnumConst+nTypedef+nInterfaceDecls+nClassDecls+
-              nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls));
+              nMethodDecls+nProtocolDecls+nCategoryDecls+nIvarDecls+
+              nNamespaces));
+  fprintf(stderr, "    %d namespace decls, %d each (%d bytes)\n", 
+          nNamespaces, (int)sizeof(NamespaceDecl), 
+          int(nNamespaces*sizeof(NamespaceDecl)));
   fprintf(stderr, "    %d function decls, %d each (%d bytes)\n", 
           nFuncs, (int)sizeof(FunctionDecl), int(nFuncs*sizeof(FunctionDecl)));
   fprintf(stderr, "    %d variable decls, %d each (%d bytes)\n", 
@@ -170,12 +176,14 @@
               nObjCPropertyDecl*sizeof(ObjCPropertyDecl)+
               nObjCPropertyImplDecl*sizeof(ObjCPropertyImplDecl)+
               nLinkageSpecDecl*sizeof(LinkageSpecDecl)+
-              nFileScopeAsmDecl*sizeof(FileScopeAsmDecl)));
+              nFileScopeAsmDecl*sizeof(FileScopeAsmDecl)+
+              nNamespaces*sizeof(NamespaceDecl)));
     
 }
 
 void Decl::addDeclKind(Kind k) {
   switch (k) {
+  case Namespace:           nNamespaces++; break;
   case Typedef:             nTypedef++; break;
   case Function:            nFuncs++; break;
   case Var:                 nVars++; break;
@@ -205,12 +213,18 @@
 //===----------------------------------------------------------------------===//
 // Decl Allocation/Deallocation Method Implementations
 //===----------------------------------------------------------------------===//
-
+ 
 TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) {
   void *Mem = C.getAllocator().Allocate<TranslationUnitDecl>();
   return new (Mem) TranslationUnitDecl();
 }
 
+NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
+                                     SourceLocation L, IdentifierInfo *Id) {
+  void *Mem = C.getAllocator().Allocate<NamespaceDecl>();
+  return new (Mem) NamespaceDecl(DC, L, Id);
+}
+
 VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC,
                          SourceLocation L,
                          IdentifierInfo *Id, QualType T,
@@ -342,6 +356,7 @@
   CASE(ObjCImplementation);
   CASE(ObjCProtocol);
   CASE(ObjCProperty);
+  CASE(Namespace);
   CASE(Typedef);
   CASE(Enum);
   CASE(EnumConstant);