Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library tree_ir_nodes; | 5 library tree_ir_nodes; |
| 6 | 6 |
| 7 import '../constants/values.dart' as values; | 7 import '../constants/values.dart' as values; |
| 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; | 8 import '../dart_types.dart' show DartType, InterfaceType, TypeVariableType; |
| 9 import '../elements/elements.dart'; | 9 import '../elements/elements.dart'; |
| 10 import '../io/source_information.dart' show SourceInformation; | 10 import '../io/source_information.dart' show SourceInformation; |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 } | 489 } |
| 490 | 490 |
| 491 Statement get next => null; | 491 Statement get next => null; |
| 492 void set next(Statement s) => throw 'UNREACHABLE'; | 492 void set next(Statement s) => throw 'UNREACHABLE'; |
| 493 | 493 |
| 494 accept(StatementVisitor visitor) => visitor.visitWhileTrue(this); | 494 accept(StatementVisitor visitor) => visitor.visitWhileTrue(this); |
| 495 accept1(StatementVisitor1 visitor, arg) => visitor.visitWhileTrue(this, arg); | 495 accept1(StatementVisitor1 visitor, arg) => visitor.visitWhileTrue(this, arg); |
| 496 } | 496 } |
| 497 | 497 |
| 498 /** | 498 /** |
| 499 * A while loop with a condition. If the condition is false, control resumes | 499 * A loop with a condition and update expressions. If there are any update |
| 500 * at the [next] statement. | 500 * expressions, this generates a for loop, otherwise a while loop. |
| 501 * | |
| 502 * When the condition is false, control resumes at the [next] statement. | |
| 501 * | 503 * |
| 502 * It is NOT valid to target this statement with a [Break]. | 504 * It is NOT valid to target this statement with a [Break]. |
| 503 * The only way to reach [next] is for the condition to evaluate to false. | 505 * The only way to reach [next] is for the condition to evaluate to false. |
| 504 * | 506 * |
| 505 * [WhileCondition] statements are introduced in the [LoopRewriter] and is | 507 * [WhileCondition] statements are introduced in the [LoopRewriter] and is |
| 506 * assumed not to occur before then. | 508 * assumed not to occur before then. |
| 507 */ | 509 */ |
| 508 class WhileCondition extends Loop { | 510 class WhileCondition extends Loop { |
|
Kevin Millikin (Google)
2015/08/13 11:32:47
Strange that While has updates. Maybe we call it
asgerf
2015/08/13 12:06:42
Renamed.
| |
| 509 final Label label; | 511 final Label label; |
| 510 Expression condition; | 512 Expression condition; |
| 513 List<Expression> updates; | |
| 511 Statement body; | 514 Statement body; |
| 512 Statement next; | 515 Statement next; |
| 513 | 516 |
| 514 WhileCondition(this.label, this.condition, this.body, | 517 WhileCondition(this.label, |
| 518 this.condition, | |
| 519 this.updates, | |
| 520 this.body, | |
| 515 this.next) { | 521 this.next) { |
| 516 assert(label.binding == null); | 522 assert(label.binding == null); |
| 517 label.binding = this; | 523 label.binding = this; |
| 518 } | 524 } |
| 519 | 525 |
| 520 accept(StatementVisitor visitor) => visitor.visitWhileCondition(this); | 526 accept(StatementVisitor visitor) => visitor.visitWhileCondition(this); |
| 521 accept1(StatementVisitor1 visitor, arg) { | 527 accept1(StatementVisitor1 visitor, arg) { |
| 522 return visitor.visitWhileCondition(this, arg); | 528 return visitor.visitWhileCondition(this, arg); |
| 523 } | 529 } |
| 524 } | 530 } |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 visitStatement(node.thenStatement); | 1141 visitStatement(node.thenStatement); |
| 1136 visitStatement(node.elseStatement); | 1142 visitStatement(node.elseStatement); |
| 1137 } | 1143 } |
| 1138 | 1144 |
| 1139 visitWhileTrue(WhileTrue node) { | 1145 visitWhileTrue(WhileTrue node) { |
| 1140 visitStatement(node.body); | 1146 visitStatement(node.body); |
| 1141 } | 1147 } |
| 1142 | 1148 |
| 1143 visitWhileCondition(WhileCondition node) { | 1149 visitWhileCondition(WhileCondition node) { |
| 1144 visitExpression(node.condition); | 1150 visitExpression(node.condition); |
| 1151 node.updates.forEach(visitExpression); | |
| 1145 visitStatement(node.body); | 1152 visitStatement(node.body); |
| 1146 visitStatement(node.next); | 1153 visitStatement(node.next); |
| 1147 } | 1154 } |
| 1148 | 1155 |
| 1149 visitExpressionStatement(ExpressionStatement inputNode) { | 1156 visitExpressionStatement(ExpressionStatement inputNode) { |
| 1150 // Iterate over chains of expression statements to avoid deep recursion. | 1157 // Iterate over chains of expression statements to avoid deep recursion. |
| 1151 Statement node = inputNode; | 1158 Statement node = inputNode; |
| 1152 while (node is ExpressionStatement) { | 1159 while (node is ExpressionStatement) { |
| 1153 ExpressionStatement stmt = node; | 1160 ExpressionStatement stmt = node; |
| 1154 visitExpression(stmt.expression); | 1161 visitExpression(stmt.expression); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1366 return node; | 1373 return node; |
| 1367 } | 1374 } |
| 1368 | 1375 |
| 1369 visitWhileTrue(WhileTrue node) { | 1376 visitWhileTrue(WhileTrue node) { |
| 1370 node.body = visitStatement(node.body); | 1377 node.body = visitStatement(node.body); |
| 1371 return node; | 1378 return node; |
| 1372 } | 1379 } |
| 1373 | 1380 |
| 1374 visitWhileCondition(WhileCondition node) { | 1381 visitWhileCondition(WhileCondition node) { |
| 1375 node.condition = visitExpression(node.condition); | 1382 node.condition = visitExpression(node.condition); |
| 1383 _replaceExpressions(node.updates); | |
| 1376 node.body = visitStatement(node.body); | 1384 node.body = visitStatement(node.body); |
| 1377 node.next = visitStatement(node.next); | 1385 node.next = visitStatement(node.next); |
| 1378 return node; | 1386 return node; |
| 1379 } | 1387 } |
| 1380 | 1388 |
| 1381 visitExpressionStatement(ExpressionStatement node) { | 1389 visitExpressionStatement(ExpressionStatement node) { |
| 1382 // Iterate over chains of expression statements to avoid deep recursion. | 1390 // Iterate over chains of expression statements to avoid deep recursion. |
| 1383 Statement first = node; | 1391 Statement first = node; |
| 1384 while (true) { | 1392 while (true) { |
| 1385 node.expression = visitExpression(node.expression); | 1393 node.expression = visitExpression(node.expression); |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1526 | 1534 |
| 1527 /// Number of uses of the current fallthrough target. | 1535 /// Number of uses of the current fallthrough target. |
| 1528 int get useCount => _stack.last.useCount; | 1536 int get useCount => _stack.last.useCount; |
| 1529 | 1537 |
| 1530 /// Indicate that a statement will fall through to the current fallthrough | 1538 /// Indicate that a statement will fall through to the current fallthrough |
| 1531 /// target. | 1539 /// target. |
| 1532 void use() { | 1540 void use() { |
| 1533 ++_stack.last.useCount; | 1541 ++_stack.last.useCount; |
| 1534 } | 1542 } |
| 1535 } | 1543 } |
| OLD | NEW |