@@ -617,27 +617,51 @@ ASTScope *ASTScope::createRoot(SourceFile *sourceFile) {
617
617
return scope;
618
618
}
619
619
620
+ // FIXME: This is a vestige of multiple parameter lists.
621
+ static ParamDecl *getParameter (AbstractFunctionDecl *func,
622
+ unsigned listIndex,
623
+ unsigned paramIndex) {
624
+ // Dig out the actual parameter.
625
+ if (auto *selfDecl = func->getImplicitSelfDecl ()) {
626
+ if (listIndex == 0 ) {
627
+ assert (paramIndex == 0 );
628
+ return selfDecl;
629
+ }
630
+
631
+ assert (listIndex == 1 );
632
+ return func->getParameters ()->get (paramIndex);
633
+ }
634
+
635
+ assert (listIndex == 0 );
636
+ return func->getParameters ()->get (paramIndex);
637
+ }
638
+
620
639
// / Find the parameter list and parameter index (into that list) corresponding
621
640
// / to the next parameter.
622
641
static Optional<std::pair<unsigned , unsigned >>
623
642
findNextParameter (AbstractFunctionDecl *func, unsigned listIndex,
624
643
unsigned paramIndex) {
625
- auto paramLists = func->getParameterLists ();
626
644
unsigned paramOffset = 1 ;
627
- while (listIndex < paramLists.size ()) {
628
- auto currentList = paramLists[listIndex];
629
645
630
- // If there is a parameter in this list, return it.
631
- if (paramIndex + paramOffset < currentList->size ()) {
632
- return std::make_pair (listIndex, paramIndex + paramOffset);
646
+ if (func->getImplicitSelfDecl ()) {
647
+ if (listIndex > 1 )
648
+ return None;
649
+
650
+ if (listIndex == 0 ) {
651
+ ++listIndex;
652
+ paramIndex = 0 ;
653
+ paramOffset = 0 ;
633
654
}
634
655
635
- // Move on to the next list.
636
- ++listIndex;
637
- paramIndex = 0 ;
638
- paramOffset = 0 ;
656
+ } else {
657
+ if (listIndex > 0 )
658
+ return None;
639
659
}
640
660
661
+ if (paramIndex + paramOffset < func->getParameters ()->size ())
662
+ return std::make_pair (listIndex, paramIndex + paramOffset);
663
+
664
+ ++listIndex;
641
665
return None;
642
666
}
643
667
@@ -907,25 +931,23 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Decl *decl) {
907
931
}
908
932
909
933
// Figure out which parameter is next is the next one down.
910
- Optional<std::pair<unsigned , unsigned >> nextParameter;
934
+ Optional<std::pair<unsigned , unsigned >> nextParameter = None ;
911
935
if (parent->getKind () == ASTScopeKind::AbstractFunctionParams &&
912
936
parent->abstractFunctionParams .decl == decl) {
913
937
nextParameter =
914
938
findNextParameter (parent->abstractFunctionParams .decl ,
915
939
parent->abstractFunctionParams .listIndex ,
916
940
parent->abstractFunctionParams .paramIndex );
917
941
918
- } else if (abstractFunction->getParameterList (0 )->size () > 0 ) {
942
+ } else if (abstractFunction->getImplicitSelfDecl () ||
943
+ abstractFunction->getParameters ()->size () > 0 ) {
919
944
nextParameter = std::make_pair (0 , 0 );
920
- } else {
921
- nextParameter = findNextParameter (abstractFunction, 0 , 0 );
922
945
}
923
946
924
947
if (nextParameter) {
925
- // Dig out the actual parameter.
926
- ParamDecl *currentParam =
927
- abstractFunction->getParameterList (nextParameter->first )
928
- ->get (nextParameter->second );
948
+ auto *currentParam = getParameter (abstractFunction,
949
+ nextParameter->first ,
950
+ nextParameter->second );
929
951
930
952
// Determine whether there is a default argument.
931
953
ASTScope *defaultArgumentScope = nullptr ;
@@ -1405,15 +1427,14 @@ SourceRange ASTScope::getSourceRangeImpl() const {
1405
1427
if (isa<DestructorDecl>(abstractFunctionParams.decl )) {
1406
1428
startLoc = abstractFunctionParams.decl ->getNameLoc ();
1407
1429
} else {
1408
- startLoc = abstractFunctionParams.decl ->getParameterList ( 1 )
1430
+ startLoc = abstractFunctionParams.decl ->getParameters ( )
1409
1431
->getLParenLoc ();
1410
1432
}
1411
1433
return SourceRange (startLoc, endLoc);
1412
1434
}
1413
1435
1414
1436
// Otherwise, find the end of this parameter.
1415
- auto param = abstractFunctionParams.decl ->getParameterList (
1416
- abstractFunctionParams.listIndex )
1437
+ auto param = abstractFunctionParams.decl ->getParameters ()
1417
1438
->get (abstractFunctionParams.paramIndex );
1418
1439
return SourceRange (param->getEndLoc (), endLoc);
1419
1440
}
@@ -1754,9 +1775,10 @@ SmallVector<ValueDecl *, 4> ASTScope::getLocalBindings() const {
1754
1775
break ;
1755
1776
1756
1777
case ASTScopeKind::AbstractFunctionParams:
1757
- result.push_back (abstractFunctionParams.decl ->getParameterList (
1758
- abstractFunctionParams.listIndex )
1759
- ->get (abstractFunctionParams.paramIndex ));
1778
+ result.push_back (
1779
+ getParameter (abstractFunctionParams.decl ,
1780
+ abstractFunctionParams.listIndex ,
1781
+ abstractFunctionParams.paramIndex ));
1760
1782
break ;
1761
1783
1762
1784
case ASTScopeKind::AfterPatternBinding:
0 commit comments