[cfe-commits] r74666 - in /cfe/trunk: include/clang/AST/DeclCXX.h lib/AST/DeclCXX.cpp lib/Sema/SemaDeclCXX.cpp

Fariborz Jahanian fjahanian at apple.com
Wed Jul 1 16:35:26 PDT 2009


Author: fjahanian
Date: Wed Jul  1 18:35:25 2009
New Revision: 74666

URL: http://llvm.org/viewvc/llvm-project?rev=74666&view=rev
Log:
Use Destroy for member initializer list clean up.
Per Doug's comments. Doug please review.

Modified:
    cfe/trunk/include/clang/AST/DeclCXX.h
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/AST/DeclCXX.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclCXX.h?rev=74666&r1=74665&r2=74666&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/DeclCXX.h (original)
+++ cfe/trunk/include/clang/AST/DeclCXX.h Wed Jul  1 18:35:25 2009
@@ -710,8 +710,7 @@
       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 @@
     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 @@
       return NumBaseOrMemberInitializers; 
   }
   
-  void setBaseOrMemberInitializers(CXXBaseOrMemberInitializer **Initializers,
+  void setBaseOrMemberInitializers(ASTContext &C,
+                                   CXXBaseOrMemberInitializer **Initializers,
                                    unsigned NumInitializers);
   
   /// isDefaultConstructor - Whether this constructor is a default

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=74666&r1=74665&r2=74666&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Wed Jul  1 18:35:25 2009
@@ -409,17 +409,25 @@
 
 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,

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=74666&r1=74665&r2=74666&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Jul  1 18:35:25 2009
@@ -782,7 +782,7 @@
     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 @@
     }
     Diag(PrevMember->getSourceLocation(), diag::note_previous_initializer)
       << 0;
+    err = true;
   }
+  if (!err)
+    Constructor->setBaseOrMemberInitializers(Context, 
+                    reinterpret_cast<CXXBaseOrMemberInitializer **>(MemInits), 
+                    NumMemInits);
 }
 
 namespace {





More information about the cfe-commits mailing list