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,
diff --git a/lib/AST/DeclPrinter.cpp b/lib/AST/DeclPrinter.cpp
index c7ad8d0..84ae729 100644
--- a/lib/AST/DeclPrinter.cpp
+++ b/lib/AST/DeclPrinter.cpp
@@ -374,6 +374,36 @@
}
}
}
+ else if (CXXDestructorDecl *DDecl = dyn_cast<CXXDestructorDecl>(D)) {
+ if (DDecl->getNumBaseOrMemberDestructions() > 0) {
+ // FIXME. This is strictly for visualization of destructor's AST for
+ // how base/members are destructed. It has no other validity.
+ assert (D->isThisDeclarationADefinition() && "Destructor with dtor-list");
+ Proto += " : ";
+ for (CXXDestructorDecl::destr_const_iterator B = DDecl->destr_begin(),
+ E = DDecl->destr_end();
+ B != E; ++B) {
+ CXXBaseOrMemberInitializer * BMInitializer = (*B);
+ if (B != DDecl->destr_begin())
+ Proto += ", ";
+
+ if (BMInitializer->isMemberInitializer()) {
+ FieldDecl *FD = BMInitializer->getMember();
+ Proto += "~";
+ Proto += FD->getNameAsString();
+ }
+ else // FIXME. skip dependent types for now.
+ if (const RecordType *RT =
+ BMInitializer->getBaseClass()->getAsRecordType()) {
+ const CXXRecordDecl *BaseDecl =
+ cast<CXXRecordDecl>(RT->getDecl());
+ Proto += "~";
+ Proto += BaseDecl->getNameAsString();
+ }
+ Proto += "()";
+ }
+ }
+ }
else
AFT->getResultType().getAsStringInternal(Proto, Policy);
} else {
diff --git a/lib/Parse/ParseCXXInlineMethods.cpp b/lib/Parse/ParseCXXInlineMethods.cpp
index 8dcf24f..3bb9c3e 100644
--- a/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/lib/Parse/ParseCXXInlineMethods.cpp
@@ -172,7 +172,7 @@
if (Tok.is(tok::colon))
ParseConstructorInitializer(LM.D);
else
- Actions.ActOnDefaultInitializers(LM.D);
+ Actions.ActOnDefaultCDtorInitializers(LM.D);
// FIXME: What if ParseConstructorInitializer doesn't leave us with a '{'??
ParseFunctionStatementBody(LM.D);
diff --git a/lib/Parse/Parser.cpp b/lib/Parse/Parser.cpp
index bac3a86..e7b0f33 100644
--- a/lib/Parse/Parser.cpp
+++ b/lib/Parse/Parser.cpp
@@ -666,7 +666,7 @@
if (Tok.is(tok::colon))
ParseConstructorInitializer(Res);
else
- Actions.ActOnDefaultInitializers(Res);
+ Actions.ActOnDefaultCDtorInitializers(Res);
return ParseFunctionStatementBody(Res);
}
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index e01bf23..f17b77b 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -1468,7 +1468,7 @@
SourceLocation MemberLoc,
IdentifierInfo &Member,
DeclPtrTy ImplDecl);
- virtual void ActOnDefaultInitializers(DeclPtrTy ConstructorDecl);
+ virtual void ActOnDefaultCDtorInitializers(DeclPtrTy CDtorDecl);
bool ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
FunctionDecl *FDecl,
const FunctionProtoType *Proto,
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 7d039dc..c62858a 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -902,15 +902,18 @@
}
}
-void Sema::ActOnDefaultInitializers(DeclPtrTy ConstructorDecl) {
- if (!ConstructorDecl)
+void Sema::ActOnDefaultCDtorInitializers(DeclPtrTy CDtorDecl) {
+ if (!CDtorDecl)
return;
if (CXXConstructorDecl *Constructor
- = dyn_cast<CXXConstructorDecl>(ConstructorDecl.getAs<Decl>()))
+ = dyn_cast<CXXConstructorDecl>(CDtorDecl.getAs<Decl>()))
Constructor->setBaseOrMemberInitializers(Context,
(CXXBaseOrMemberInitializer **)0, 0);
-
+ else
+ if (CXXDestructorDecl *Destructor
+ = dyn_cast<CXXDestructorDecl>(CDtorDecl.getAs<Decl>()))
+ Destructor->setBaseOrMemberDestructions(Context);
}
namespace {