Files
swift-mirror/utils/gyb_syntax_support/StmtNodes.py
Philippe Hausler 6e05240426 AsyncSequence and protocol conformance rethrows (#35224)
* Initial draft of async sequences

* Adjust AsyncSequence associated type requirements

* Add a draft implementation of AsyncSequence and associated functionality

* Correct merge damage and rename from GeneratorProtocol to AsyncIteratorProtocol

* Add AsyncSequence types to the cmake lists

* Add cancellation support

* [DRAFT] Implementation of protocol conformance rethrowing

* Account for ASTVerifier passes to ensure throwing and by conformance rethrowing verifies appropriately

* Remove commented out code

* OtherConstructorDeclRefExpr can also be a source of a rethrowing kind function

* Re-order the checkApply logic to account for existing throwing calculations better

* Extract rethrowing calculation into smaller functions

* Allow for closures and protocol conformances to contribute to throwing

* Add unit tests for conformance based rethrowing

* Restrict rethrowing requirements to only protocols marked with @rethrows

* Correct logic for gating of `@rethrows` and adjust the determinates to be based upon throws and not rethrows spelling

* Attempt to unify the async sequence features together

* Reorder try await to latest syntax

* revert back to the inout diagnosis

* House mutations in local scope

* Revert "House mutations in local scope"

This reverts commit d91f1b25b59fff8e4be107c808895ff3f293b394.

* Adjust for inout diagnostics and fall back to original mutation strategy

* Convert async flag to source locations and add initial try support to for await in syntax

* Fix case typo of MinMax.swift

* Adjust rethrowing tests to account for changes associated with @rethrows

* Allow parsing and diagnostics associated with try applied to for await in syntax

* Correct the code-completion for @rethrows

* Additional corrections for the code-completion for @rethrows this time for the last in the list

* Handle throwing cases of iteration of async sequences

* restore building XCTest

* First wave of feedback fixes

* Rework constraints checking for async sequence for-try-await-in checking

* Allow testing of for-await-in parsing and silgen testing and add unit tests for both

* Remove async sequence operators for now

* Back out cancellation of AsyncIteratorProtocols

* Restructure protocol conformance throws checking and cache results

* remove some stray whitespaces

* Correct some merge damage

* Ensure the throwing determinate for applying for-await-in always has a valid value and adjust the for-await-in silgen test to reflect the cancel changes

* Squelch the python linter for line length
2021-01-25 18:48:50 -08:00

372 lines
14 KiB
Python

from .Child import Child
from .Node import Node # noqa: I201
STMT_NODES = [
# continue-stmt -> 'continue' label? ';'?
Node('ContinueStmt', kind='Stmt',
children=[
Child('ContinueKeyword', kind='ContinueToken'),
Child('Label', kind='IdentifierToken',
is_optional=True),
]),
# while-stmt -> label? ':'? 'while' condition-list code-block ';'?
Node('WhileStmt', kind='Stmt',
traits=['WithCodeBlock', 'Labeled'],
children=[
Child('LabelName', kind='IdentifierToken',
is_optional=True),
Child('LabelColon', kind='ColonToken',
is_optional=True),
Child('WhileKeyword', kind='WhileToken'),
Child('Conditions', kind='ConditionElementList',
collection_element_name='Condition'),
Child('Body', kind='CodeBlock'),
]),
# defer-stmt -> 'defer' code-block ';'?
Node('DeferStmt', kind='Stmt',
traits=['WithCodeBlock'],
children=[
Child('DeferKeyword', kind='DeferToken'),
Child('Body', kind='CodeBlock'),
]),
# expr-stmt -> expression ';'?
Node('ExpressionStmt', kind='Stmt',
children=[
Child('Expression', kind='Expr'),
]),
# switch-case-list -> switch-case switch-case-list?
Node('SwitchCaseList', kind='SyntaxCollection',
element='Syntax', element_name='SwitchCase',
element_choices=['SwitchCase', 'IfConfigDecl']),
# repeat-while-stmt -> label? ':'? 'repeat' code-block 'while' expr ';'?
Node('RepeatWhileStmt', kind='Stmt',
traits=['WithCodeBlock', 'Labeled'],
children=[
Child('LabelName', kind='IdentifierToken',
is_optional=True),
Child('LabelColon', kind='ColonToken',
is_optional=True),
Child('RepeatKeyword', kind='RepeatToken'),
Child('Body', kind='CodeBlock'),
Child('WhileKeyword', kind='WhileToken'),
Child('Condition', kind='Expr'),
]),
# guard-stmt -> 'guard' condition-list 'else' code-block ';'?
Node('GuardStmt', kind='Stmt',
traits=['WithCodeBlock'],
children=[
Child('GuardKeyword', kind='GuardToken'),
Child('Conditions', kind='ConditionElementList',
collection_element_name='Condition'),
Child('ElseKeyword', kind='ElseToken'),
Child('Body', kind='CodeBlock'),
]),
Node('WhereClause', kind='Syntax',
children=[
Child('WhereKeyword', kind='WhereToken'),
Child('GuardResult', kind='Expr'),
]),
# for-in-stmt -> label? ':'?
# 'for' 'try'? 'await'? 'case'? pattern 'in' expr 'where'?
# expr code-block ';'?
Node('ForInStmt', kind='Stmt',
traits=['WithCodeBlock', 'Labeled'],
children=[
Child('LabelName', kind='IdentifierToken',
is_optional=True),
Child('LabelColon', kind='ColonToken',
is_optional=True),
Child('ForKeyword', kind='ForToken'),
Child('TryKeyword', kind='TryToken',
is_optional=True),
Child('AwaitKeyword', kind='IdentifierToken',
classification='Keyword',
text_choices=['await'], is_optional=True),
Child('CaseKeyword', kind='CaseToken',
is_optional=True),
Child('Pattern', kind='Pattern'),
Child('TypeAnnotation', kind='TypeAnnotation',
is_optional=True),
Child('InKeyword', kind='InToken'),
Child('SequenceExpr', kind='Expr'),
Child('WhereClause', kind='WhereClause',
is_optional=True),
Child('Body', kind='CodeBlock'),
]),
# switch-stmt -> identifier? ':'? 'switch' expr '{'
# switch-case-list '}' ';'?
Node('SwitchStmt', kind='Stmt',
traits=['Braced', 'Labeled'],
children=[
Child('LabelName', kind='IdentifierToken',
is_optional=True),
Child('LabelColon', kind='ColonToken',
is_optional=True),
Child('SwitchKeyword', kind='SwitchToken'),
Child('Expression', kind='Expr'),
Child('LeftBrace', kind='LeftBraceToken'),
Child('Cases', kind='SwitchCaseList',
collection_element_name='Case'),
Child('RightBrace', kind='RightBraceToken'),
]),
# catch-clause-list -> catch-clause catch-clause-list?
Node('CatchClauseList', kind='SyntaxCollection',
element='CatchClause'),
# do-stmt -> identifier? ':'? 'do' code-block catch-clause-list ';'?
Node('DoStmt', kind='Stmt',
traits=['WithCodeBlock', 'Labeled'],
children=[
Child('LabelName', kind='IdentifierToken',
is_optional=True),
Child('LabelColon', kind='ColonToken',
is_optional=True),
Child('DoKeyword', kind='DoToken'),
Child('Body', kind='CodeBlock'),
Child('CatchClauses', kind='CatchClauseList',
collection_element_name='CatchClause', is_optional=True),
]),
# return-stmt -> 'return' expr? ';'?
Node('ReturnStmt', kind='Stmt',
children=[
Child('ReturnKeyword', kind='ReturnToken'),
Child('Expression', kind='Expr',
is_optional=True),
]),
# yield-stmt -> 'yield' '('? expr-list? ')'?
Node('YieldStmt', kind='Stmt',
children=[
Child('YieldKeyword', kind='YieldToken'),
Child('Yields', kind='Syntax',
node_choices=[
Child('YieldList', kind='YieldList'),
Child('SimpleYield', kind='Expr'),
]),
]),
Node('YieldList', kind='Syntax',
children=[
Child('LeftParen', kind='LeftParenToken'),
Child('ElementList', kind='ExprList',
collection_element_name='Element'),
Child('TrailingComma', kind='CommaToken', is_optional=True),
Child('RightParen', kind='RightParenToken'),
]),
# fallthrough-stmt -> 'fallthrough' ';'?
Node('FallthroughStmt', kind='Stmt',
children=[
Child('FallthroughKeyword', kind='FallthroughToken'),
]),
# break-stmt -> 'break' identifier? ';'?
Node('BreakStmt', kind='Stmt',
children=[
Child('BreakKeyword', kind='BreakToken'),
Child('Label', kind='IdentifierToken',
is_optional=True),
]),
# case-item-list -> case-item case-item-list?
Node('CaseItemList', kind='SyntaxCollection',
element='CaseItem'),
# catch-item-list -> catch-item catch-item-list?
Node('CatchItemList', kind='SyntaxCollection',
element='CatchItem'),
# condition -> expression
# | availability-condition
# | case-condition
# | optional-binding-condition
Node('ConditionElement', kind='Syntax',
traits=['WithTrailingComma'],
children=[
Child('Condition', kind='Syntax',
node_choices=[
Child('Expression', kind='Expr'),
Child('Availablity', kind='AvailabilityCondition'),
Child('MatchingPattern',
kind='MatchingPatternCondition'),
Child('OptionalBinding',
kind='OptionalBindingCondition'),
]),
Child('TrailingComma', kind='CommaToken',
is_optional=True),
]),
# availability-condition -> '#available' '(' availability-spec ')'
Node('AvailabilityCondition', kind='Syntax',
children=[
Child('PoundAvailableKeyword', kind='PoundAvailableToken'),
Child('LeftParen', kind='LeftParenToken'),
Child('AvailabilitySpec', kind='AvailabilitySpecList',
collection_element_name='AvailabilityArgument'),
Child('RightParen', kind='RightParenToken'),
]),
Node('MatchingPatternCondition', kind='Syntax',
children=[
Child('CaseKeyword', kind='CaseToken'),
Child('Pattern', kind='Pattern'),
Child('TypeAnnotation', kind='TypeAnnotation',
is_optional=True),
Child('Initializer', kind='InitializerClause'),
]),
Node('OptionalBindingCondition', kind='Syntax',
children=[
Child('LetOrVarKeyword', kind='Token',
token_choices=[
'LetToken', 'VarToken',
]),
Child('Pattern', kind='Pattern'),
Child('TypeAnnotation', kind='TypeAnnotation',
is_optional=True),
Child('Initializer', kind='InitializerClause'),
]),
# condition-list -> condition
# | condition ','? condition-list
Node('ConditionElementList', kind='SyntaxCollection',
element='ConditionElement'),
# A declaration in statement position.
# struct Foo {};
Node('DeclarationStmt', kind='Stmt',
children=[
Child('Declaration', kind='Decl'),
]),
# throw-stmt -> 'throw' expr ';'?
Node('ThrowStmt', kind='Stmt',
children=[
Child('ThrowKeyword', kind='ThrowToken'),
Child('Expression', kind='Expr'),
]),
# if-stmt -> identifier? ':'? 'if' condition-list code-block
# else-clause ';'?
Node('IfStmt', kind='Stmt',
traits=['WithCodeBlock', 'Labeled'],
children=[
Child('LabelName', kind='IdentifierToken',
is_optional=True),
Child('LabelColon', kind='ColonToken',
is_optional=True),
Child('IfKeyword', kind='IfToken'),
Child('Conditions', kind='ConditionElementList',
collection_element_name='Condition'),
Child('Body', kind='CodeBlock'),
Child('ElseKeyword', kind='ElseToken',
is_optional=True),
Child('ElseBody', kind='Syntax',
node_choices=[
Child('IfStmt', kind='IfStmt'),
Child('CodeBlock', kind='CodeBlock'),
],
is_optional=True),
]),
# else-if-continuation -> label? ':'? 'while' condition-list code-block ';'
Node('ElseIfContinuation', kind='Syntax',
children=[
Child('IfStatement', kind='IfStmt'),
]),
# else-clause -> 'else' code-block
Node('ElseBlock', kind='Syntax',
traits=['WithCodeBlock'],
children=[
Child('ElseKeyword', kind='ElseToken'),
Child('Body', kind='CodeBlock'),
]),
# switch-case -> unknown-attr? switch-case-label stmt-list
# | unknown-attr? switch-default-label stmt-list
Node('SwitchCase', kind='Syntax',
traits=['WithStatements'],
children=[
Child('UnknownAttr', kind='Attribute', is_optional=True),
Child('Label', kind='Syntax',
node_choices=[
Child('Default', kind='SwitchDefaultLabel'),
Child('Case', kind='SwitchCaseLabel'),
]),
Child('Statements', kind='CodeBlockItemList',
collection_element_name='Statement'),
]),
# switch-default-label -> 'default' ':'
Node('SwitchDefaultLabel', kind='Syntax',
children=[
Child('DefaultKeyword', kind='DefaultToken'),
Child('Colon', kind='ColonToken'),
]),
# case-item -> pattern where-clause? ','?
Node('CaseItem', kind='Syntax',
traits=['WithTrailingComma'],
children=[
Child('Pattern', kind='Pattern'),
Child('WhereClause', kind='WhereClause',
is_optional=True),
Child('TrailingComma', kind='CommaToken',
is_optional=True),
]),
# catch-item -> pattern? where-clause? ','?
Node('CatchItem', kind='Syntax',
traits=['WithTrailingComma'],
children=[
Child('Pattern', kind='Pattern', is_optional=True),
Child('WhereClause', kind='WhereClause',
is_optional=True),
Child('TrailingComma', kind='CommaToken',
is_optional=True),
]),
# switch-case-label -> 'case' case-item-list ':'
Node('SwitchCaseLabel', kind='Syntax',
children=[
Child('CaseKeyword', kind='CaseToken'),
Child('CaseItems', kind='CaseItemList',
collection_element_name='CaseItem'),
Child('Colon', kind='ColonToken'),
]),
# catch-clause 'catch' case-item-list? code-block
Node('CatchClause', kind='Syntax',
traits=['WithCodeBlock'],
children=[
Child('CatchKeyword', kind='CatchToken'),
Child('CatchItems', kind='CatchItemList',
collection_element_name='CatchItem', is_optional=True),
Child('Body', kind='CodeBlock'),
]),
# e.g. #assert(1 == 2)
Node('PoundAssertStmt', kind='Stmt',
children=[
Child('PoundAssert', kind='PoundAssertToken'),
Child('LeftParen', kind='LeftParenToken'),
Child('Condition', kind='Expr',
description='The assertion condition.'),
Child('Comma', kind='CommaToken', is_optional=True,
description='The comma after the assertion condition.'),
Child('Message', kind='StringLiteralToken', is_optional=True,
description='The assertion message.'),
Child('RightParen', kind='RightParenToken'),
]),
]