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

Unified Diff: sdk/lib/_internal/compiler/implementation/dart_backend/loop_rewriter.dart

Issue 694353007: Move dart2js from sdk/lib/_internal/compiler to pkg/compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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: sdk/lib/_internal/compiler/implementation/dart_backend/loop_rewriter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/dart_backend/loop_rewriter.dart b/sdk/lib/_internal/compiler/implementation/dart_backend/loop_rewriter.dart
deleted file mode 100644
index 8c233838dafb24461963e10c2988dd384f6444a2..0000000000000000000000000000000000000000
--- a/sdk/lib/_internal/compiler/implementation/dart_backend/loop_rewriter.dart
+++ /dev/null
@@ -1,134 +0,0 @@
-// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-library loop_rewriter;
-
-import 'tree_ir_nodes.dart';
-
-/// Rewrites [WhileTrue] statements with an [If] body into a [WhileCondition],
-/// in situations where only one of the branches contains a [Continue] to the
-/// loop. Schematically:
-///
-/// L:
-/// while (true) {
-/// if (E) {
-/// S1 (has references to L)
-/// } else {
-/// S2 (has no references to L)
-/// }
-/// }
-/// ==>
-/// L:
-/// while (E) {
-/// S1
-/// };
-/// S2
-///
-/// A similar transformation is used when S2 occurs in the 'then' position.
-///
-/// Note that the above pattern needs no iteration since nested ifs
-/// have been collapsed previously in the [StatementRewriter] phase.
-class LoopRewriter extends RecursiveVisitor {
-
- Set<Label> usedContinueLabels = new Set<Label>();
-
- void rewrite(FunctionDefinition function) {
- if (function.isAbstract) return;
-
- function.body = visitStatement(function.body);
- }
-
- Statement visitLabeledStatement(LabeledStatement node) {
- node.body = visitStatement(node.body);
- node.next = visitStatement(node.next);
- return node;
- }
-
- Statement visitAssign(Assign node) {
- // Clean up redundant assignments left behind in the previous phase.
- if (node.variable == node.definition) {
- --node.variable.readCount;
- --node.variable.writeCount;
- return visitStatement(node.next);
- }
- visitExpression(node.definition);
- node.next = visitStatement(node.next);
- return node;
- }
-
- Statement visitReturn(Return node) {
- visitExpression(node.value);
- return node;
- }
-
- Statement visitBreak(Break node) {
- return node;
- }
-
- Statement visitContinue(Continue node) {
- usedContinueLabels.add(node.target);
- return node;
- }
-
- Statement visitIf(If node) {
- visitExpression(node.condition);
- node.thenStatement = visitStatement(node.thenStatement);
- node.elseStatement = visitStatement(node.elseStatement);
- return node;
- }
-
- Statement visitWhileTrue(WhileTrue node) {
- assert(!usedContinueLabels.contains(node.label));
- if (node.body is If) {
- If body = node.body;
- body.thenStatement = visitStatement(body.thenStatement);
- bool thenHasContinue = usedContinueLabels.remove(node.label);
- body.elseStatement = visitStatement(body.elseStatement);
- bool elseHasContinue = usedContinueLabels.remove(node.label);
- if (thenHasContinue && !elseHasContinue) {
- node.label.binding = null; // Prepare to rebind the label.
- return new WhileCondition(
- node.label,
- body.condition,
- body.thenStatement,
- body.elseStatement);
- } else if (!thenHasContinue && elseHasContinue) {
- node.label.binding = null;
- return new WhileCondition(
- node.label,
- new Not(body.condition),
- body.elseStatement,
- body.thenStatement);
- }
- } else {
- node.body = visitStatement(node.body);
- usedContinueLabels.remove(node.label);
- }
- return node;
- }
-
- Statement visitWhileCondition(WhileCondition node) {
- // Note: not reachable but the implementation is trivial
- visitExpression(node.condition);
- node.body = visitStatement(node.body);
- node.next = visitStatement(node.next);
- return node;
- }
-
- Statement visitExpressionStatement(ExpressionStatement node) {
- visitExpression(node.expression);
- node.next = visitStatement(node.next);
- return node;
- }
-
- Statement visitFunctionDeclaration(FunctionDeclaration node) {
- new LoopRewriter().rewrite(node.definition);
- node.next = visitStatement(node.next);
- return node;
- }
-
- void visitFunctionExpression(FunctionExpression node) {
- new LoopRewriter().rewrite(node.definition);
- }
-}

Powered by Google App Engine
This is Rietveld 408576698