mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Fix libSyntax support for operator decl designated types.
This commit is contained in:
@@ -6500,7 +6500,7 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
SmallVector<SourceLoc, 4> identifierLocs;
|
||||
if (Tok.is(tok::colon)) {
|
||||
SyntaxParsingContext GroupCtxt(SyntaxContext,
|
||||
SyntaxKind::InfixOperatorGroup);
|
||||
SyntaxKind::OperatorPrecedenceAndTypes);
|
||||
colonLoc = consumeToken();
|
||||
if (Tok.is(tok::code_complete)) {
|
||||
if (CodeCompletion && !isPrefix && !isPostfix) {
|
||||
@@ -6514,6 +6514,9 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
|
||||
if (Context.LangOpts.EnableOperatorDesignatedTypes) {
|
||||
if (Tok.is(tok::identifier)) {
|
||||
SyntaxParsingContext GroupCtxt(SyntaxContext,
|
||||
SyntaxKind::IdentifierList);
|
||||
|
||||
identifiers.push_back(Context.getIdentifier(Tok.getText()));
|
||||
identifierLocs.push_back(consumeToken(tok::identifier));
|
||||
|
||||
@@ -6534,6 +6537,9 @@ Parser::parseDeclOperatorImpl(SourceLoc OperatorLoc, Identifier Name,
|
||||
}
|
||||
}
|
||||
} else if (Tok.is(tok::identifier)) {
|
||||
SyntaxParsingContext GroupCtxt(SyntaxContext,
|
||||
SyntaxKind::IdentifierList);
|
||||
|
||||
identifiers.push_back(Context.getIdentifier(Tok.getText()));
|
||||
identifierLocs.push_back(consumeToken(tok::identifier));
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// RUN: %target-typecheck-verify-swift -enable-operator-designated-types
|
||||
// RUN: %target-typecheck-verify-swift -enable-operator-designated-types -verify-syntax-tree
|
||||
|
||||
precedencegroup LowPrecedence {
|
||||
associativity: right
|
||||
|
||||
@@ -492,7 +492,7 @@ precedencegroup BazPrecedence {<PrecedenceGroupAssociativity>
|
||||
lowerThan: <PrecedenceGroupNameElement>DefaultPrecedence</PrecedenceGroupNameElement></PrecedenceGroupRelation>
|
||||
}</PrecedenceGroupDecl><OperatorDecl><DeclModifier>
|
||||
|
||||
infix </DeclModifier>operator<++><InfixOperatorGroup>:FooPrecedence</InfixOperatorGroup></OperatorDecl><OperatorDecl><DeclModifier>
|
||||
infix </DeclModifier>operator<++><OperatorPrecedenceAndTypes>:FooPrecedence</OperatorPrecedenceAndTypes></OperatorDecl><OperatorDecl><DeclModifier>
|
||||
prefix </DeclModifier>operator..<<</OperatorDecl><OperatorDecl><DeclModifier>
|
||||
postfix </DeclModifier>operator <-</OperatorDecl><FunctionDecl>
|
||||
|
||||
|
||||
@@ -662,31 +662,27 @@ DECL_NODES = [
|
||||
'PrefixOperatorToken',
|
||||
'PostfixOperatorToken',
|
||||
]),
|
||||
Child('InfixOperatorGroup', kind='InfixOperatorGroup',
|
||||
Child('OperatorPrecedenceAndTypes', kind='OperatorPrecedenceAndTypes',
|
||||
description='''
|
||||
Optionally specify a precedence group
|
||||
Optionally specify a precedence group and designated types.
|
||||
''',
|
||||
is_optional=True),
|
||||
]),
|
||||
|
||||
Node('IdentifierList', kind='SyntaxCollection',
|
||||
element='IdentifierToken'),
|
||||
|
||||
# infix-operator-group -> ':' identifier ','? identifier?
|
||||
Node('InfixOperatorGroup', kind='Syntax',
|
||||
Node('OperatorPrecedenceAndTypes', kind='Syntax',
|
||||
description='''
|
||||
A clause to specify precedence group in infix operator declaration.
|
||||
A clause to specify precedence group in infix operator declarations, and designated types in any operator declaration.
|
||||
''',
|
||||
children=[
|
||||
Child('Colon', kind='ColonToken'),
|
||||
Child('PrecedenceGroupName', kind='IdentifierToken',
|
||||
Child('PrecedenceGroupAndDesignatedTypes', kind='IdentifierList',
|
||||
description='''
|
||||
The name of the precedence group for the operator
|
||||
The precedence group and designated types for this operator
|
||||
'''),
|
||||
Child('TrailingComma', kind='CommaToken',
|
||||
is_optional=True),
|
||||
Child('ProtocolName', kind='IdentifierToken',
|
||||
description='''
|
||||
The protocol associated with the operator
|
||||
''',
|
||||
is_optional=True),
|
||||
]),
|
||||
|
||||
# precedence-group-decl -> attributes? modifiers? 'precedencegroup'
|
||||
|
||||
@@ -129,7 +129,7 @@ SYNTAX_NODE_SERIALIZATION_CODES = {
|
||||
'AccessorBlock': 124,
|
||||
'PatternBinding': 125,
|
||||
'EnumCaseElement': 126,
|
||||
'InfixOperatorGroup': 127,
|
||||
'OperatorPrecedenceAndTypes': 127,
|
||||
'PrecedenceGroupRelation': 128,
|
||||
'PrecedenceGroupNameElement': 129,
|
||||
'PrecedenceGroupAssignment': 130,
|
||||
@@ -228,6 +228,7 @@ SYNTAX_NODE_SERIALIZATION_CODES = {
|
||||
'AttributedType': 223,
|
||||
'YieldStmt': 224,
|
||||
'YieldList': 225,
|
||||
'IdentifierList': 226,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user