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

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

Issue 2746333005: Parse for-look statements with Fasta. (Closed)
Patch Set: Update kompile.status file. 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
Index: pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
diff --git a/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart b/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
index 922da2b97c80c80994494ab509a2707d0284bccf..11ec061cd722eac598402d4ef56c87bb0e32bbf6 100644
--- a/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
+++ b/pkg/front_end/lib/src/fasta/analyzer/ast_builder.dart
@@ -415,8 +415,8 @@ class AstBuilder extends ScopeListener {
debugEvent("WhileStatement");
Statement body = pop();
ParenthesizedExpression condition = pop();
- pop(); // continue target
- pop(); // break target
+ exitContinueTarget();
+ exitBreakTarget();
push(ast.whileStatement(
toAnalyzerToken(whileKeyword),
condition.leftParenthesis,
@@ -475,25 +475,43 @@ class AstBuilder extends ScopeListener {
toAnalyzerToken(beginToken), statements, toAnalyzerToken(endToken)));
}
- void endForStatement(
- int updateExpressionCount, Token beginToken, Token endToken) {
+ void endForStatement(Token forKeyword, Token leftSeparator,
+ int updateExpressionCount, Token endToken) {
debugEvent("ForStatement");
Statement body = pop();
List<Expression> updates = popList(updateExpressionCount);
- ExpressionStatement condition = pop();
- VariableDeclarationStatement variables = pop();
+ Statement conditionStatement = pop();
+ Object initializerPart = pop();
+ exitLocalScope();
exitContinueTarget();
exitBreakTarget();
- exitLocalScope();
- BeginGroupToken leftParenthesis = beginToken.next;
+ BeginGroupToken leftParenthesis = forKeyword.next;
+
+ VariableDeclarationList variableList;
+ Expression initializer;
+ if (initializerPart is VariableDeclarationStatement) {
+ variableList = initializerPart.variables;
+ } else {
+ initializer = initializerPart as Expression;
+ }
+
+ Expression condition;
+ analyzer.Token rightSeparator;
+ if (conditionStatement is ExpressionStatement) {
+ condition = conditionStatement.expression;
+ rightSeparator = conditionStatement.semicolon;
+ } else {
+ rightSeparator = (conditionStatement as EmptyStatement).semicolon;
+ }
+
push(ast.forStatement(
- toAnalyzerToken(beginToken),
+ toAnalyzerToken(forKeyword),
toAnalyzerToken(leftParenthesis),
- variables?.variables,
- null, // initialization.
- variables?.semicolon,
- condition.expression,
- condition.semicolon,
+ variableList,
+ initializer,
+ toAnalyzerToken(leftSeparator),
+ condition,
+ rightSeparator,
updates,
toAnalyzerToken(leftParenthesis.endGroup),
body));
@@ -701,9 +719,9 @@ class AstBuilder extends ScopeListener {
Statement body = pop();
Expression iterator = pop();
Object variableOrDeclaration = pop();
- pop(); // local scope
- pop(); // continue target
- pop(); // break target
+ exitLocalScope();
+ exitContinueTarget();
+ exitBreakTarget();
if (variableOrDeclaration is SimpleIdentifier) {
push(ast.forEachStatementWithReference(
toAnalyzerToken(awaitToken),
@@ -1068,8 +1086,8 @@ class AstBuilder extends ScopeListener {
debugEvent("DoWhileStatement");
ParenthesizedExpression condition = pop();
Statement body = pop();
- pop(); // continue target
- pop(); // break target
+ exitContinueTarget();
+ exitBreakTarget();
push(ast.doStatement(
toAnalyzerToken(doKeyword),
body,
« no previous file with comments | « pkg/compiler/lib/src/parser/node_listener.dart ('k') | pkg/front_end/lib/src/fasta/kernel/body_builder.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698