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

Unified Diff: pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart

Issue 1287253002: dart2js cps: Compile some loops as 'for' loops. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Update test expectations Created 5 years, 4 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/compiler/lib/src/tree_ir/tree_ir_nodes.dart
diff --git a/pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart b/pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart
index 8f0e85666c0f69773ef1daf68001d334d27bb93c..ed91773ef1aadac8ce238a4c89f7138e44e7e123 100644
--- a/pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart
+++ b/pkg/compiler/lib/src/tree_ir/tree_ir_nodes.dart
@@ -446,7 +446,7 @@ class FunctionExpression extends Expression {
}
}
-/// A [LabeledStatement] or [WhileTrue] or [WhileCondition].
+/// A [LabeledStatement] or [WhileTrue] or [For].
abstract class JumpTarget extends Statement {
Label get label;
Statement get body;
@@ -472,7 +472,7 @@ class LabeledStatement extends JumpTarget {
}
}
-/// A [WhileTrue] or [WhileCondition] loop.
+/// A [WhileTrue] or [For] loop.
abstract class Loop extends JumpTarget {
}
@@ -496,30 +496,36 @@ class WhileTrue extends Loop {
}
/**
- * A while loop with a condition. If the condition is false, control resumes
- * at the [next] statement.
+ * A loop with a condition and update expressions. If there are any update
+ * expressions, this generates a for loop, otherwise a while loop.
+ *
+ * When the condition is false, control resumes at the [next] statement.
*
* It is NOT valid to target this statement with a [Break].
* The only way to reach [next] is for the condition to evaluate to false.
*
- * [WhileCondition] statements are introduced in the [LoopRewriter] and is
+ * [For] statements are introduced in the [LoopRewriter] and are
* assumed not to occur before then.
*/
-class WhileCondition extends Loop {
+class For extends Loop {
final Label label;
Expression condition;
+ List<Expression> updates;
Statement body;
Statement next;
- WhileCondition(this.label, this.condition, this.body,
- this.next) {
+ For(this.label,
+ this.condition,
+ this.updates,
+ this.body,
+ this.next) {
assert(label.binding == null);
label.binding = this;
}
- accept(StatementVisitor visitor) => visitor.visitWhileCondition(this);
+ accept(StatementVisitor visitor) => visitor.visitFor(this);
accept1(StatementVisitor1 visitor, arg) {
- return visitor.visitWhileCondition(this, arg);
+ return visitor.visitFor(this, arg);
}
}
@@ -547,7 +553,7 @@ class Break extends Jump {
}
/**
- * A continue to an enclosing [WhileTrue] or [WhileCondition] loop.
+ * A continue to an enclosing [WhileTrue] or [For] loop.
* The continue targets the loop's body.
*/
class Continue extends Jump {
@@ -1013,7 +1019,7 @@ abstract class StatementVisitor<S> {
S visitContinue(Continue node);
S visitIf(If node);
S visitWhileTrue(WhileTrue node);
- S visitWhileCondition(WhileCondition node);
+ S visitFor(For node);
S visitExpressionStatement(ExpressionStatement node);
S visitTry(Try node);
S visitUnreachable(Unreachable node);
@@ -1030,7 +1036,7 @@ abstract class StatementVisitor1<S, A> {
S visitContinue(Continue node, A arg);
S visitIf(If node, A arg);
S visitWhileTrue(WhileTrue node, A arg);
- S visitWhileCondition(WhileCondition node, A arg);
+ S visitFor(For node, A arg);
S visitExpressionStatement(ExpressionStatement node, A arg);
S visitTry(Try node, A arg);
S visitUnreachable(Unreachable node, A arg);
@@ -1140,8 +1146,9 @@ abstract class RecursiveVisitor implements StatementVisitor, ExpressionVisitor {
visitStatement(node.body);
}
- visitWhileCondition(WhileCondition node) {
+ visitFor(For node) {
visitExpression(node.condition);
+ node.updates.forEach(visitExpression);
visitStatement(node.body);
visitStatement(node.next);
}
@@ -1371,8 +1378,9 @@ class RecursiveTransformer extends Transformer {
return node;
}
- visitWhileCondition(WhileCondition node) {
+ visitFor(For node) {
node.condition = visitExpression(node.condition);
+ _replaceExpressions(node.updates);
node.body = visitStatement(node.body);
node.next = visitStatement(node.next);
return node;
« no previous file with comments | « pkg/compiler/lib/src/tree_ir/tree_ir_integrity.dart ('k') | pkg/compiler/lib/src/tree_ir/tree_ir_tracer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698