]> granicus.if.org Git - clang/commitdiff
Use Destroy for member initializer list clean up.
authorFariborz Jahanian <fjahanian@apple.com>
Wed, 1 Jul 2009 23:35:25 +0000 (23:35 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Wed, 1 Jul 2009 23:35:25 +0000 (23:35 +0000)
Per Doug's comments. Doug please review.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74666 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclCXX.h
lib/AST/DeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp

index d5ae20d356d6fa88ac7bacc07ec678e6acea5511..a6e55ea65abb54dc27b264e39e482ccea5445afb 100644 (file)
@@ -710,8 +710,7 @@ class CXXConstructorDecl : public CXXMethodDecl {
       BaseOrMemberInitializers(0), NumBaseOrMemberInitializers(0) { 
     setImplicit(isImplicitlyDeclared);
   }
-  
-  ~CXXConstructorDecl() { delete [] BaseOrMemberInitializers; }
+  virtual void Destroy(ASTContext& C);
   
 public:
   static CXXConstructorDecl *Create(ASTContext &C, CXXRecordDecl *RD,
@@ -742,23 +741,23 @@ public:
     ImplicitlyDefined = ID; 
   }
   
-  /// arg_iterator - Iterates through the member/base initializer list.
-  typedef CXXBaseOrMemberInitializer **arg_iterator;
+  /// init_iterator - Iterates through the member/base initializer list.
+  typedef CXXBaseOrMemberInitializer **init_iterator;
   
-  /// arg_const_iterator - Iterates through the memberbase initializer list.
-  typedef CXXBaseOrMemberInitializer * const * arg_const_iterator;
+  /// init_const_iterator - Iterates through the memberbase initializer list.
+  typedef CXXBaseOrMemberInitializer * const * init_const_iterator;
   
   /// begin() - Retrieve an iterator to the first initializer.
-  arg_iterator       begin()       { return BaseOrMemberInitializers; }
+  init_iterator       begin()       { return BaseOrMemberInitializers; }
   /// begin() - Retrieve an iterator to the first initializer.
-  arg_const_iterator begin() const { return BaseOrMemberInitializers; }
+  init_const_iterator begin() const { return BaseOrMemberInitializers; }
   
   /// end() - Retrieve an iterator past the last initializer.
-  arg_iterator       end()       { 
+  init_iterator       end()       { 
     return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 
   }
   /// end() - Retrieve an iterator past the last initializer.
-  arg_const_iterator end() const { 
+  init_const_iterator end() const { 
     return BaseOrMemberInitializers + NumBaseOrMemberInitializers; 
   }
   
@@ -768,7 +767,8 @@ public:
       return NumBaseOrMemberInitializers; 
   }
   
-  void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer **Initializers,
+  void setBaseOrMemberInitializers(ASTContext &C,
+                                   CXXBaseOrMemberInitializer **Initializers,
                                    unsigned NumInitializers);
   
   /// isDefaultConstructor - Whether this constructor is a default
index f653943f1dd46cdc54bc91e5bd49a41fa3e2cd0a..9bdf07b29e51121561c5ea475de809e7cc7dfb74 100644 (file)
@@ -409,17 +409,25 @@ CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
 
 void
 CXXConstructorDecl::setBaseOrMemberInitializers(
+                                    ASTContext &C,
                                     CXXBaseOrMemberInitializer **Initializers,
                                     unsigned NumInitializers) {
   if (NumInitializers > 0) {
     NumBaseOrMemberInitializers = NumInitializers;
     BaseOrMemberInitializers = 
-    new CXXBaseOrMemberInitializer*[NumInitializers];
+      new (C, 8) CXXBaseOrMemberInitializer*[NumInitializers]; 
     for (unsigned Idx = 0; Idx < NumInitializers; ++Idx)
       BaseOrMemberInitializers[Idx] = Initializers[Idx];
   }
 }
 
+void
+CXXConstructorDecl::Destroy(ASTContext& C) {
+  C.Deallocate(BaseOrMemberInitializers);
+  this->~CXXMethodDecl();
+  C.Deallocate((void *)this);
+}
+
 CXXConversionDecl *
 CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
                           SourceLocation L, DeclarationName N,
index bbb173a02adc5f2e25defd9f1202075762aa995c..bef63a16d6cc7255bb28cbed645842fe306f8b12 100644 (file)
@@ -782,7 +782,7 @@ void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl,
     return;
   }
   llvm::DenseMap<void*, CXXBaseOrMemberInitializer *>Members;
-  
+  bool err = false;
   for (unsigned i = 0; i < NumMemInits; i++) {
     CXXBaseOrMemberInitializer *Member = 
       static_cast<CXXBaseOrMemberInitializer*>(MemInits[i]);
@@ -811,7 +811,12 @@ void Sema::ActOnMemInitializers(DeclPtrTy ConstructorDecl,
     }
     Diag(PrevMember->getSourceLocation(), diag::note_previous_initializer)
       << 0;
+    err = true;
   }
+  if (!err)
+    Constructor->setBaseOrMemberInitializers(Context, 
+                    reinterpret_cast<CXXBaseOrMemberInitializer **>(MemInits), 
+                    NumMemInits);
 }
 
 namespace {