aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDeclCXX.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2010-04-20 23:11:20 +0000
committerAnders Carlsson <andersca@mac.com>2010-04-20 23:11:20 +0000
commit84688f2a21bfde3cfdf1c41a053ef7b774d4cd0c (patch)
tree14a9d40506959eb049204cc5e3adc006a12a08c5 /lib/Sema/SemaDeclCXX.cpp
parent876681e706287d23ce45ea5bf715514da9e9212d (diff)
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
Diffstat (limited to 'lib/Sema/SemaDeclCXX.cpp')
-rw-r--r--lib/Sema/SemaDeclCXX.cpp77
1 files 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<Expr>(),
+ SourceLocation());
+
+ return CXXBaseInit;
+}
+
bool
Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor,
CXXBaseOrMemberInitializer **Initializers,
@@ -1471,8 +1502,6 @@ Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor,
AllBaseFields[Member->getMember()] = Member;
}
- llvm::SmallVector<CXXBaseSpecifier *, 4> 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<RecordType>())) {
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<Expr>(),
- SourceLocation());
+
AllToInit.push_back(CXXBaseInit);
}
}
@@ -1516,27 +1532,14 @@ Sema::SetBaseOrMemberInitializers(CXXConstructorDecl *Constructor,
= AllBaseFields.lookup(Base->getType()->getAs<RecordType>())) {
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<Expr>(),
- SourceLocation());
AllToInit.push_back(CXXBaseInit);
}
}