@@ -7347,100 +7347,6 @@ ParserResult<TypeDecl> Parser::parseDeclAssociatedType(Parser::ParseDeclOptions
7347
7347
return makeParserResult (Status, assocType);
7348
7348
}
7349
7349
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
-
7444
7350
// / Parse a "(value)" specifier for "set" or "willSet" if present. Create a
7445
7351
// / parameter list to represent the spelled argument or return null if none is
7446
7352
// / present.
@@ -7482,9 +7388,12 @@ static ParameterList *parseOptionalAccessorArgument(SourceLoc SpecifierLoc,
7482
7388
P.parseMatchingToken (tok::r_paren, EndLoc, DiagID, StartLoc);
7483
7389
}
7484
7390
}
7391
+ if (Name.empty ())
7392
+ return nullptr ;
7393
+
7394
+ auto *param = new (P.Context ) ParamDecl (
7395
+ SourceLoc (), SourceLoc (), Identifier (), NameLoc, Name, P.CurDeclContext );
7485
7396
7486
- if (Name.empty ()) NameLoc = SpecifierLoc;
7487
- auto param = createSetterAccessorArgument (NameLoc, Name, Kind, P);
7488
7397
return ParameterList::create (P.Context , StartLoc, param, EndLoc);
7489
7398
}
7490
7399
@@ -7740,10 +7649,10 @@ ParserStatus Parser::parseGetEffectSpecifier(ParsedAccessors &accessors,
7740
7649
7741
7650
bool Parser::parseAccessorAfterIntroducer (
7742
7651
SourceLoc Loc, AccessorKind Kind, ParsedAccessors &accessors,
7743
- bool &hasEffectfulGet, ParameterList *Indices, bool &parsingLimitedSyntax,
7652
+ bool &hasEffectfulGet, bool &parsingLimitedSyntax,
7744
7653
DeclAttributes &Attributes, ParseDeclOptions Flags,
7745
7654
AbstractStorageDecl *storage, ParserStatus &Status) {
7746
- auto *ValueNamePattern = parseOptionalAccessorArgument (Loc, *this , Kind);
7655
+ auto *param = parseOptionalAccessorArgument (Loc, *this , Kind);
7747
7656
7748
7657
// Next, parse effects specifiers. While it's only valid to have them
7749
7658
// on 'get' accessors, we also emit diagnostics if they show up on others.
@@ -7754,15 +7663,14 @@ bool Parser::parseAccessorAfterIntroducer(
7754
7663
hasEffectfulGet, Kind, Loc);
7755
7664
7756
7665
// 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 );
7760
7669
accessor->getAttrs () = Attributes;
7761
7670
7762
7671
// Collect this accessor and detect conflicts.
7763
7672
if (auto existingAccessor = accessors.add (accessor)) {
7764
- diagnoseRedundantAccessors (*this , Loc, Kind,
7765
- /* subscript*/ Indices != nullptr ,
7673
+ diagnoseRedundantAccessors (*this , Loc, Kind, isa<SubscriptDecl>(storage),
7766
7674
existingAccessor);
7767
7675
}
7768
7676
@@ -7841,12 +7749,11 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
7841
7749
auto parseImplicitGetter = [&]() {
7842
7750
assert (Tok.is (tok::l_brace));
7843
7751
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);
7850
7757
accessors.add (getter);
7851
7758
parseAbstractFunctionBody (getter);
7852
7759
accessors.RBLoc = getter->getEndLoc ();
@@ -7932,8 +7839,8 @@ ParserStatus Parser::parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
7932
7839
}
7933
7840
7934
7841
if (parseAccessorAfterIntroducer (Loc, Kind, accessors, hasEffectfulGet,
7935
- Indices, parsingLimitedSyntax, Attributes,
7936
- Flags, storage, Status))
7842
+ parsingLimitedSyntax, Attributes, Flags ,
7843
+ storage, Status))
7937
7844
break ;
7938
7845
}
7939
7846
backtrack->cancelBacktrack ();
@@ -7956,10 +7863,6 @@ void Parser::parseTopLevelAccessors(
7956
7863
if (Tok.is (tok::NUM_TOKENS))
7957
7864
consumeTokenWithoutFeedingReceiver ();
7958
7865
7959
- ParameterList *indices = nullptr ;
7960
- if (auto subscript = dyn_cast<SubscriptDecl>(storage))
7961
- indices = subscript->getIndices ();
7962
-
7963
7866
bool hadLBrace = consumeIf (tok::l_brace);
7964
7867
7965
7868
// Prepopulate the field for any accessors that were already parsed parsed accessors
@@ -7982,8 +7885,8 @@ void Parser::parseTopLevelAccessors(
7982
7885
break ;
7983
7886
7984
7887
(void )parseAccessorAfterIntroducer (loc, kind, accessors, hasEffectfulGet,
7985
- indices, parsingLimitedSyntax ,
7986
- attributes, PD_Default, storage, status);
7888
+ parsingLimitedSyntax, attributes ,
7889
+ PD_Default, storage, status);
7987
7890
}
7988
7891
7989
7892
if (hadLBrace && Tok.is (tok::r_brace)) {
0 commit comments