Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: pkg/analyzer/lib/src/fasta/ast_builder.dart

Issue 2776743002: Parse LabeledStatement and SwitchStatement with Fasta. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_fasta_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/fasta/ast_builder.dart
diff --git a/pkg/analyzer/lib/src/fasta/ast_builder.dart b/pkg/analyzer/lib/src/fasta/ast_builder.dart
index 7c9d2ceb5c8265da56611974132c78ce3dec7b3d..96d367d1683ec3e746e94d4bd3e0d99c7103a247 100644
--- a/pkg/analyzer/lib/src/fasta/ast_builder.dart
+++ b/pkg/analyzer/lib/src/fasta/ast_builder.dart
@@ -902,6 +902,65 @@ class AstBuilder extends ScopeListener {
toAnalyzerToken(endToken)));
}
+ @override
+ void endSwitchBlock(int caseCount, Token leftBracket, Token rightBracket) {
+ debugEvent("SwitchBlock");
+ List<List<SwitchMember>> membersList = popList(caseCount);
+ exitBreakTarget();
+ exitLocalScope();
+ List<SwitchMember> members =
+ membersList?.expand((members) => members)?.toList() ?? <SwitchMember>[];
+ push(leftBracket);
+ push(members);
+ push(rightBracket);
+ }
+
+ @override
+ void handleSwitchCase(
+ int labelCount,
+ int expressionCount,
+ Token defaultKeyword,
+ int statementCount,
+ Token firstToken,
+ Token endToken) {
+ debugEvent("SwitchCase");
+ List<Statement> statements = popList(statementCount);
+ List<SwitchMember> members = popList(expressionCount) ?? [];
+ List<Label> labels = popList(labelCount);
+ if (defaultKeyword != null) {
+ members.add(ast.switchDefault(
+ <Label>[], defaultKeyword, defaultKeyword.next, <Statement>[]));
+ }
+ members.last.statements.addAll(statements);
+ members.first.labels.addAll(labels);
+ push(members);
+ }
+
+ @override
+ void handleCaseMatch(Token caseKeyword, Token colon) {
+ debugEvent("CaseMatch");
+ Expression expression = pop();
+ push(ast.switchCase(
+ <Label>[], caseKeyword, expression, colon, <Statement>[]));
+ }
+
+ @override
+ void endSwitchStatement(Token switchKeyword, Token endToken) {
+ debugEvent("SwitchStatement");
+ Token rightBracket = pop();
+ List<SwitchMember> members = pop();
+ Token leftBracket = pop();
+ ParenthesizedExpression expression = pop();
+ push(ast.switchStatement(
+ switchKeyword,
+ expression.leftParenthesis,
+ expression.expression,
+ expression.rightParenthesis,
+ leftBracket,
+ members,
+ rightBracket));
+ }
+
void handleCatchBlock(Token onKeyword, Token catchKeyword) {
debugEvent("CatchBlock");
Block body = pop();
@@ -944,6 +1003,13 @@ class AstBuilder extends ScopeListener {
toAnalyzerToken(finallyKeyword), finallyBlock));
}
+ @override
+ void handleLabel(Token colon) {
+ debugEvent("Label");
+ SimpleIdentifier name = pop();
+ push(ast.label(name, colon));
+ }
+
void handleNoExpression(Token token) {
debugEvent("NoExpression");
push(NullValue.Expression);
@@ -1306,6 +1372,14 @@ class AstBuilder extends ScopeListener {
}
@override
+ void endLabeledStatement(int labelCount) {
+ debugEvent("LabeledStatement");
+ Statement statement = pop();
+ List<Label> labels = popList(labelCount);
+ push(ast.labeledStatement(labels, statement));
+ }
+
+ @override
void endLibraryName(Token libraryKeyword, Token semicolon) {
debugEvent("LibraryName");
List<SimpleIdentifier> libraryName = pop();
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_fasta_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698