Skip to content

Commit 5213f80

Browse files
committed
IDE: Remove uses of AbstractFunctionDecl::getParameterLists()
1 parent 3a6fa6b commit 5213f80

File tree

9 files changed

+55
-71
lines changed

9 files changed

+55
-71
lines changed

lib/IDE/CodeCompletion.cpp

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2148,8 +2148,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
21482148
static bool hasInterestingDefaultValues(const AbstractFunctionDecl *func) {
21492149
if (!func) return false;
21502150

2151-
bool isMemberOfType = func->getDeclContext()->isTypeContext();
2152-
for (auto param : *func->getParameterList(isMemberOfType ? 1 : 0)) {
2151+
for (auto param : *func->getParameters()) {
21532152
switch (param->getDefaultArgumentKind()) {
21542153
case DefaultArgumentKind::Normal:
21552154
case DefaultArgumentKind::Inherited: // FIXME: include this?
@@ -2168,18 +2167,21 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
21682167
bool includeDefaultArgs = true) {
21692168

21702169
const ParameterList *BodyParams = nullptr;
2170+
const ParamDecl *SelfDecl = nullptr;
2171+
21712172
if (AFD) {
2172-
BodyParams = AFD->getParameterList(AFD->getImplicitSelfDecl() ? 1 : 0);
2173+
BodyParams = AFD->getParameters();
21732174

21742175
// FIXME: Hack because we don't know which parameter list we're
21752176
// actually working with.
21762177
const unsigned expectedNumParams = AFT->getParams().size();
21772178
if (expectedNumParams != BodyParams->size()) {
2179+
BodyParams = nullptr;
2180+
21782181
// Adjust to the "self" list if that is present, otherwise give up.
21792182
if (expectedNumParams == 1 && AFD->getImplicitSelfDecl())
2180-
BodyParams = AFD->getParameterList(0);
2181-
else
2182-
BodyParams = nullptr;
2183+
SelfDecl = AFD->getImplicitSelfDecl();
2184+
BodyParams = nullptr;
21832185
}
21842186
}
21852187

@@ -2228,8 +2230,9 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
22282230

22292231
if (NeedComma)
22302232
Builder.addComma();
2231-
if (BodyParams) {
2232-
auto *PD = BodyParams->get(i);
2233+
if (BodyParams || SelfDecl) {
2234+
auto *PD = (BodyParams ? BodyParams->get(i) : SelfDecl);
2235+
22332236
// If we have a local name for the parameter, pass in that as well.
22342237
auto argName = PD->getArgumentName();
22352238
auto bodyName = PD->getName();
@@ -2395,13 +2398,23 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
23952398
StringRef Name = FD->getName().get();
23962399
assert(!Name.empty() && "name should not be empty");
23972400

2398-
unsigned FirstIndex = 0;
2399-
if (!IsImplicitlyCurriedInstanceMethod && FD->getImplicitSelfDecl())
2400-
FirstIndex = 1;
24012401
Type FunctionType = getTypeOfMember(FD);
24022402
assert(FunctionType);
2403-
if (FirstIndex != 0 && FunctionType->is<AnyFunctionType>())
2404-
FunctionType = FunctionType->castTo<AnyFunctionType>()->getResult();
2403+
2404+
unsigned NumParamLists;
2405+
if (FD->getImplicitSelfDecl()) {
2406+
if (IsImplicitlyCurriedInstanceMethod)
2407+
NumParamLists = 2;
2408+
else {
2409+
NumParamLists = 1;
2410+
2411+
// Strip off 'self'
2412+
if (FunctionType->is<AnyFunctionType>())
2413+
FunctionType = FunctionType->castTo<AnyFunctionType>()->getResult();
2414+
}
2415+
} else {
2416+
NumParamLists = 1;
2417+
}
24052418

24062419
bool trivialTrailingClosure = false;
24072420
if (!IsImplicitlyCurriedInstanceMethod &&
@@ -2458,8 +2471,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
24582471
// Build type annotation.
24592472
{
24602473
llvm::raw_svector_ostream OS(TypeStr);
2461-
for (unsigned i = FirstIndex + 1, e = FD->getParameterLists().size();
2462-
i != e; ++i) {
2474+
for (unsigned i = 0; i < NumParamLists - 1; ++i) {
24632475
ResultType->castTo<AnyFunctionType>()->printParams(OS);
24642476
ResultType = ResultType->castTo<AnyFunctionType>()->getResult();
24652477
OS << " -> ";

lib/IDE/Formatting.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -601,12 +601,9 @@ class FormatWalker : public SourceEntityWalker {
601601

602602
if (auto AFD = dyn_cast_or_null<AbstractFunctionDecl>(Node.dyn_cast<Decl*>())) {
603603
// Function parameters are siblings.
604-
for (auto P : AFD->getParameterLists()) {
605-
for (ParamDecl* param : *P) {
606-
if (!param->isSelfParameter())
607-
addPair(param->getEndLoc(), FindAlignLoc(param->getStartLoc()),
608-
tok::comma);
609-
}
604+
for (auto *param : *AFD->getParameters()) {
605+
addPair(param->getEndLoc(), FindAlignLoc(param->getStartLoc()),
606+
tok::comma);
610607
}
611608
}
612609

lib/IDE/SourceEntityWalker.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,8 @@ bool SemaAnnotator::walkToDeclPre(Decl *D) {
118118
};
119119

120120
if (auto AF = dyn_cast<AbstractFunctionDecl>(VD)) {
121-
for (auto *PL : AF->getParameterLists())
122-
if (ReportParamList(PL))
123-
return false;
121+
if (ReportParamList(AF->getParameters()))
122+
return false;
124123
}
125124
if (auto SD = dyn_cast<SubscriptDecl>(VD)) {
126125
if (ReportParamList(SD->getIndices()))

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,8 @@ bool NameMatcher::walkToDeclPre(Decl *D) {
380380
} else if (AbstractFunctionDecl *AFD = dyn_cast<AbstractFunctionDecl>(D)) {
381381
std::vector<CharSourceRange> LabelRanges;
382382
if (AFD->getNameLoc() == nextLoc()) {
383-
for(auto ParamList: AFD->getParameterLists()) {
384-
LabelRanges = getLabelRanges(ParamList, getSourceMgr());
385-
if (LabelRanges.size() == ParamList->size())
386-
break;
387-
}
383+
auto ParamList = AFD->getParameters();
384+
LabelRanges = getLabelRanges(ParamList, getSourceMgr());
388385
}
389386
tryResolve(ASTWalker::ParentTy(D), D->getLoc(), LabelRangeType::Param,
390387
LabelRanges);

lib/Index/Index.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,8 @@ bool IndexSwiftASTWalker::initFuncDeclIndexSymbol(FuncDecl *D,
10281028

10291029
if (D->getAttrs().hasAttribute<IBActionAttr>()) {
10301030
// Relate with type of the first parameter using RelationIBTypeOf.
1031-
if (D->getParameterLists().size() >= 2) {
1032-
auto paramList = D->getParameterList(1);
1031+
if (D->getImplicitSelfDecl()) {
1032+
auto paramList = D->getParameters();
10331033
if (!paramList->getArray().empty()) {
10341034
auto param = paramList->get(0);
10351035
if (auto nominal = param->getType()->getAnyNominal()) {

lib/Index/IndexSymbol.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ static bool isUnitTest(const ValueDecl *D) {
6262
return false;
6363

6464
// 4. ...takes no parameters...
65-
if (FD->getParameterLists().size() != 2)
66-
return false;
67-
if (FD->getParameterList(1)->size() != 0)
65+
if (FD->getParameters()->size() != 0)
6866
return false;
6967

7068
// 5. ...is of at least 'internal' access (unless we can use

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,9 @@ class ChildIndexFinder : public TypeReprVisitor<ChildIndexFinder, FoundResult> {
7171
return {SourceRange(), false, false, false};
7272
}
7373

74-
for (auto *Params: Parent->getParameterLists()) {
75-
for (auto *Param: Params->getArray()) {
76-
if (Param->isImplicit())
77-
continue;
78-
if (!--NextIndex) {
79-
return findChild(Param->getTypeLoc());
80-
}
74+
for (auto *Param: *Parent->getParameters()) {
75+
if (!--NextIndex) {
76+
return findChild(Param->getTypeLoc());
8177
}
8278
}
8379
llvm_unreachable("child index out of bounds");
@@ -1131,13 +1127,8 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
11311127

11321128
static void collectParamters(AbstractFunctionDecl *AFD,
11331129
SmallVectorImpl<ParamDecl*> &Results) {
1134-
for (auto PL : AFD->getParameterLists()) {
1135-
for (auto *PD: *PL) {
1136-
// Self parameter should not be updated.
1137-
if (PD->isSelfParameter())
1138-
continue;
1139-
Results.push_back(PD);
1140-
}
1130+
for (auto PD : *AFD->getParameters()) {
1131+
Results.push_back(PD);
11411132
}
11421133
}
11431134

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -839,19 +839,13 @@ static void addParameters(const AbstractFunctionDecl *FD,
839839
TextEntity &Ent,
840840
SourceManager &SM,
841841
unsigned BufferID) {
842-
auto params = FD->getParameterLists();
843-
// Ignore 'self'.
844-
if (FD->getDeclContext()->isTypeContext())
845-
params = params.slice(1);
846-
847842
ArrayRef<Identifier> ArgNames;
848843
DeclName Name = FD->getFullName();
849844
if (Name) {
850845
ArgNames = Name.getArgumentNames();
851846
}
852-
for (auto paramList : params) {
853-
addParameters(ArgNames, paramList, Ent, SM, BufferID);
854-
}
847+
auto paramList = FD->getParameters();
848+
addParameters(ArgNames, paramList, Ent, SM, BufferID);
855849
}
856850

857851
static void addParameters(const SubscriptDecl *D,

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,20 +1475,16 @@ static SDKNode *constructTypeNode(SDKContext &Ctx, Type T,
14751475
}
14761476

14771477
static std::vector<SDKNode*>
1478-
createParameterNodes(SDKContext &Ctx, ArrayRef<ParameterList*> AllParamLists) {
1478+
createParameterNodes(SDKContext &Ctx, ParameterList *PL) {
14791479
std::vector<SDKNode*> Result;
1480-
for (auto PL: AllParamLists) {
1481-
for (auto param: *PL) {
1482-
if (param->isSelfParameter())
1483-
continue;
1484-
TypeInitInfo TypeInfo;
1485-
TypeInfo.IsImplicitlyUnwrappedOptional = param->getAttrs().
1486-
hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
1487-
TypeInfo.hasDefaultArgument = param->getDefaultArgumentKind() !=
1488-
DefaultArgumentKind::None;
1489-
Result.push_back(constructTypeNode(Ctx, param->getInterfaceType(),
1490-
TypeInfo));
1491-
}
1480+
for (auto param: *PL) {
1481+
TypeInitInfo TypeInfo;
1482+
TypeInfo.IsImplicitlyUnwrappedOptional = param->getAttrs().
1483+
hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
1484+
TypeInfo.hasDefaultArgument = param->getDefaultArgumentKind() !=
1485+
DefaultArgumentKind::None;
1486+
Result.push_back(constructTypeNode(Ctx, param->getInterfaceType(),
1487+
TypeInfo));
14921488
}
14931489
return Result;
14941490
}
@@ -1504,15 +1500,15 @@ static SDKNode *constructFunctionNode(SDKContext &Ctx, FuncDecl* FD,
15041500
TypeInfo.IsImplicitlyUnwrappedOptional = FD->getAttrs().
15051501
hasAttribute<ImplicitlyUnwrappedOptionalAttr>();
15061502
Func->addChild(constructTypeNode(Ctx, FD->getResultInterfaceType(), TypeInfo));
1507-
for (auto *Node : createParameterNodes(Ctx, FD->getParameterLists()))
1503+
for (auto *Node : createParameterNodes(Ctx, FD->getParameters()))
15081504
Func->addChild(Node);
15091505
return Func;
15101506
}
15111507

15121508
static SDKNode* constructInitNode(SDKContext &Ctx, ConstructorDecl *CD) {
15131509
auto Func = SDKNodeInitInfo(Ctx, CD).createSDKNode(SDKNodeKind::DeclConstructor);
15141510
Func->addChild(constructTypeNode(Ctx, CD->getResultInterfaceType()));
1515-
for (auto *Node : createParameterNodes(Ctx, CD->getParameterLists()))
1511+
for (auto *Node : createParameterNodes(Ctx, CD->getParameters()))
15161512
Func->addChild(Node);
15171513
return Func;
15181514
}

0 commit comments

Comments
 (0)