@@ -7977,13 +7977,13 @@ ParserResult<ClassDecl> Parser::parseDeclClass(ParseDeclOptions Flags,
79777977}
79787978
79797979ParserStatus Parser::parsePrimaryAssociatedTypes (
7980- SmallVectorImpl<AssociatedTypeDecl * > &AssocTypes ) {
7980+ SmallVectorImpl<PrimaryAssociatedTypeName > &AssocTypeNames ) {
79817981 SyntaxParsingContext GPSContext (SyntaxContext,
79827982 SyntaxKind::PrimaryAssociatedTypeClause);
79837983
79847984 SourceLoc LAngleLoc = consumeStartingLess ();
79857985
7986- auto Result = parsePrimaryAssociatedTypeList (AssocTypes );
7986+ auto Result = parsePrimaryAssociatedTypeList (AssocTypeNames );
79877987
79887988 // Parse the closing '>'.
79897989 SourceLoc RAngleLoc;
@@ -8001,7 +8001,7 @@ ParserStatus Parser::parsePrimaryAssociatedTypes(
80018001}
80028002
80038003ParserStatus Parser::parsePrimaryAssociatedTypeList (
8004- SmallVectorImpl<AssociatedTypeDecl * > &AssocTypes ) {
8004+ SmallVectorImpl<PrimaryAssociatedTypeName > &AssocTypeNames ) {
80058005 ParserStatus Result;
80068006 SyntaxParsingContext PATContext (SyntaxContext,
80078007 SyntaxKind::PrimaryAssociatedTypeList);
@@ -8011,16 +8011,6 @@ ParserStatus Parser::parsePrimaryAssociatedTypeList(
80118011 SyntaxParsingContext ATContext (SyntaxContext,
80128012 SyntaxKind::PrimaryAssociatedType);
80138013
8014- // Note that we're parsing a declaration.
8015- StructureMarkerRAII ParsingDecl (*this , Tok.getLoc (),
8016- StructureMarkerKind::Declaration);
8017-
8018- // Parse attributes.
8019- DeclAttributes Attrs;
8020- if (Tok.hasComment ())
8021- Attrs.add (new (Context) RawDocCommentAttr (Tok.getCommentRange ()));
8022- parseDeclAttributeList (Attrs);
8023-
80248014 // Parse the name of the parameter.
80258015 Identifier Name;
80268016 SourceLoc NameLoc;
@@ -8030,54 +8020,7 @@ ParserStatus Parser::parsePrimaryAssociatedTypeList(
80308020 break ;
80318021 }
80328022
8033- // Parse the ':' followed by a type.
8034- SmallVector<InheritedEntry, 1 > Inherited;
8035- if (Tok.is (tok::colon)) {
8036- (void )consumeToken ();
8037- ParserResult<TypeRepr> Ty;
8038-
8039- if (Tok.isAny (tok::identifier, tok::code_complete, tok::kw_protocol,
8040- tok::kw_Any)) {
8041- Ty = parseType ();
8042- } else if (Tok.is (tok::kw_class)) {
8043- diagnose (Tok, diag::unexpected_class_constraint);
8044- diagnose (Tok, diag::suggest_anyobject)
8045- .fixItReplace (Tok.getLoc (), " AnyObject" );
8046- consumeToken ();
8047- Result.setIsParseError ();
8048- } else {
8049- diagnose (Tok, diag::expected_generics_type_restriction, Name);
8050- Result.setIsParseError ();
8051- }
8052-
8053- if (Ty.hasCodeCompletion ())
8054- return makeParserCodeCompletionStatus ();
8055-
8056- if (Ty.isNonNull ())
8057- Inherited.push_back ({Ty.get ()});
8058- }
8059-
8060- ParserResult<TypeRepr> UnderlyingTy;
8061- if (Tok.is (tok::equal)) {
8062- SyntaxParsingContext InitContext (SyntaxContext,
8063- SyntaxKind::TypeInitializerClause);
8064- consumeToken (tok::equal);
8065- UnderlyingTy = parseType (diag::expected_type_in_associatedtype);
8066- Result |= UnderlyingTy;
8067- if (UnderlyingTy.isNull ())
8068- return Result;
8069- }
8070-
8071- auto *AssocType = new (Context)
8072- AssociatedTypeDecl (CurDeclContext, NameLoc, Name, NameLoc,
8073- UnderlyingTy.getPtrOrNull (),
8074- /* trailingWhere=*/ nullptr );
8075- AssocType->getAttrs () = Attrs;
8076- if (!Inherited.empty ())
8077- AssocType->setInherited (Context.AllocateCopy (Inherited));
8078- AssocType->setPrimary ();
8079-
8080- AssocTypes.push_back (AssocType);
8023+ AssocTypeNames.emplace_back (Name, NameLoc);
80818024
80828025 // Parse the comma, if the list continues.
80838026 HasNextParam = consumeIf (tok::comma);
@@ -8097,13 +8040,7 @@ ParserStatus Parser::parsePrimaryAssociatedTypeList(
80978040// / inheritance?
80988041// /
80998042// / primary-associated-type-list:
8100- // / '<' primary-associated-type+ '>'
8101- // /
8102- // / primary-associated-type:
8103- // / identifier inheritance? default-associated-type
8104- // /
8105- // / default-associated-type:
8106- // / '=' type
8043+ // / '<' identifier+ '>'
81078044// /
81088045// / protocol-member:
81098046// / decl-func
@@ -8124,11 +8061,11 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
81248061 if (Status.isErrorOrHasCompletion ())
81258062 return Status;
81268063
8127- SmallVector<AssociatedTypeDecl * , 2 > PrimaryAssociatedTypes ;
8064+ SmallVector<PrimaryAssociatedTypeName , 2 > PrimaryAssociatedTypeNames ;
81288065
81298066 if (Context.LangOpts .EnableParameterizedProtocolTypes ) {
81308067 if (startsWithLess (Tok)) {
8131- Status |= parsePrimaryAssociatedTypes (PrimaryAssociatedTypes );
8068+ Status |= parsePrimaryAssociatedTypes (PrimaryAssociatedTypeNames );
81328069 }
81338070 } else {
81348071 // Protocols don't support generic parameters, but people often want them and
@@ -8167,6 +8104,7 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
81678104
81688105 ProtocolDecl *Proto = new (Context)
81698106 ProtocolDecl (CurDeclContext, ProtocolLoc, NameLoc, ProtocolName,
8107+ Context.AllocateCopy (PrimaryAssociatedTypeNames),
81708108 Context.AllocateCopy (InheritedProtocols), TrailingWhere);
81718109 // No need to setLocalDiscriminator: protocols can't appear in local contexts.
81728110
@@ -8176,12 +8114,6 @@ parseDeclProtocol(ParseDeclOptions Flags, DeclAttributes &Attributes) {
81768114
81778115 ContextChange CC (*this , Proto);
81788116
8179- // Re-parent the primary associated type declarations into the protocol.
8180- for (auto *AssocType : PrimaryAssociatedTypes) {
8181- AssocType->setDeclContext (Proto);
8182- Proto->addMember (AssocType);
8183- }
8184-
81858117 // Parse the body.
81868118 {
81878119 SyntaxParsingContext BlockContext (SyntaxContext, SyntaxKind::MemberDeclBlock);
0 commit comments