Skip to content

Commit fc3bc76

Browse files
committed
ASTScope: Hack it up for removal of multiple parameter lists
A better approach would be to split off ASTScopeKind::AbstractFunctionSelf from ASTScopeKind::AbstractFunctionParams, but for now, hack things up at the boundary to match the old behavior.
1 parent 5213f80 commit fc3bc76

File tree

1 file changed

+46
-24
lines changed

1 file changed

+46
-24
lines changed

lib/AST/ASTScope.cpp

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -617,27 +617,51 @@ ASTScope *ASTScope::createRoot(SourceFile *sourceFile) {
617617
return scope;
618618
}
619619

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+
620639
/// Find the parameter list and parameter index (into that list) corresponding
621640
/// to the next parameter.
622641
static Optional<std::pair<unsigned, unsigned>>
623642
findNextParameter(AbstractFunctionDecl *func, unsigned listIndex,
624643
unsigned paramIndex) {
625-
auto paramLists = func->getParameterLists();
626644
unsigned paramOffset = 1;
627-
while (listIndex < paramLists.size()) {
628-
auto currentList = paramLists[listIndex];
629645

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;
633654
}
634655

635-
// Move on to the next list.
636-
++listIndex;
637-
paramIndex = 0;
638-
paramOffset = 0;
656+
} else {
657+
if (listIndex > 0)
658+
return None;
639659
}
640660

661+
if (paramIndex + paramOffset < func->getParameters()->size())
662+
return std::make_pair(listIndex, paramIndex + paramOffset);
663+
664+
++listIndex;
641665
return None;
642666
}
643667

@@ -907,25 +931,23 @@ ASTScope *ASTScope::createIfNeeded(const ASTScope *parent, Decl *decl) {
907931
}
908932

909933
// 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;
911935
if (parent->getKind() == ASTScopeKind::AbstractFunctionParams &&
912936
parent->abstractFunctionParams.decl == decl) {
913937
nextParameter =
914938
findNextParameter(parent->abstractFunctionParams.decl,
915939
parent->abstractFunctionParams.listIndex,
916940
parent->abstractFunctionParams.paramIndex);
917941

918-
} else if (abstractFunction->getParameterList(0)->size() > 0) {
942+
} else if (abstractFunction->getImplicitSelfDecl() ||
943+
abstractFunction->getParameters()->size() > 0) {
919944
nextParameter = std::make_pair(0, 0);
920-
} else {
921-
nextParameter = findNextParameter(abstractFunction, 0, 0);
922945
}
923946

924947
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);
929951

930952
// Determine whether there is a default argument.
931953
ASTScope *defaultArgumentScope = nullptr;
@@ -1405,15 +1427,14 @@ SourceRange ASTScope::getSourceRangeImpl() const {
14051427
if (isa<DestructorDecl>(abstractFunctionParams.decl)) {
14061428
startLoc = abstractFunctionParams.decl->getNameLoc();
14071429
} else {
1408-
startLoc = abstractFunctionParams.decl->getParameterList(1)
1430+
startLoc = abstractFunctionParams.decl->getParameters()
14091431
->getLParenLoc();
14101432
}
14111433
return SourceRange(startLoc, endLoc);
14121434
}
14131435

14141436
// Otherwise, find the end of this parameter.
1415-
auto param = abstractFunctionParams.decl->getParameterList(
1416-
abstractFunctionParams.listIndex)
1437+
auto param = abstractFunctionParams.decl->getParameters()
14171438
->get(abstractFunctionParams.paramIndex);
14181439
return SourceRange(param->getEndLoc(), endLoc);
14191440
}
@@ -1754,9 +1775,10 @@ SmallVector<ValueDecl *, 4> ASTScope::getLocalBindings() const {
17541775
break;
17551776

17561777
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));
17601782
break;
17611783

17621784
case ASTScopeKind::AfterPatternBinding:

0 commit comments

Comments
 (0)