@@ -2262,8 +2262,10 @@ Parser::parseMacroRoleAttribute(
22622262 SourceLoc rParenLoc;
22632263 Optional<MacroRole> role;
22642264 bool sawRole = false ;
2265+ bool sawConformances = false ;
22652266 bool sawNames = false ;
22662267 SmallVector<MacroIntroducedDeclName, 2 > names;
2268+ SmallVector<TypeExpr *, 2 > conformances;
22672269 auto argumentsStatus = parseList (tok::r_paren, lParenLoc, rParenLoc,
22682270 /* AllowSepAfterLast=*/ false ,
22692271 diag::expected_rparen_expr_list,
@@ -2292,7 +2294,8 @@ Parser::parseMacroRoleAttribute(
22922294 parseOptionalArgumentLabel (fieldName, fieldNameLoc);
22932295
22942296 // If there is a field name, it better be 'names'.
2295- if (!(fieldName.empty () || fieldName.is (" names" ))) {
2297+ if (!(fieldName.empty () || fieldName.is (" names" ) ||
2298+ fieldName.is (" conformances" ))) {
22962299 diagnose (
22972300 fieldNameLoc, diag::macro_attribute_unknown_label, isAttached,
22982301 fieldName);
@@ -2302,7 +2305,7 @@ Parser::parseMacroRoleAttribute(
23022305
23032306 // If there is no field name and we haven't seen either names or the role,
23042307 // this is the role.
2305- if (fieldName.empty () && !sawNames && !sawRole) {
2308+ if (fieldName.empty () && !sawConformances && ! sawNames && !sawRole) {
23062309 // Whether we saw anything we tried to treat as a role.
23072310 sawRole = true ;
23082311
@@ -2347,6 +2350,25 @@ Parser::parseMacroRoleAttribute(
23472350 return status;
23482351 }
23492352
2353+ if (fieldName.is (" conformances" ) ||
2354+ (fieldName.empty () && sawConformances && !sawNames)) {
2355+ if (fieldName.is (" conformances" ) && sawConformances) {
2356+ diagnose (fieldNameLoc.isValid () ? fieldNameLoc : Tok.getLoc (),
2357+ diag::macro_attribute_duplicate_label,
2358+ isAttached,
2359+ " conformances" );
2360+ }
2361+
2362+ sawConformances = true ;
2363+
2364+ // Parse the introduced conformances
2365+ auto type = parseType ();
2366+ auto *typeExpr = new (Context) TypeExpr (type.get ());
2367+ conformances.push_back (typeExpr);
2368+
2369+ return status;
2370+ }
2371+
23502372 // If the field name is empty and we haved seen "names", or the field name
23512373 // is "names" but we've already seen the argument label, complain.
23522374 if (fieldName.empty () != sawNames) {
@@ -2450,7 +2472,7 @@ Parser::parseMacroRoleAttribute(
24502472 SourceRange range (Loc, rParenLoc);
24512473 return makeParserResult (MacroRoleAttr::create (
24522474 Context, AtLoc, range, syntax, lParenLoc, *role, names,
2453- rParenLoc, /* isImplicit*/ false ));
2475+ conformances, rParenLoc, /* isImplicit*/ false ));
24542476}
24552477
24562478// / Guts of \c parseSingleAttrOption and \c parseSingleAttrOptionIdentifier.
@@ -3822,7 +3844,7 @@ ParserStatus Parser::parseDeclAttribute(
38223844 auto attr = MacroRoleAttr::create (
38233845 Context, AtLoc, SourceRange (AtLoc, attrLoc),
38243846 MacroSyntax::Freestanding, SourceLoc (), MacroRole::Expression, { },
3825- SourceLoc (), /* isImplicit*/ false );
3847+ /* conformances= */ {}, SourceLoc (), /* isImplicit*/ false );
38263848 Attributes.add (attr);
38273849 return makeParserSuccess ();
38283850 }
0 commit comments