Fix libSyntax support for operator decl designated types.

This commit is contained in:
Mark Lacey
2018-10-11 11:55:10 -07:00
parent 2f7c21003b
commit 5e0cb1978a
5 changed files with 20 additions and 17 deletions

View File

@@ -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));

View File

@@ -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

View File

@@ -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>

View File

@@ -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'

View File

@@ -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,
}