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.optimization.statement_rewriter; | 5 library tree_ir.optimization.statement_rewriter; |
6 | 6 |
7 import 'optimization.dart' show Pass; | 7 import 'optimization.dart' show Pass; |
8 import '../tree_ir_nodes.dart'; | 8 import '../tree_ir_nodes.dart'; |
| 9 import '../../io/source_information.dart'; |
9 | 10 |
10 /** | 11 /** |
11 * Translates to direct-style. | 12 * Translates to direct-style. |
12 * | 13 * |
13 * In addition to the general IR constraints (see [CheckTreeIntegrity]), | 14 * In addition to the general IR constraints (see [CheckTreeIntegrity]), |
14 * the input is assumed to satisfy the following criteria: | 15 * the input is assumed to satisfy the following criteria: |
15 * | 16 * |
16 * All expressions other than those nested in [Assign] or [ExpressionStatement] | 17 * All expressions other than those nested in [Assign] or [ExpressionStatement] |
17 * must be simple. A [VariableUse] and [This] is a simple expression. | 18 * must be simple. A [VariableUse] and [This] is a simple expression. |
18 * The right-hand of an [Assign] may not be an [Assign]. | 19 * The right-hand of an [Assign] may not be an [Assign]. |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 } | 918 } |
918 return s; | 919 return s; |
919 } | 920 } |
920 if (s is Continue && t is Continue && s.target == t.target) { | 921 if (s is Continue && t is Continue && s.target == t.target) { |
921 --t.target.useCount; // Two continues become one. | 922 --t.target.useCount; // Two continues become one. |
922 return s; | 923 return s; |
923 } | 924 } |
924 if (s is Return && t is Return) { | 925 if (s is Return && t is Return) { |
925 CombinedExpressions values = combineExpressions(s.value, t.value); | 926 CombinedExpressions values = combineExpressions(s.value, t.value); |
926 if (values != null) { | 927 if (values != null) { |
927 return new Return(values.combined); | 928 // TODO(johnniwinther): Handle multiple source informations. |
| 929 SourceInformation sourceInformation = s.sourceInformation != null |
| 930 ? s.sourceInformation : t.sourceInformation; |
| 931 return new Return(values.combined, |
| 932 sourceInformation: sourceInformation); |
928 } | 933 } |
929 } | 934 } |
930 if (s is ExpressionStatement && t is ExpressionStatement) { | 935 if (s is ExpressionStatement && t is ExpressionStatement) { |
931 CombinedExpressions values = | 936 CombinedExpressions values = |
932 combineExpressions(s.expression, t.expression); | 937 combineExpressions(s.expression, t.expression); |
933 if (values == null) return null; | 938 if (values == null) return null; |
934 environment.add(values.combined); | 939 environment.add(values.combined); |
935 Variable leftHand = getLeftHand(values.combined); | 940 Variable leftHand = getLeftHand(values.combined); |
936 pushDominatingAssignment(leftHand); | 941 pushDominatingAssignment(leftHand); |
937 Statement next = combineStatements(s.next, t.next); | 942 Statement next = combineStatements(s.next, t.next); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 VariableUseVisitor(this.callback); | 1165 VariableUseVisitor(this.callback); |
1161 | 1166 |
1162 visitVariableUse(VariableUse use) => callback(use); | 1167 visitVariableUse(VariableUse use) => callback(use); |
1163 | 1168 |
1164 visitInnerFunction(FunctionDefinition node) {} | 1169 visitInnerFunction(FunctionDefinition node) {} |
1165 | 1170 |
1166 static void visit(Expression node, VariableUseCallback callback) { | 1171 static void visit(Expression node, VariableUseCallback callback) { |
1167 new VariableUseVisitor(callback).visitExpression(node); | 1172 new VariableUseVisitor(callback).visitExpression(node); |
1168 } | 1173 } |
1169 } | 1174 } |
OLD | NEW |