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

Side by Side Diff: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart

Issue 759193005: Add support for fields to the new dart backend. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix dart2js-cps Created 6 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 part of tree_ir.optimization; 5 part of tree_ir.optimization;
6 6
7 /** 7 /**
8 * Performs the following transformations on the tree: 8 * Performs the following transformations on the tree:
9 * - Assignment propagation 9 * - Assignment propagation
10 * - If-to-conditional conversion 10 * - If-to-conditional conversion
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 /// for a break to L' if L maps to L'. 100 /// for a break to L' if L maps to L'.
101 Map<Label, Jump> labelRedirects = <Label, Jump>{}; 101 Map<Label, Jump> labelRedirects = <Label, Jump>{};
102 102
103 /// Returns the redirect target of [label] or [label] itself if it should not 103 /// Returns the redirect target of [label] or [label] itself if it should not
104 /// be redirected. 104 /// be redirected.
105 Jump redirect(Jump jump) { 105 Jump redirect(Jump jump) {
106 Jump newJump = labelRedirects[jump.target]; 106 Jump newJump = labelRedirects[jump.target];
107 return newJump != null ? newJump : jump; 107 return newJump != null ? newJump : jump;
108 } 108 }
109 109
110 void rewrite(FunctionDefinition definition) { 110 void rewrite(ExecutableDefinition definition) => definition.acceptPass(this);
111
112 void rewriteFieldDefinition(FieldDefinition definition) {
113 environment = <Assign>[];
114 definition.body = visitStatement(definition.body);
115
116 // TODO(kmillikin): Allow definitions that are not propagated. Here,
117 // this means rebuilding the binding with a recursively unnamed definition,
118 // or else introducing a variable definition and an assignment.
119 assert(environment.isEmpty);
120 }
121
122 void rewriteFunctionDefinition(FunctionDefinition definition) {
111 if (definition.isAbstract) return; 123 if (definition.isAbstract) return;
112 124
113 environment = <Assign>[]; 125 environment = <Assign>[];
114 definition.body = visitStatement(definition.body); 126 definition.body = visitStatement(definition.body);
115 127
116 // TODO(kmillikin): Allow definitions that are not propagated. Here, 128 // TODO(kmillikin): Allow definitions that are not propagated. Here,
117 // this means rebuilding the binding with a recursively unnamed definition, 129 // this means rebuilding the binding with a recursively unnamed definition,
118 // or else introducing a variable definition and an assignment. 130 // or else introducing a variable definition and an assignment.
119 assert(environment.isEmpty); 131 assert(environment.isEmpty);
120 } 132 }
121 133
134
122 Expression visitExpression(Expression e) => e.processed ? e : e.accept(this); 135 Expression visitExpression(Expression e) => e.processed ? e : e.accept(this);
123 136
124 Expression visitVariable(Variable node) { 137 Expression visitVariable(Variable node) {
125 // Propagate a variable's definition to its use site if: 138 // Propagate a variable's definition to its use site if:
126 // 1. It has a single use, to avoid code growth and potential duplication 139 // 1. It has a single use, to avoid code growth and potential duplication
127 // of side effects, AND 140 // of side effects, AND
128 // 2. It was the most recent expression evaluated so that we do not 141 // 2. It was the most recent expression evaluated so that we do not
129 // reorder expressions with side effects. 142 // reorder expressions with side effects.
130 if (!environment.isEmpty && 143 if (!environment.isEmpty &&
131 environment.last.variable == node && 144 environment.last.variable == node &&
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 } 555 }
543 556
544 Expression makeCondition(Expression e, bool polarity) { 557 Expression makeCondition(Expression e, bool polarity) {
545 return polarity ? e : new Not(e); 558 return polarity ? e : new Not(e);
546 } 559 }
547 560
548 Statement getBranch(If node, bool polarity) { 561 Statement getBranch(If node, bool polarity) {
549 return polarity ? node.thenStatement : node.elseStatement; 562 return polarity ? node.thenStatement : node.elseStatement;
550 } 563 }
551 } 564 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698