@@ -437,6 +437,62 @@ bool Parser::parseSpecializeAttribute(swift::tok ClosingBrace, SourceLoc AtLoc,
437
437
return true ;
438
438
}
439
439
440
+ ParserResult<ImplementsAttr>
441
+ Parser::parseImplementsAttribute (SourceLoc AtLoc, SourceLoc Loc) {
442
+ StringRef AttrName = " _implements" ;
443
+ ParserStatus Status;
444
+
445
+ if (Tok.isNot (tok::l_paren)) {
446
+ diagnose (Loc, diag::attr_expected_lparen, AttrName,
447
+ /* DeclModifier=*/ false );
448
+ Status.setIsParseError ();
449
+ return Status;
450
+ }
451
+
452
+ SourceLoc lParenLoc = consumeToken ();
453
+
454
+ ParserResult<TypeRepr> ProtocolType = parseType ();
455
+ Status |= ProtocolType;
456
+
457
+ if (!(Status.shouldStopParsing () || consumeIf (tok::comma))) {
458
+ diagnose (Tok.getLoc (), diag::attr_expected_comma, AttrName,
459
+ /* DeclModifier=*/ false );
460
+ Status.setIsParseError ();
461
+ }
462
+
463
+ DeclNameLoc MemberNameLoc;
464
+ DeclName MemberName;
465
+ if (!Status.shouldStopParsing ()) {
466
+ MemberName =
467
+ parseUnqualifiedDeclName (/* afterDot=*/ false , MemberNameLoc,
468
+ diag::attr_implements_expected_member_name,
469
+ /* allowOperators=*/ true ,
470
+ /* allowZeroArgCompoundNames=*/ true );
471
+ if (!MemberName) {
472
+ Status.setIsParseError ();
473
+ }
474
+ }
475
+
476
+ if (Status.isError ()) {
477
+ skipUntil (tok::r_paren);
478
+ }
479
+
480
+ SourceLoc rParenLoc;
481
+ if (!consumeIf (tok::r_paren, rParenLoc)) {
482
+ diagnose (lParenLoc, diag::attr_expected_rparen, AttrName,
483
+ /* DeclModifier=*/ false );
484
+ Status.setIsParseError ();
485
+ }
486
+
487
+ if (Status.isError ()) {
488
+ return Status;
489
+ }
490
+
491
+ return ParserResult<ImplementsAttr>(
492
+ ImplementsAttr::create (Context, AtLoc, SourceRange (Loc, rParenLoc),
493
+ ProtocolType.get (), MemberName, MemberNameLoc));
494
+ }
495
+
440
496
bool Parser::parseNewDeclAttribute (DeclAttributes &Attributes, SourceLoc AtLoc,
441
497
DeclAttrKind DK) {
442
498
// Ok, it is a valid attribute, eat it, and then process it.
@@ -1258,6 +1314,14 @@ bool Parser::parseNewDeclAttribute(DeclAttributes &Attributes, SourceLoc AtLoc,
1258
1314
Attributes.add (Attr);
1259
1315
break ;
1260
1316
}
1317
+
1318
+ case DAK_Implements: {
1319
+ ParserResult<ImplementsAttr> Attr = parseImplementsAttribute (AtLoc, Loc);
1320
+ if (Attr.isNonNull ()) {
1321
+ Attributes.add (Attr.get ());
1322
+ }
1323
+ break ;
1324
+ }
1261
1325
}
1262
1326
1263
1327
if (DuplicateAttribute) {
0 commit comments