From 8fdb48d91029270201a1fac73faa3c2023d3e28c Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Fri, 15 Dec 2023 19:53:52 +0000 Subject: [PATCH] [AST] Rename `SubscriptDecl::create` -> `createParsed` And generate the DeclName using the argument labels on the ParameterList. --- include/swift/AST/Decl.h | 13 ++++++------- lib/AST/Decl.cpp | 13 ++++++------- lib/Parse/ParseDecl.cpp | 15 ++++++--------- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h index 6d4b9082537..5d8ddaa0e38 100644 --- a/include/swift/AST/Decl.h +++ b/include/swift/AST/Decl.h @@ -6843,13 +6843,12 @@ public: Type ElementTy, DeclContext *Parent, GenericParamList *GenericParams); - static SubscriptDecl *create(ASTContext &Context, DeclName Name, - SourceLoc StaticLoc, - StaticSpellingKind StaticSpelling, - SourceLoc SubscriptLoc, ParameterList *Indices, - SourceLoc ArrowLoc, TypeRepr *ElementTyR, - DeclContext *Parent, - GenericParamList *GenericParams); + static SubscriptDecl *createParsed(ASTContext &Context, SourceLoc StaticLoc, + StaticSpellingKind StaticSpelling, + SourceLoc SubscriptLoc, + ParameterList *Indices, SourceLoc ArrowLoc, + TypeRepr *ElementTyR, DeclContext *Parent, + GenericParamList *GenericParams); static SubscriptDecl *create(ASTContext &Context, DeclName Name, SourceLoc StaticLoc, diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 078b2b382ea..a9a8da9c062 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -8812,14 +8812,13 @@ SubscriptDecl::createDeserialized(ASTContext &Context, DeclName Name, return SD; } -SubscriptDecl *SubscriptDecl::create(ASTContext &Context, DeclName Name, - SourceLoc StaticLoc, - StaticSpellingKind StaticSpelling, - SourceLoc SubscriptLoc, - ParameterList *Indices, SourceLoc ArrowLoc, - TypeRepr *ElementTyR, DeclContext *Parent, - GenericParamList *GenericParams) { +SubscriptDecl *SubscriptDecl::createParsed( + ASTContext &Context, SourceLoc StaticLoc, StaticSpellingKind StaticSpelling, + SourceLoc SubscriptLoc, ParameterList *Indices, SourceLoc ArrowLoc, + TypeRepr *ElementTyR, DeclContext *Parent, + GenericParamList *GenericParams) { assert(ElementTyR); + auto Name = DeclName(Context, DeclBaseName::createSubscript(), Indices); auto *const SD = new (Context) SubscriptDecl(Name, StaticLoc, StaticSpelling, SubscriptLoc, Indices, ArrowLoc, ElementTyR, Parent, GenericParams); diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index a45ad4a2381..d4692124585 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -9508,10 +9508,9 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc, // Parse the parameter list. DefaultArgumentInfo DefaultArgs; - SmallVector argumentNames; - ParserResult Indices - = parseSingleParameterClause(ParameterContextKind::Subscript, - &argumentNames, &DefaultArgs); + ParserResult Indices = + parseSingleParameterClause(ParameterContextKind::Subscript, + /*argumentNamesOut*/ nullptr, &DefaultArgs); Status |= Indices; if (Status.hasCodeCompletion() && !CodeCompletionCallbacks) return Status; @@ -9554,11 +9553,9 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc, } // Build an AST for the subscript declaration. - DeclName name = DeclName(Context, DeclBaseName::createSubscript(), - argumentNames); - auto *const Subscript = SubscriptDecl::create( - Context, name, StaticLoc, StaticSpelling, SubscriptLoc, Indices.get(), - ArrowLoc, ElementTy.get(), CurDeclContext, GenericParams); + auto *const Subscript = SubscriptDecl::createParsed( + Context, StaticLoc, StaticSpelling, SubscriptLoc, Indices.get(), ArrowLoc, + ElementTy.get(), CurDeclContext, GenericParams); Subscript->getAttrs() = Attributes; // Let the source file track the opaque return type mapping, if any.