@@ -7347,100 +7347,6 @@ ParserResult<TypeDecl> Parser::parseDeclAssociatedType(Parser::ParseDeclOptions
73477347 return makeParserResult (Status, assocType);
73487348}
73497349
7350- // / This function creates an accessor function (with no body) for a computed
7351- // / property or subscript.
7352- static AccessorDecl *
7353- createAccessorFunc (SourceLoc DeclLoc, ParameterList *param,
7354- ParameterList *Indices, Parser::ParseDeclOptions Flags,
7355- AccessorKind Kind, AbstractStorageDecl *storage, Parser *P,
7356- SourceLoc AccessorKeywordLoc, SourceLoc asyncLoc,
7357- SourceLoc throwsLoc, TypeRepr *thrownTy) {
7358- // First task, set up the value argument list. This is the "newValue" name
7359- // (for setters) followed by the index list (for subscripts). For
7360- // non-subscript getters, this degenerates down to "()".
7361- //
7362- // We put the 'newValue' argument before the subscript index list as a
7363- // micro-optimization for Objective-C thunk generation.
7364- ParameterList *ValueArg;
7365- {
7366- SmallVector<ParamDecl*, 2 > ValueArgElements;
7367- SourceLoc StartLoc, EndLoc;
7368- if (param) {
7369- assert (param->size () == 1 &&
7370- " Should only have a single parameter in the list" );
7371- ValueArgElements.push_back (param->get (0 ));
7372- StartLoc = param->getStartLoc ();
7373- EndLoc = param->getEndLoc ();
7374- }
7375-
7376- if (Indices) {
7377- // Create parameter declarations corresponding to each of the
7378- // parameter declarations from the subscript declaration.
7379- for (ParamDecl *storageParam : *Indices) {
7380- // Clone the parameter. Do not clone the parameter type;
7381- // this will be filled in by the type-checker.
7382- auto accessorParam =
7383- new (P->Context ) ParamDecl (storageParam->getSpecifierLoc (),
7384- storageParam->getArgumentNameLoc (),
7385- storageParam->getArgumentName (),
7386- storageParam->getNameLoc (),
7387- storageParam->getName (),
7388- P->CurDeclContext );
7389- accessorParam->setAutoClosure (storageParam->isAutoClosure ());
7390-
7391- // The cloned parameter is implicit.
7392- accessorParam->setImplicit ();
7393-
7394- // It has no default arguments; these will be always be taken
7395- // from the subscript declaration.
7396- accessorParam->setDefaultArgumentKind (DefaultArgumentKind::None);
7397-
7398- ValueArgElements.push_back (accessorParam);
7399- }
7400-
7401- if (StartLoc.isInvalid ()) {
7402- StartLoc = Indices->getStartLoc ();
7403- EndLoc = Indices->getEndLoc ();
7404- }
7405- }
7406-
7407- ValueArg = ParameterList::create (P->Context , StartLoc, ValueArgElements,
7408- EndLoc);
7409- }
7410-
7411- // Start the function.
7412- auto *D = AccessorDecl::create (P->Context ,
7413- /* FIXME FuncLoc=*/ DeclLoc, AccessorKeywordLoc,
7414- Kind, storage, asyncLoc.isValid (), asyncLoc,
7415- throwsLoc.isValid (), throwsLoc, thrownTy,
7416- ValueArg, Type (), P->CurDeclContext );
7417-
7418- return D;
7419- }
7420-
7421- static ParamDecl *createSetterAccessorArgument (SourceLoc nameLoc,
7422- Identifier name,
7423- AccessorKind accessorKind,
7424- Parser &P) {
7425- // Add the parameter. If no name was specified, the name defaults to
7426- // 'value'.
7427- bool isNameImplicit = name.empty ();
7428- if (isNameImplicit) {
7429- const char *implName =
7430- accessorKind == AccessorKind::DidSet ? " oldValue" : " newValue" ;
7431- name = P.Context .getIdentifier (implName);
7432- }
7433-
7434- auto result = new (P.Context )
7435- ParamDecl (SourceLoc (), SourceLoc (),
7436- Identifier (), nameLoc, name, P.CurDeclContext );
7437-
7438- if (isNameImplicit)
7439- result->setImplicit ();
7440-
7441- return result;
7442- }
7443-
74447350// / Parse a "(value)" specifier for "set" or "willSet" if present. Create a
74457351// / parameter list to represent the spelled argument or return null if none is
74467352// / present.
@@ -7482,9 +7388,12 @@ static ParameterList *parseOptionalAccessorArgument(SourceLoc SpecifierLoc,
74827388 P.parseMatchingToken (tok::r_paren, EndLoc, DiagID, StartLoc);
74837389 }
74847390 }
7391+ if (Name.empty ())
7392+ return nullptr ;
7393+
7394+ auto *param = new (P.Context ) ParamDecl (
7395+ SourceLoc (), SourceLoc (), Identifier (), NameLoc, Name, P.CurDeclContext );
74857396
7486- if (Name.empty ()) NameLoc = SpecifierLoc;
7487- auto param = createSetterAccessorArgument (NameLoc, Name, Kind, P);
74887397 return ParameterList::create (P.Context , StartLoc, param, EndLoc);
74897398}
74907399
@@ -7740,10 +7649,10 @@ ParserStatus Parser::parseGetEffectSpecifier(ParsedAccessors &accessors,
77407649
77417650bool Parser::parseAccessorAfterIntroducer (
77427651 SourceLoc Loc, AccessorKind Kind, ParsedAccessors &accessors,
7743- bool &hasEffectfulGet, ParameterList *Indices, bool &parsingLimitedSyntax,
7652+ bool &hasEffectfulGet, bool &parsingLimitedSyntax,
77447653 DeclAttributes &Attributes, ParseDeclOptions Flags,
77457654 AbstractStorageDecl *storage, ParserStatus &Status) {
7746- auto *ValueNamePattern = parseOptionalAccessorArgument (Loc, *this , Kind);
7655+ auto *param = parseOptionalAccessorArgument (Loc, *this , Kind);
77477656
77487657 // Next, parse effects specifiers. While it's only valid to have them
77497658 // on 'get' accessors, we also emit diagnostics if they show up on others.
@@ -7754,15 +7663,14 @@ bool Parser::parseAccessorAfterIntroducer(
77547663 hasEffectfulGet, Kind, Loc);
77557664
77567665 // Set up a function declaration.
7757- auto accessor =
7758- createAccessorFunc (Loc, ValueNamePattern, Indices, Flags, Kind, storage ,
7759- this , Loc, asyncLoc, throwsLoc, thrownTy);
7666+ auto * accessor = AccessorDecl::createParsed (
7667+ Context, Kind, storage, /* declLoc */ Loc, /* accessorKeywordLoc */ Loc ,
7668+ param, asyncLoc, throwsLoc, thrownTy, CurDeclContext );
77607669 accessor->getAttrs () = Attributes;
77617670
77627671 // Collect this accessor and detect conflicts.
77637672 if (auto existingAccessor = accessors.add (accessor)) {
7764- diagnoseRedundantAccessors (*this , Loc, Kind,
7765- /* subscript*/ Indices != nullptr ,
7673+ diagnoseRedundantAccessors (*this , Loc, Kind, isa<SubscriptDecl>(storage),
77667674 existingAccessor);
77677675 }
77687676
@@ -7841,12 +7749,11 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
78417749 auto parseImplicitGetter = [&]() {
78427750 assert (Tok.is (tok::l_brace));
78437751 accessors.LBLoc = Tok.getLoc ();
7844- auto getter =
7845- createAccessorFunc (Tok.getLoc (), /* ValueNamePattern*/ nullptr , Indices,
7846- Flags, AccessorKind::Get, storage, this ,
7847- /* AccessorKeywordLoc*/ SourceLoc (),
7848- /* asyncLoc*/ SourceLoc (), /* throwsLoc*/ SourceLoc (),
7849- /* thrownTy*/ nullptr );
7752+ auto *getter = AccessorDecl::createParsed (
7753+ Context, AccessorKind::Get, storage, /* declLoc*/ Tok.getLoc (),
7754+ /* accessorKeywordLoc*/ SourceLoc (), /* paramList*/ nullptr ,
7755+ /* asyncLoc*/ SourceLoc (), /* throwsLoc*/ SourceLoc (),
7756+ /* thrownTy*/ nullptr , CurDeclContext);
78507757 accessors.add (getter);
78517758 parseAbstractFunctionBody (getter);
78527759 accessors.RBLoc = getter->getEndLoc ();
@@ -7932,8 +7839,8 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
79327839 }
79337840
79347841 if (parseAccessorAfterIntroducer (Loc, Kind, accessors, hasEffectfulGet,
7935- Indices, parsingLimitedSyntax, Attributes,
7936- Flags, storage, Status))
7842+ parsingLimitedSyntax, Attributes, Flags ,
7843+ storage, Status))
79377844 break ;
79387845 }
79397846 backtrack->cancelBacktrack ();
@@ -7956,10 +7863,6 @@ void Parser::parseTopLevelAccessors(
79567863 if (Tok.is (tok::NUM_TOKENS))
79577864 consumeTokenWithoutFeedingReceiver ();
79587865
7959- ParameterList *indices = nullptr ;
7960- if (auto subscript = dyn_cast<SubscriptDecl>(storage))
7961- indices = subscript->getIndices ();
7962-
79637866 bool hadLBrace = consumeIf (tok::l_brace);
79647867
79657868 // Prepopulate the field for any accessors that were already parsed parsed accessors
@@ -7982,8 +7885,8 @@ void Parser::parseTopLevelAccessors(
79827885 break ;
79837886
79847887 (void )parseAccessorAfterIntroducer (loc, kind, accessors, hasEffectfulGet,
7985- indices, parsingLimitedSyntax ,
7986- attributes, PD_Default, storage, status);
7888+ parsingLimitedSyntax, attributes ,
7889+ PD_Default, storage, status);
79877890 }
79887891
79897892 if (hadLBrace && Tok.is (tok::r_brace)) {
0 commit comments