Skip to content

Commit

Permalink
Parser and listener API changes for supporting pattern guards.
Browse files Browse the repository at this point in the history
These are in their own CL so that it's easy to verify that no
functionalty has changed, even though a lot of parser expectations
files are affected.

In a follow-up CL, I'll add code that actually parses pattern guards.

Bug: #50035
Change-Id: I79f5a02df45e29b69aa4d8348cfdf27042ada9d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/264020
Reviewed-by: Jens Johansen <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
  • Loading branch information
stereotype441 authored and Commit Queue committed Oct 14, 2022
1 parent 3fa0a2f commit 4cf63fb
Show file tree
Hide file tree
Showing 571 changed files with 1,905 additions and 1,893 deletions.
12 changes: 6 additions & 6 deletions pkg/_fe_analyzer_shared/lib/src/parser/forwarding_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ class ForwardingListener implements Listener {
}

@override
void endCaseExpression(Token colon) {
listener?.endCaseExpression(colon);
void endCaseExpression(Token? when, Token colon) {
listener?.endCaseExpression(when, colon);
}

@override
Expand Down Expand Up @@ -1292,8 +1292,8 @@ class ForwardingListener implements Listener {
}

@override
void handleCaseMatch(Token caseKeyword, Token colon) {
listener?.handleCaseMatch(caseKeyword, colon);
void handleCaseMatch(Token caseKeyword, Token? when, Token colon) {
listener?.handleCaseMatch(caseKeyword, when, colon);
}

@override
Expand Down Expand Up @@ -1772,8 +1772,8 @@ class ForwardingListener implements Listener {
}

@override
void handleParenthesizedCondition(Token token, Token? case_) {
listener?.handleParenthesizedCondition(token, case_);
void handleParenthesizedCondition(Token token, Token? case_, Token? when) {
listener?.handleParenthesizedCondition(token, case_, when);
}

@override
Expand Down
6 changes: 3 additions & 3 deletions pkg/_fe_analyzer_shared/lib/src/parser/listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Listener implements UnescapeErrorListener {

void beginCaseExpression(Token caseKeyword) {}

void endCaseExpression(Token colon) {
void endCaseExpression(Token? when, Token colon) {
logEvent("CaseExpression");
}

Expand Down Expand Up @@ -1351,7 +1351,7 @@ class Listener implements UnescapeErrorListener {

void beginTryStatement(Token token) {}

void handleCaseMatch(Token caseKeyword, Token colon) {
void handleCaseMatch(Token caseKeyword, Token? when, Token colon) {
logEvent("CaseMatch");
}

Expand Down Expand Up @@ -1849,7 +1849,7 @@ class Listener implements UnescapeErrorListener {
/// - do while loop
/// - switch statement
/// - while loop
void handleParenthesizedCondition(Token token, Token? case_) {
void handleParenthesizedCondition(Token token, Token? case_, Token? when) {
logEvent("ParenthesizedCondition");
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6241,10 +6241,11 @@ class Parser {
Token case_ = token = next;
token = parsePattern(token);
token = ensureCloseParen(token, begin);
listener.handleParenthesizedCondition(begin, case_);
listener.handleParenthesizedCondition(begin, case_, null);
} else {
token = ensureCloseParen(token, begin);
listener.handleParenthesizedCondition(begin, /* case_ = */ null);
listener.handleParenthesizedCondition(
begin, /* case_ = */ null, /* when = */ null);
}
assert(optional(')', token));
return token;
Expand Down Expand Up @@ -8258,8 +8259,8 @@ class Parser {
token = parseExpression(caseKeyword);
}
token = ensureColon(token);
listener.endCaseExpression(token);
listener.handleCaseMatch(caseKeyword, token);
listener.endCaseExpression(null, token);
listener.handleCaseMatch(caseKeyword, null, token);
expressionCount++;
peek = peekPastLabels(token.next!);
} else if (expressionCount > 0) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/_fe_analyzer_shared/lib/src/parser/stack_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ abstract class StackListener extends Listener {
}

@override
void handleParenthesizedCondition(Token token, Token? case_) {
void handleParenthesizedCondition(Token token, Token? case_, Token? when) {
debugEvent("handleParenthesizedCondition");
}

Expand Down Expand Up @@ -482,7 +482,7 @@ abstract class StackListener extends Listener {
}

@override
void endCaseExpression(Token colon) {
void endCaseExpression(Token? when, Token colon) {
debugEvent("CaseExpression");
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3276,7 +3276,7 @@ class AstBuilder extends StackListener {
}

@override
void handleCaseMatch(Token caseKeyword, Token colon) {
void handleCaseMatch(Token caseKeyword, Token? when, Token colon) {
assert(optional('case', caseKeyword));
assert(optional(':', colon));
debugEvent("CaseMatch");
Expand Down Expand Up @@ -4556,7 +4556,8 @@ class AstBuilder extends StackListener {
}

@override
void handleParenthesizedCondition(Token leftParenthesis, Token? case_) {
void handleParenthesizedCondition(
Token leftParenthesis, Token? case_, Token? when) {
ExpressionImpl condition;
CaseClauseImpl? caseClause;
if (case_ != null) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyzer/test/generated/parser_fasta_listener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,9 @@ class ForwardingTestListener extends ForwardingListener {
}

@override
void endCaseExpression(Token colon) {
void endCaseExpression(Token? when, Token colon) {
end('CaseExpression');
super.endCaseExpression(colon);
super.endCaseExpression(when, colon);
}

@override
Expand Down
6 changes: 3 additions & 3 deletions pkg/front_end/lib/src/fasta/kernel/body_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2279,7 +2279,7 @@ class BodyBuilder extends StackListenerImpl
}

@override
void handleParenthesizedCondition(Token token, Token? case_) {
void handleParenthesizedCondition(Token token, Token? case_, Token? when) {
if (case_ != null) {
assert(checkState(token, [
unionOfKinds([
Expand Down Expand Up @@ -2507,7 +2507,7 @@ class BodyBuilder extends StackListenerImpl
}

@override
void endCaseExpression(Token colon) {
void endCaseExpression(Token? when, Token colon) {
assert(checkState(colon, [
unionOfKinds([
ValueKinds.Expression,
Expand Down Expand Up @@ -7208,7 +7208,7 @@ class BodyBuilder extends StackListenerImpl
}

@override
void handleCaseMatch(Token caseKeyword, Token colon) {
void handleCaseMatch(Token caseKeyword, Token? when, Token colon) {
debugEvent("CaseMatch");
// Do nothing. Handled by [handleSwitchCase].
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ class _MacroListener implements Listener {
}

@override
void endCaseExpression(Token colon) {
void endCaseExpression(Token? when, Token colon) {
_unsupported();
}

Expand Down Expand Up @@ -1580,7 +1580,7 @@ class _MacroListener implements Listener {
}

@override
void handleCaseMatch(Token caseKeyword, Token colon) {
void handleCaseMatch(Token caseKeyword, Token? when, Token colon) {
_unsupported();
}

Expand Down Expand Up @@ -2003,7 +2003,7 @@ class _MacroListener implements Listener {
}

@override
void handleParenthesizedCondition(Token token, Token? case_) {
void handleParenthesizedCondition(Token token, Token? case_, Token? when) {
_unknown();
}

Expand Down
25 changes: 16 additions & 9 deletions pkg/front_end/lib/src/fasta/util/parser_ast_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ abstract class AbstractParserAstListener implements Listener {
}

@override
void endCaseExpression(Token colon) {
void endCaseExpression(Token? when, Token colon) {
CaseExpressionEnd data =
new CaseExpressionEnd(ParserAstType.END, colon: colon);
new CaseExpressionEnd(ParserAstType.END, when: when, colon: colon);
seen(data);
}

Expand Down Expand Up @@ -1780,9 +1780,9 @@ abstract class AbstractParserAstListener implements Listener {
}

@override
void handleCaseMatch(Token caseKeyword, Token colon) {
void handleCaseMatch(Token caseKeyword, Token? when, Token colon) {
CaseMatchHandle data = new CaseMatchHandle(ParserAstType.HANDLE,
caseKeyword: caseKeyword, colon: colon);
caseKeyword: caseKeyword, when: when, colon: colon);
seen(data);
}

Expand Down Expand Up @@ -2511,11 +2511,12 @@ abstract class AbstractParserAstListener implements Listener {
}

@override
void handleParenthesizedCondition(Token token, Token? case_) {
void handleParenthesizedCondition(Token token, Token? case_, Token? when) {
ParenthesizedConditionHandle data = new ParenthesizedConditionHandle(
ParserAstType.HANDLE,
token: token,
case_: case_);
case_: case_,
when: when);
seen(data);
}

Expand Down Expand Up @@ -3024,13 +3025,15 @@ class CaseExpressionBegin extends ParserAstNode {
}

class CaseExpressionEnd extends ParserAstNode {
final Token? when;
final Token colon;

CaseExpressionEnd(ParserAstType type, {required this.colon})
CaseExpressionEnd(ParserAstType type, {this.when, required this.colon})
: super("CaseExpression", type);

@override
Map<String, Object?> get deprecatedArguments => {
"when": when,
"colon": colon,
};
}
Expand Down Expand Up @@ -6005,15 +6008,17 @@ class TryStatementBegin extends ParserAstNode {

class CaseMatchHandle extends ParserAstNode {
final Token caseKeyword;
final Token? when;
final Token colon;

CaseMatchHandle(ParserAstType type,
{required this.caseKeyword, required this.colon})
{required this.caseKeyword, this.when, required this.colon})
: super("CaseMatch", type);

@override
Map<String, Object?> get deprecatedArguments => {
"caseKeyword": caseKeyword,
"when": when,
"colon": colon,
};
}
Expand Down Expand Up @@ -7314,15 +7319,17 @@ class InvalidOperatorNameHandle extends ParserAstNode {
class ParenthesizedConditionHandle extends ParserAstNode {
final Token token;
final Token? case_;
final Token? when;

ParenthesizedConditionHandle(ParserAstType type,
{required this.token, this.case_})
{required this.token, this.case_, this.when})
: super("ParenthesizedCondition", type);

@override
Map<String, Object?> get deprecatedArguments => {
"token": token,
"case_": case_,
"when": when,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ beginCompilationUnit(foo)
handleLiteralNull(null)
endBinaryExpression(==)
endBinaryExpression(||)
handleParenthesizedCondition((, null)
handleParenthesizedCondition((, null, null)
beginThenStatement({)
beginBlock({, BlockKind(statement))
beginReturnStatement(return)
Expand Down Expand Up @@ -124,7 +124,7 @@ beginCompilationUnit(foo)
handleLiteralNull(null)
endBinaryExpression(==)
endBinaryExpression(&&)
handleParenthesizedCondition((, null)
handleParenthesizedCondition((, null, null)
beginThenStatement({)
beginBlock({, BlockKind(statement))
beginReturnStatement(return)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ parseUnit(foo)
listener: endBinaryExpression(==)
listener: endBinaryExpression(||)
ensureCloseParen(null, ()
listener: handleParenthesizedCondition((, null)
listener: handleParenthesizedCondition((, null, null)
listener: beginThenStatement({)
parseStatement())
parseStatementX())
Expand Down Expand Up @@ -280,7 +280,7 @@ parseUnit(foo)
listener: endBinaryExpression(==)
listener: endBinaryExpression(&&)
ensureCloseParen(null, ()
listener: handleParenthesizedCondition((, null)
listener: handleParenthesizedCondition((, null, null)
listener: beginThenStatement({)
parseStatement())
parseStatementX())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ beginCompilationUnit(foo)
handleLiteralNull(null)
endBinaryExpression(==)
endBinaryExpression(||)
handleParenthesizedCondition((, null)
handleParenthesizedCondition((, null, null)
beginThenStatement({)
beginBlock({, BlockKind(statement))
beginReturnStatement(return)
Expand Down Expand Up @@ -150,7 +150,7 @@ beginCompilationUnit(foo)
handleLiteralNull(null)
endBinaryExpression(==)
endBinaryExpression(||)
handleParenthesizedCondition((, null)
handleParenthesizedCondition((, null, null)
beginThenStatement({)
beginBlock({, BlockKind(statement))
beginReturnStatement(return)
Expand Down Expand Up @@ -209,7 +209,7 @@ beginCompilationUnit(foo)
handleLiteralNull(null)
endBinaryExpression(==)
endBinaryExpression(&&)
handleParenthesizedCondition((, null)
handleParenthesizedCondition((, null, null)
beginThenStatement({)
beginBlock({, BlockKind(statement))
beginReturnStatement(return)
Expand Down Expand Up @@ -287,7 +287,7 @@ beginCompilationUnit(foo)
handleLiteralNull(null)
endBinaryExpression(==)
endBinaryExpression(&&)
handleParenthesizedCondition((, null)
handleParenthesizedCondition((, null, null)
beginThenStatement({)
beginBlock({, BlockKind(statement))
beginReturnStatement(return)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ parseUnit(foo)
listener: endBinaryExpression(==)
listener: endBinaryExpression(||)
ensureCloseParen(null, ()
listener: handleParenthesizedCondition((, null)
listener: handleParenthesizedCondition((, null, null)
listener: beginThenStatement({)
parseStatement())
parseStatementX())
Expand Down Expand Up @@ -337,7 +337,7 @@ parseUnit(foo)
listener: endBinaryExpression(==)
listener: endBinaryExpression(||)
ensureCloseParen(null, ()
listener: handleParenthesizedCondition((, null)
listener: handleParenthesizedCondition((, null, null)
listener: beginThenStatement({)
parseStatement())
parseStatementX())
Expand Down Expand Up @@ -489,7 +489,7 @@ parseUnit(foo)
listener: endBinaryExpression(==)
listener: endBinaryExpression(&&)
ensureCloseParen(null, ()
listener: handleParenthesizedCondition((, null)
listener: handleParenthesizedCondition((, null, null)
listener: beginThenStatement({)
parseStatement())
parseStatementX())
Expand Down Expand Up @@ -701,7 +701,7 @@ parseUnit(foo)
listener: endBinaryExpression(==)
listener: endBinaryExpression(&&)
ensureCloseParen(null, ()
listener: handleParenthesizedCondition((, null)
listener: handleParenthesizedCondition((, null, null)
listener: beginThenStatement({)
parseStatement())
parseStatementX())
Expand Down
Loading

0 comments on commit 4cf63fb

Please sign in to comment.