From 84688f2a21bfde3cfdf1c41a053ef7b774d4cd0c Mon Sep 17 00:00:00 2001 From: Anders Carlsson Date: Tue, 20 Apr 2010 23:11:20 +0000 Subject: [PATCH] Factor some common code out into a separate function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101952 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 77 +++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index c8a3a8ab33..ca23727c5b 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1432,6 +1432,37 @@ Sema::BuildBaseInitializer(QualType BaseType, TypeSourceInfo *BaseTInfo, RParenLoc); } +static CXXBaseOrMemberInitializer * +BuildImplicitBaseInitializer(Sema &SemaRef, + const CXXConstructorDecl *Constructor, + CXXBaseSpecifier *BaseSpec) { + InitializedEntity InitEntity + = InitializedEntity::InitializeBase(SemaRef.Context, BaseSpec); + + InitializationKind InitKind + = InitializationKind::CreateDefault(Constructor->getLocation()); + + InitializationSequence InitSeq(SemaRef, InitEntity, InitKind, 0, 0); + Sema::OwningExprResult BaseInit = + InitSeq.Perform(SemaRef, InitEntity, InitKind, + Sema::MultiExprArg(SemaRef, 0, 0)); + + BaseInit = SemaRef.MaybeCreateCXXExprWithTemporaries(move(BaseInit)); + if (BaseInit.isInvalid()) + return 0; + + CXXBaseOrMemberInitializer *CXXBaseInit = + new (SemaRef.Context) CXXBaseOrMemberInitializer(SemaRef.Context, + SemaRef.Context.getTrivialTypeSourceInfo(BaseSpec->getType(), + SourceLocation()), + BaseSpec->isVirtual(), + SourceLocation(), + BaseInit.takeAs(), + SourceLocation()); + + return CXXBaseInit; +} + bool Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor, CXXBaseOrMemberInitializer **Initializers, @@ -1471,8 +1502,6 @@ Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor, AllBaseFields[Member->getMember()] = Member; } - llvm::SmallVector BasesToDefaultInit; - // Push virtual bases before others. for (CXXRecordDecl::base_class_iterator VBase = ClassDecl->vbases_begin(), E = ClassDecl->vbases_end(); VBase != E; ++VBase) { @@ -1481,27 +1510,14 @@ Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor, = AllBaseFields.lookup(VBase->getType()->getAs())) { AllToInit.push_back(Value); } else if (!AnyErrors) { - InitializedEntity InitEntity - = InitializedEntity::InitializeBase(Context, VBase); - InitializationKind InitKind - = InitializationKind::CreateDefault(Constructor->getLocation()); - InitializationSequence InitSeq(*this, InitEntity, InitKind, 0, 0); - OwningExprResult BaseInit = InitSeq.Perform(*this, InitEntity, InitKind, - MultiExprArg(*this, 0, 0)); - BaseInit = MaybeCreateCXXExprWithTemporaries(move(BaseInit)); - if (BaseInit.isInvalid()) { + CXXBaseOrMemberInitializer *CXXBaseInit = + BuildImplicitBaseInitializer(*this, Constructor, VBase); + + if (!CXXBaseInit) { HadError = true; continue; } - - CXXBaseOrMemberInitializer *CXXBaseInit = - new (Context) CXXBaseOrMemberInitializer(Context, - Context.getTrivialTypeSourceInfo(VBase->getType(), - SourceLocation()), - /*IsVirtual=*/true, - SourceLocation(), - BaseInit.takeAs(), - SourceLocation()); + AllToInit.push_back(CXXBaseInit); } } @@ -1516,27 +1532,14 @@ Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor, = AllBaseFields.lookup(Base->getType()->getAs())) { AllToInit.push_back(Value); } else if (!AnyErrors) { - InitializedEntity InitEntity - = InitializedEntity::InitializeBase(Context, Base); - InitializationKind InitKind - = InitializationKind::CreateDefault(Constructor->getLocation()); - InitializationSequence InitSeq(*this, InitEntity, InitKind, 0, 0); - OwningExprResult BaseInit = InitSeq.Perform(*this, InitEntity, InitKind, - MultiExprArg(*this, 0, 0)); - BaseInit = MaybeCreateCXXExprWithTemporaries(move(BaseInit)); - if (BaseInit.isInvalid()) { + CXXBaseOrMemberInitializer *CXXBaseInit = + BuildImplicitBaseInitializer(*this, Constructor, Base); + + if (!CXXBaseInit) { HadError = true; continue; } - CXXBaseOrMemberInitializer *CXXBaseInit = - new (Context) CXXBaseOrMemberInitializer(Context, - Context.getTrivialTypeSourceInfo(Base->getType(), - SourceLocation()), - /*IsVirtual=*/false, - SourceLocation(), - BaseInit.takeAs(), - SourceLocation()); AllToInit.push_back(CXXBaseInit); } } -- 2.40.0