@@ -1316,8 +1316,7 @@ bool Decl::hasUnderscoredNaming() const {
1316
1316
// underscore, it's a private function or subscript.
1317
1317
if (isa<AbstractFunctionDecl>(D) || isa<SubscriptDecl>(D)) {
1318
1318
const auto VD = cast<ValueDecl>(D);
1319
- if (getParameterList(const_cast<ValueDecl *>(VD))
1320
- ->hasInternalParameter("_")) {
1319
+ if (VD->getParameterList()->hasInternalParameter("_")) {
1321
1320
return true;
1322
1321
}
1323
1322
}
@@ -4096,6 +4095,26 @@ ValueDecl::getCachedOpaqueResultTypeDecl() const {
4096
4095
.getCachedResult();
4097
4096
}
4098
4097
4098
+ ParameterList *ValueDecl::getParameterList() {
4099
+ if (auto *function = dyn_cast<AbstractFunctionDecl>(this)) {
4100
+ return function->getParameters();
4101
+ } else if (auto *enumElement = dyn_cast<EnumElementDecl>(this)) {
4102
+ return enumElement->getParameterList();
4103
+ } else if (auto *subscript = dyn_cast<SubscriptDecl>(this)) {
4104
+ return subscript->getIndices();
4105
+ } else if (auto *macro = dyn_cast<MacroDecl>(this)) {
4106
+ return macro->parameterList;
4107
+ }
4108
+
4109
+ return nullptr;
4110
+ }
4111
+
4112
+ const ParameterList *ValueDecl::getParameterList() const {
4113
+ return const_cast<ValueDecl *>(this)->getParameterList();
4114
+ }
4115
+
4116
+ bool ValueDecl::hasParameterList() const { return (bool)getParameterList(); }
4117
+
4099
4118
bool ValueDecl::isObjC() const {
4100
4119
ASTContext &ctx = getASTContext();
4101
4120
return evaluateOrDefault(ctx.evaluator,
@@ -9578,24 +9597,10 @@ DeclName AbstractFunctionDecl::getEffectiveFullName() const {
9578
9597
return DeclName();
9579
9598
}
9580
9599
9581
- ParameterList *swift::getParameterList(ValueDecl *source) {
9582
- if (auto *AFD = dyn_cast<AbstractFunctionDecl>(source)) {
9583
- return AFD->getParameters();
9584
- } else if (auto *EED = dyn_cast<EnumElementDecl>(source)) {
9585
- return EED->getParameterList();
9586
- } else if (auto *SD = dyn_cast<SubscriptDecl>(source)) {
9587
- return SD->getIndices();
9588
- } else if (auto *MD = dyn_cast<MacroDecl>(source)) {
9589
- return MD->parameterList;
9590
- }
9591
-
9592
- return nullptr;
9593
- }
9594
-
9595
9600
ParameterList *swift::getParameterList(DeclContext *source) {
9596
9601
if (auto *D = source->getAsDecl()) {
9597
9602
if (auto *VD = dyn_cast<ValueDecl>(D)) {
9598
- return getParameterList(VD );
9603
+ return VD-> getParameterList();
9599
9604
}
9600
9605
} else if (auto *CE = dyn_cast<AbstractClosureExpr>(source)) {
9601
9606
return CE->getParameters();
@@ -9607,7 +9612,7 @@ ParameterList *swift::getParameterList(DeclContext *source) {
9607
9612
const ParamDecl *swift::getParameterAt(ConcreteDeclRef declRef,
9608
9613
unsigned index) {
9609
9614
auto *source = declRef.getDecl();
9610
- if (auto *params = getParameterList(const_cast<ValueDecl *>(source) )) {
9615
+ if (auto *params = source-> getParameterList()) {
9611
9616
unsigned origIndex = params->getOrigParamIndex(declRef.getSubstitutions(),
9612
9617
index);
9613
9618
return params->get(origIndex);
@@ -9617,7 +9622,7 @@ const ParamDecl *swift::getParameterAt(ConcreteDeclRef declRef,
9617
9622
9618
9623
const ParamDecl *swift::getParameterAt(const ValueDecl *source,
9619
9624
unsigned index) {
9620
- if (auto *params = getParameterList(const_cast<ValueDecl *>(source) )) {
9625
+ if (auto *params = source-> getParameterList()) {
9621
9626
return index < params->size() ? params->get(index) : nullptr;
9622
9627
}
9623
9628
return nullptr;
0 commit comments