Skip to content

Commit df9f7f9

Browse files
committed
Parse: Remove uses of getParameterLists() from default argument parsing
1 parent dff56d8 commit df9f7f9

File tree

5 files changed

+13
-21
lines changed

5 files changed

+13
-21
lines changed

include/swift/AST/Initializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class DefaultArgumentInitializer : public Initializer {
167167
/// Change the parent of this context. This is necessary because
168168
/// the function signature is parsed before the function
169169
/// declaration/expression itself is built.
170-
void changeFunction(DeclContext *parent, ArrayRef<ParameterList *> paramLists);
170+
void changeFunction(DeclContext *parent, ParameterList *paramLists);
171171

172172
static bool classof(const DeclContext *DC) {
173173
if (auto init = dyn_cast<Initializer>(DC))

include/swift/Parse/Parser.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,10 +1009,10 @@ class Parser {
10091009

10101010
/// Set the parsed context for all the initializers to the given
10111011
/// function.
1012-
void setFunctionContext(DeclContext *DC, ArrayRef<ParameterList *> paramList);
1012+
void setFunctionContext(DeclContext *DC, ParameterList *paramList);
10131013

1014-
DefaultArgumentInfo(bool inTypeContext) {
1015-
NextIndex = inTypeContext ? 1 : 0;
1014+
DefaultArgumentInfo() {
1015+
NextIndex = 0;
10161016
HasDefaultArgument = false;
10171017
}
10181018
};

lib/AST/Decl.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4647,22 +4647,14 @@ void ParamDecl::setDefaultArgumentInitContext(Initializer *initContext) {
46474647
}
46484648

46494649
void DefaultArgumentInitializer::changeFunction(
4650-
DeclContext *parent, ArrayRef<ParameterList *> paramLists) {
4650+
DeclContext *parent, ParameterList *paramList) {
46514651
if (parent->isLocalContext()) {
46524652
setParent(parent);
46534653
}
46544654

4655-
unsigned offset = getIndex();
4656-
for (auto list : paramLists) {
4657-
if (offset < list->size()) {
4658-
auto param = list->get(offset);
4659-
if (param->getDefaultValue())
4660-
param->setDefaultArgumentInitContext(this);
4661-
return;
4662-
}
4663-
4664-
offset -= list->size();
4665-
}
4655+
auto param = paramList->get(getIndex());
4656+
if (param->getDefaultValue())
4657+
param->setDefaultArgumentInitContext(this);
46664658
}
46674659

46684660
/// Determine whether the given Swift type is an integral type, i.e.,

lib/Parse/ParseDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5255,7 +5255,7 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
52555255
if (HasContainerType)
52565256
SelfDecl = ParamDecl::createUnboundSelf(NameLoc, CurDeclContext);
52575257

5258-
DefaultArgumentInfo DefaultArgs(HasContainerType);
5258+
DefaultArgumentInfo DefaultArgs;
52595259
TypeRepr *FuncRetTy = nullptr;
52605260
DeclName FullName;
52615261
ParameterList *BodyParams;
@@ -5322,7 +5322,7 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
53225322
if (SignatureHasCodeCompletion)
53235323
CodeCompletion->setParsedDecl(FD);
53245324

5325-
DefaultArgs.setFunctionContext(FD, FD->getParameterLists());
5325+
DefaultArgs.setFunctionContext(FD, FD->getParameters());
53265326
if (auto *P = FD->getImplicitSelfDecl())
53275327
addToScope(P);
53285328
addParametersToScope(FD->getParameters());
@@ -6177,7 +6177,7 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
61776177
return makeParserCodeCompletionStatus();
61786178

61796179
// Parse the parameters.
6180-
DefaultArgumentInfo DefaultArgs(/*inTypeContext*/true);
6180+
DefaultArgumentInfo DefaultArgs;
61816181
llvm::SmallVector<Identifier, 4> namePieces;
61826182
bool SignatureHasCodeCompletion = false;
61836183
ParserResult<ParameterList> Params
@@ -6237,7 +6237,7 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
62376237

62386238
// No need to setLocalDiscriminator.
62396239

6240-
DefaultArgs.setFunctionContext(CD, CD->getParameterLists());
6240+
DefaultArgs.setFunctionContext(CD, CD->getParameters());
62416241

62426242
// Pass the function signature to code completion.
62436243
if (SignatureHasCodeCompletion)

lib/Parse/ParsePattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ static DefaultArgumentKind getDefaultArgKind(Expr *init) {
5757
}
5858

5959
void Parser::DefaultArgumentInfo::setFunctionContext(
60-
DeclContext *DC, ArrayRef<ParameterList *> paramList){
60+
DeclContext *DC, ParameterList *paramList){
6161
for (auto context : ParsedContexts) {
6262
context->changeFunction(DC, paramList);
6363
}

0 commit comments

Comments
 (0)