Added ASTs to destructor decl AST for default destruction of object's
base/members.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@75849 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp
index 674e98a..57ac611 100644
--- a/lib/AST/DeclCXX.cpp
+++ b/lib/AST/DeclCXX.cpp
@@ -478,6 +478,50 @@
}
void
+CXXDestructorDecl::setBaseOrMemberDestructions(ASTContext &C) {
+ CXXRecordDecl *ClassDecl = cast<CXXRecordDecl>(getDeclContext());
+ llvm::SmallVector<CXXBaseOrMemberInitializer*, 32> AllToDestruct;
+ for (CXXRecordDecl::base_class_iterator VBase = ClassDecl->vbases_begin(),
+ E = ClassDecl->vbases_end(); VBase != E; ++VBase) {
+ CXXBaseOrMemberInitializer *Member =
+ new CXXBaseOrMemberInitializer(VBase->getType(), 0, 0,SourceLocation());
+ AllToDestruct.push_back(Member);
+ }
+ for (CXXRecordDecl::base_class_iterator Base =
+ ClassDecl->bases_begin(),
+ E = ClassDecl->bases_end(); Base != E; ++Base) {
+ if (Base->isVirtual())
+ continue;
+ CXXBaseOrMemberInitializer *Member =
+ new CXXBaseOrMemberInitializer(Base->getType(), 0, 0, SourceLocation());
+ AllToDestruct.push_back(Member);
+ }
+ // non-static data members.
+ for (CXXRecordDecl::field_iterator Field = ClassDecl->field_begin(),
+ E = ClassDecl->field_end(); Field != E; ++Field) {
+ QualType FieldType = C.getCanonicalType((*Field)->getType());
+ while (const ArrayType *AT = C.getAsArrayType(FieldType))
+ FieldType = AT->getElementType();
+
+ if (FieldType->getAsRecordType()) {
+ CXXBaseOrMemberInitializer *Member =
+ new CXXBaseOrMemberInitializer((*Field), 0, 0, SourceLocation());
+ AllToDestruct.push_back(Member);
+ }
+ }
+
+ unsigned NumDestructions = AllToDestruct.size();
+ if (NumDestructions > 0) {
+ NumBaseOrMemberDestructions = NumDestructions;
+ BaseOrMemberDestructions =
+ new (C) CXXBaseOrMemberInitializer*[NumDestructions];
+ // Insert in reverse order.
+ for (int Idx = NumDestructions-1, i=0 ; Idx >= 0; --Idx)
+ BaseOrMemberDestructions[i++] = AllToDestruct[Idx];
+ }
+}
+
+void
CXXConstructorDecl::setBaseOrMemberInitializers(
ASTContext &C,
CXXBaseOrMemberInitializer **Initializers,