Allocate most of DeclarationNamesTable using ASTContext's allcocator.  The only things that
aren't allocated this way are the internal FoldingSets.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103429 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclarationName.cpp b/lib/AST/DeclarationName.cpp
index 0623283..343d403 100644
--- a/lib/AST/DeclarationName.cpp
+++ b/lib/AST/DeclarationName.cpp
@@ -384,12 +384,12 @@
   llvm::errs() << '\n';
 }
 
-DeclarationNameTable::DeclarationNameTable(ASTContext &C) {
+DeclarationNameTable::DeclarationNameTable(ASTContext &C) : Ctx(C) {
   CXXSpecialNamesImpl = new llvm::FoldingSet<CXXSpecialName>;
   CXXLiteralOperatorNames = new llvm::FoldingSet<CXXLiteralOperatorIdName>;
 
   // Initialize the overloaded operator names.
-  CXXOperatorNames = new (C) CXXOperatorIdName[NUM_OVERLOADED_OPERATORS];
+  CXXOperatorNames = new (Ctx) CXXOperatorIdName[NUM_OVERLOADED_OPERATORS];
   for (unsigned Op = 0; Op < NUM_OVERLOADED_OPERATORS; ++Op) {
     CXXOperatorNames[Op].ExtraKindOrNumArgs
       = Op + DeclarationNameExtra::CXXConversionFunction;
@@ -400,36 +400,34 @@
 DeclarationNameTable::~DeclarationNameTable() {
   llvm::FoldingSet<CXXSpecialName> *SpecialNames =
     static_cast<llvm::FoldingSet<CXXSpecialName>*>(CXXSpecialNamesImpl);
-  llvm::FoldingSetIterator<CXXSpecialName>
-                           SI = SpecialNames->begin(), SE = SpecialNames->end();
-
-  while (SI != SE) {
-    CXXSpecialName *n = &*SI++;
-    delete n;
-  }
-
-
   llvm::FoldingSet<CXXLiteralOperatorIdName> *LiteralNames
     = static_cast<llvm::FoldingSet<CXXLiteralOperatorIdName>*>
-                                                      (CXXLiteralOperatorNames);
-  llvm::FoldingSetIterator<CXXLiteralOperatorIdName>
-                           LI = LiteralNames->begin(), LE = LiteralNames->end();
+        (CXXLiteralOperatorNames);
 
-  while (LI != LE) {
-    CXXLiteralOperatorIdName *n = &*LI++;
-    delete n;
+  if (Ctx.FreeMemory) {
+    llvm::FoldingSetIterator<CXXSpecialName>
+      SI = SpecialNames->begin(), SE = SpecialNames->end();
+
+    while (SI != SE) {
+      CXXSpecialName *n = &*SI++;
+      Ctx.Deallocate(n);
+    }
+
+    llvm::FoldingSetIterator<CXXLiteralOperatorIdName>
+      LI = LiteralNames->begin(), LE = LiteralNames->end();
+
+    while (LI != LE) {
+      CXXLiteralOperatorIdName *n = &*LI++;
+      Ctx.Deallocate(n);
+    }
+
+    Ctx.Deallocate(CXXOperatorNames);
   }
 
   delete SpecialNames;
   delete LiteralNames;
 }
 
-void DeclarationNameTable::DoDestroy(ASTContext &C) {
-  if (C.FreeMemory) {
-    C.Deallocate(CXXOperatorNames);
-  }
-}
-
 DeclarationName
 DeclarationNameTable::getCXXSpecialName(DeclarationName::NameKind Kind,
                                         CanQualType Ty) {
@@ -465,7 +463,7 @@
   if (CXXSpecialName *Name = SpecialNames->FindNodeOrInsertPos(ID, InsertPos))
     return DeclarationName(Name);
 
-  CXXSpecialName *SpecialName = new CXXSpecialName;
+  CXXSpecialName *SpecialName = new (Ctx) CXXSpecialName;
   SpecialName->ExtraKindOrNumArgs = EKind;
   SpecialName->Type = Ty;
   SpecialName->FETokenInfo = 0;
@@ -493,7 +491,7 @@
                                LiteralNames->FindNodeOrInsertPos(ID, InsertPos))
     return DeclarationName (Name);
   
-  CXXLiteralOperatorIdName *LiteralName = new CXXLiteralOperatorIdName;
+  CXXLiteralOperatorIdName *LiteralName = new (Ctx) CXXLiteralOperatorIdName;
   LiteralName->ExtraKindOrNumArgs = DeclarationNameExtra::CXXLiteralOperator;
   LiteralName->ID = II;