@@ -1337,8 +1337,7 @@ bool Decl::hasUnderscoredNaming() const {
1337
1337
// underscore, it's a private function or subscript.
1338
1338
if (isa<AbstractFunctionDecl>(D) || isa<SubscriptDecl>(D)) {
1339
1339
const auto VD = cast<ValueDecl>(D);
1340
- if (getParameterList (const_cast <ValueDecl *>(VD))
1341
- ->hasInternalParameter (" _" )) {
1340
+ if (VD->getParameterList ()->hasInternalParameter (" _" )) {
1342
1341
return true ;
1343
1342
}
1344
1343
}
@@ -4117,6 +4116,26 @@ ValueDecl::getCachedOpaqueResultTypeDecl() const {
4117
4116
.getCachedResult ();
4118
4117
}
4119
4118
4119
+ ParameterList *ValueDecl::getParameterList () {
4120
+ if (auto *function = dyn_cast<AbstractFunctionDecl>(this )) {
4121
+ return function->getParameters ();
4122
+ } else if (auto *enumElement = dyn_cast<EnumElementDecl>(this )) {
4123
+ return enumElement->getParameterList ();
4124
+ } else if (auto *subscript = dyn_cast<SubscriptDecl>(this )) {
4125
+ return subscript->getIndices ();
4126
+ } else if (auto *macro = dyn_cast<MacroDecl>(this )) {
4127
+ return macro->parameterList ;
4128
+ }
4129
+
4130
+ return nullptr ;
4131
+ }
4132
+
4133
+ const ParameterList *ValueDecl::getParameterList () const {
4134
+ return const_cast <ValueDecl *>(this )->getParameterList ();
4135
+ }
4136
+
4137
+ bool ValueDecl::hasParameterList () const { return (bool )getParameterList (); }
4138
+
4120
4139
bool ValueDecl::isObjC () const {
4121
4140
ASTContext &ctx = getASTContext ();
4122
4141
return evaluateOrDefault (ctx.evaluator ,
@@ -4182,6 +4201,24 @@ bool ValueDecl::isDynamic() const {
4182
4201
getAttrs ().hasAttribute <DynamicAttr>());
4183
4202
}
4184
4203
4204
+ bool ValueDecl::isAsync () const {
4205
+ if (auto *function = dyn_cast<AbstractFunctionDecl>(this )) {
4206
+ return function->hasAsync ();
4207
+ }
4208
+
4209
+ // Async storage declarations must be get-only. Don't consider it async
4210
+ // otherwise, even if it has an async getter.
4211
+ if (auto *storage = dyn_cast<AbstractStorageDecl>(this )) {
4212
+ if (storage->getAllAccessors ().size () == 1 ) {
4213
+ if (auto *getter = storage->getAccessor (AccessorKind::Get)) {
4214
+ return getter->hasAsync ();
4215
+ }
4216
+ }
4217
+ }
4218
+
4219
+ return false ;
4220
+ }
4221
+
4185
4222
bool ValueDecl::isObjCDynamicInGenericClass () const {
4186
4223
if (!isObjCDynamic ())
4187
4224
return false ;
@@ -9599,24 +9636,10 @@ DeclName AbstractFunctionDecl::getEffectiveFullName() const {
9599
9636
return DeclName ();
9600
9637
}
9601
9638
9602
- ParameterList *swift::getParameterList (ValueDecl *source) {
9603
- if (auto *AFD = dyn_cast<AbstractFunctionDecl>(source)) {
9604
- return AFD->getParameters ();
9605
- } else if (auto *EED = dyn_cast<EnumElementDecl>(source)) {
9606
- return EED->getParameterList ();
9607
- } else if (auto *SD = dyn_cast<SubscriptDecl>(source)) {
9608
- return SD->getIndices ();
9609
- } else if (auto *MD = dyn_cast<MacroDecl>(source)) {
9610
- return MD->parameterList ;
9611
- }
9612
-
9613
- return nullptr ;
9614
- }
9615
-
9616
9639
ParameterList *swift::getParameterList (DeclContext *source) {
9617
9640
if (auto *D = source->getAsDecl ()) {
9618
9641
if (auto *VD = dyn_cast<ValueDecl>(D)) {
9619
- return getParameterList (VD );
9642
+ return VD-> getParameterList ();
9620
9643
}
9621
9644
} else if (auto *CE = dyn_cast<AbstractClosureExpr>(source)) {
9622
9645
return CE->getParameters ();
@@ -9628,7 +9651,7 @@ ParameterList *swift::getParameterList(DeclContext *source) {
9628
9651
const ParamDecl *swift::getParameterAt (ConcreteDeclRef declRef,
9629
9652
unsigned index) {
9630
9653
auto *source = declRef.getDecl ();
9631
- if (auto *params = getParameterList (const_cast <ValueDecl *>(source) )) {
9654
+ if (auto *params = source-> getParameterList ()) {
9632
9655
unsigned origIndex = params->getOrigParamIndex (declRef.getSubstitutions (),
9633
9656
index);
9634
9657
return params->get (origIndex);
@@ -9638,7 +9661,7 @@ const ParamDecl *swift::getParameterAt(ConcreteDeclRef declRef,
9638
9661
9639
9662
const ParamDecl *swift::getParameterAt (const ValueDecl *source,
9640
9663
unsigned index) {
9641
- if (auto *params = getParameterList (const_cast <ValueDecl *>(source) )) {
9664
+ if (auto *params = source-> getParameterList ()) {
9642
9665
return index < params->size () ? params->get (index) : nullptr ;
9643
9666
}
9644
9667
return nullptr ;
0 commit comments