Skip to content

Commit 5e0cb19

Browse files
committed
Fix libSyntax support for operator decl designated types.
1 parent 2f7c210 commit 5e0cb19

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6500,7 +6500,7 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
65006500
SmallVector<SourceLoc, 4> identifierLocs;
65016501
if (Tok.is(tok::colon)) {
65026502
SyntaxParsingContext GroupCtxt(SyntaxContext,
6503-
SyntaxKind::InfixOperatorGroup);
6503+
SyntaxKind::OperatorPrecedenceAndTypes);
65046504
colonLoc = consumeToken();
65056505
if (Tok.is(tok::code_complete)) {
65066506
if (CodeCompletion && !isPrefix && !isPostfix) {
@@ -6514,6 +6514,9 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
65146514

65156515
if (Context.LangOpts.EnableOperatorDesignatedTypes) {
65166516
if (Tok.is(tok::identifier)) {
6517+
SyntaxParsingContext GroupCtxt(SyntaxContext,
6518+
SyntaxKind::IdentifierList);
6519+
65176520
identifiers.push_back(Context.getIdentifier(Tok.getText()));
65186521
identifierLocs.push_back(consumeToken(tok::identifier));
65196522

@@ -6534,6 +6537,9 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
65346537
}
65356538
}
65366539
} else if (Tok.is(tok::identifier)) {
6540+
SyntaxParsingContext GroupCtxt(SyntaxContext,
6541+
SyntaxKind::IdentifierList);
6542+
65376543
identifiers.push_back(Context.getIdentifier(Tok.getText()));
65386544
identifierLocs.push_back(consumeToken(tok::identifier));
65396545

test/Parse/operator_decl_designated_types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -enable-operator-designated-types
1+
// RUN: %target-typecheck-verify-swift -enable-operator-designated-types -verify-syntax-tree
22

33
precedencegroup LowPrecedence {
44
associativity: right

test/Syntax/Outputs/round_trip_parse_gen.swift.withkinds

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ precedencegroup BazPrecedence {<PrecedenceGroupAssociativity>
492492
lowerThan: <PrecedenceGroupNameElement>DefaultPrecedence</PrecedenceGroupNameElement></PrecedenceGroupRelation>
493493
}</PrecedenceGroupDecl><OperatorDecl><DeclModifier>
494494

495-
infix </DeclModifier>operator<++><InfixOperatorGroup>:FooPrecedence</InfixOperatorGroup></OperatorDecl><OperatorDecl><DeclModifier>
495+
infix </DeclModifier>operator<++><OperatorPrecedenceAndTypes>:FooPrecedence</OperatorPrecedenceAndTypes></OperatorDecl><OperatorDecl><DeclModifier>
496496
prefix </DeclModifier>operator..<<</OperatorDecl><OperatorDecl><DeclModifier>
497497
postfix </DeclModifier>operator <-</OperatorDecl><FunctionDecl>
498498

utils/gyb_syntax_support/DeclNodes.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -662,31 +662,27 @@
662662
'PrefixOperatorToken',
663663
'PostfixOperatorToken',
664664
]),
665-
Child('InfixOperatorGroup', kind='InfixOperatorGroup',
665+
Child('OperatorPrecedenceAndTypes', kind='OperatorPrecedenceAndTypes',
666666
description='''
667-
Optionally specify a precedence group
667+
Optionally specify a precedence group and designated types.
668668
''',
669669
is_optional=True),
670670
]),
671671

672+
Node('IdentifierList', kind='SyntaxCollection',
673+
element='IdentifierToken'),
674+
672675
# infix-operator-group -> ':' identifier ','? identifier?
673-
Node('InfixOperatorGroup', kind='Syntax',
676+
Node('OperatorPrecedenceAndTypes', kind='Syntax',
674677
description='''
675-
A clause to specify precedence group in infix operator declaration.
678+
A clause to specify precedence group in infix operator declarations, and designated types in any operator declaration.
676679
''',
677680
children=[
678681
Child('Colon', kind='ColonToken'),
679-
Child('PrecedenceGroupName', kind='IdentifierToken',
682+
Child('PrecedenceGroupAndDesignatedTypes', kind='IdentifierList',
680683
description='''
681-
The name of the precedence group for the operator
684+
The precedence group and designated types for this operator
682685
'''),
683-
Child('TrailingComma', kind='CommaToken',
684-
is_optional=True),
685-
Child('ProtocolName', kind='IdentifierToken',
686-
description='''
687-
The protocol associated with the operator
688-
''',
689-
is_optional=True),
690686
]),
691687

692688
# precedence-group-decl -> attributes? modifiers? 'precedencegroup'

utils/gyb_syntax_support/NodeSerializationCodes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
'AccessorBlock': 124,
130130
'PatternBinding': 125,
131131
'EnumCaseElement': 126,
132-
'InfixOperatorGroup': 127,
132+
'OperatorPrecedenceAndTypes': 127,
133133
'PrecedenceGroupRelation': 128,
134134
'PrecedenceGroupNameElement': 129,
135135
'PrecedenceGroupAssignment': 130,
@@ -228,6 +228,7 @@
228228
'AttributedType': 223,
229229
'YieldStmt': 224,
230230
'YieldList': 225,
231+
'IdentifierList': 226,
231232
}
232233

233234

0 commit comments

Comments
 (0)