Centralize the definition of isMemberwiseInitialized()

This utility was defined in Sema, used in Sema and Index, declared in
two headers, and semi- copy-pasted into SILGen. Pull it into
VarDecl::isMemberwiseInitialized() and use it consistently.
This commit is contained in:
Doug Gregor
2019-04-29 10:30:38 -07:00
parent 209e7fcd83
commit 1a169b91bd
8 changed files with 43 additions and 39 deletions

View File

@@ -5254,6 +5254,30 @@ bool VarDecl::isSelfParameter() const {
return false;
}
bool VarDecl::isMemberwiseInitialized() const {
if (!getDeclContext()->isTypeContext())
return false;
// Implicit, computed, and static properties are not initialized.
// The exception is lazy properties, which due to batch mode we may or
// may not have yet finalized, so they may currently be "stored" or
// "computed" in the current AST state.
if (isImplicit() || isStatic())
return false;
if (!hasStorage() && !getAttrs().hasAttribute<LazyAttr>() &&
!getAttachedPropertyDelegate())
return false;
// Initialized 'let' properties have storage, but don't get an argument
// to the memberwise initializer since they already have an initial
// value that cannot be overridden.
if (isLet() && isParentInitialized())
return false;
return true;
}
void VarDecl::setSpecifier(Specifier specifier) {
Bits.VarDecl.Specifier = static_cast<unsigned>(specifier);
setSupportsMutationIfStillStored(