Skip to content

Commit 166a6b8

Browse files
committed
[SE-0258] Clean up some code repetition involving initialization forms.
1 parent 629766e commit 166a6b8

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

lib/AST/Decl.cpp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5489,12 +5489,13 @@ VarDecl *VarDecl::getPropertyWrapperBackingProperty() const {
54895489
return getPropertyWrapperBackingPropertyInfo().backingVar;
54905490
}
54915491

5492-
bool VarDecl::isPropertyWrapperInitializedWithInitialValue() const {
5493-
auto customAttrs = getAttachedPropertyWrappers();
5492+
static bool propertyWrapperInitializedViaInitialValue(
5493+
const VarDecl *var, bool checkDefaultInit) {
5494+
auto customAttrs = var->getAttachedPropertyWrappers();
54945495
if (customAttrs.empty())
54955496
return false;
54965497

5497-
auto *PBD = getParentPatternBinding();
5498+
auto *PBD = var->getParentPatternBinding();
54985499
if (!PBD)
54995500
return false;
55005501

@@ -5509,36 +5510,23 @@ bool VarDecl::isPropertyWrapperInitializedWithInitialValue() const {
55095510
return false;
55105511

55115512
// Default initialization does not use a value.
5512-
if (getAttachedPropertyWrapperTypeInfo(0).defaultInit)
5513+
if (checkDefaultInit &&
5514+
var->getAttachedPropertyWrapperTypeInfo(0).defaultInit)
55135515
return false;
55145516

55155517
// If all property wrappers have an initialValue initializer, the property
55165518
// wrapper will be initialized that way.
5517-
return allAttachedPropertyWrappersHaveInitialValueInit();
5519+
return var->allAttachedPropertyWrappersHaveInitialValueInit();
55185520
}
55195521

5520-
bool VarDecl::isPropertyMemberwiseInitializedWithWrappedType() const {
5521-
auto customAttrs = getAttachedPropertyWrappers();
5522-
if (customAttrs.empty())
5523-
return false;
5524-
5525-
auto *PBD = getParentPatternBinding();
5526-
if (!PBD)
5527-
return false;
5528-
5529-
// If there was an initializer on the original property, initialize
5530-
// via the initial value.
5531-
if (PBD->getPatternList()[0].getEqualLoc().isValid())
5532-
return true;
5533-
5534-
// If there was an initializer on the outermost wrapper, initialize
5535-
// via the full wrapper.
5536-
if (customAttrs[0]->getArg() != nullptr)
5537-
return false;
5522+
bool VarDecl::isPropertyWrapperInitializedWithInitialValue() const {
5523+
return propertyWrapperInitializedViaInitialValue(
5524+
this, /*checkDefaultInit=*/true);
5525+
}
55385526

5539-
// If all property wrappers have an initialValue initializer, the property
5540-
// wrapper will be initialized that way.
5541-
return allAttachedPropertyWrappersHaveInitialValueInit();
5527+
bool VarDecl::isPropertyMemberwiseInitializedWithWrappedType() const {
5528+
return propertyWrapperInitializedViaInitialValue(
5529+
this, /*checkDefaultInit=*/false);
55425530
}
55435531

55445532
Identifier VarDecl::getObjCPropertyName() const {

0 commit comments

Comments
 (0)