OLD | NEW |
---|---|
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 rewrite_async; | 5 library rewrite_async; |
6 | 6 |
7 import "dart:math" show max; | 7 import "dart:math" show max; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 | 9 |
10 import 'package:_internal/compiler/js_lib/shared/async_await_error_codes.dart' | 10 import 'package:_internal/compiler/js_lib/shared/async_await_error_codes.dart' |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
742 | 742 |
743 @override | 743 @override |
744 js.Expression visitAssignment(js.Assignment node) { | 744 js.Expression visitAssignment(js.Assignment node) { |
745 if (!shouldTransform(node)) { | 745 if (!shouldTransform(node)) { |
746 return new js.Assignment.compound(visitExpression(node.leftHandSide), | 746 return new js.Assignment.compound(visitExpression(node.leftHandSide), |
747 node.op, visitExpression(node.value)); | 747 node.op, visitExpression(node.value)); |
748 } | 748 } |
749 js.Expression leftHandSide = node.leftHandSide; | 749 js.Expression leftHandSide = node.leftHandSide; |
750 if (leftHandSide is js.VariableUse) { | 750 if (leftHandSide is js.VariableUse) { |
751 return withExpression(node.value, (js.Expression value) { | 751 return withExpression(node.value, (js.Expression value) { |
752 return new js.Assignment(leftHandSide, value); | 752 // visit the [js.VariableUse] to ensure renaming is done correctly. |
floitsch
2015/03/17 17:01:17
Capital "V".
sigurdm
2015/03/18 14:06:24
Done.
| |
753 return new js.Assignment.compound(visitExpression(leftHandSide), | |
floitsch
2015/03/17 17:01:17
Add a comment explaining that it is ok to use comp
sigurdm
2015/03/18 14:06:24
Done.
| |
754 node.op, | |
755 value); | |
753 }, store: false); | 756 }, store: false); |
754 } else if (leftHandSide is js.PropertyAccess) { | 757 } else if (leftHandSide is js.PropertyAccess) { |
755 return withExpressions([ | 758 return withExpressions([ |
756 leftHandSide.receiver, | 759 leftHandSide.receiver, |
757 leftHandSide.selector, | 760 leftHandSide.selector, |
758 node.value | 761 node.value |
759 ], (evaluated) { | 762 ], (evaluated) { |
760 return new js.Assignment.compound( | 763 return new js.Assignment.compound( |
761 new js.PropertyAccess(evaluated[0], evaluated[1]), node.op, | 764 new js.PropertyAccess(evaluated[0], evaluated[1]), node.op, |
762 evaluated[2]); | 765 evaluated[2]); |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1204 } | 1207 } |
1205 | 1208 |
1206 @override | 1209 @override |
1207 visitParameter(js.Parameter node) => unreachable(node); | 1210 visitParameter(js.Parameter node) => unreachable(node); |
1208 | 1211 |
1209 @override | 1212 @override |
1210 js.Expression visitPostfix(js.Postfix node) { | 1213 js.Expression visitPostfix(js.Postfix node) { |
1211 if (node.op == "++" || node.op == "--") { | 1214 if (node.op == "++" || node.op == "--") { |
1212 js.Expression argument = node.argument; | 1215 js.Expression argument = node.argument; |
1213 if (argument is js.VariableUse) { | 1216 if (argument is js.VariableUse) { |
1214 return new js.Postfix(node.op, argument); | 1217 return new js.Postfix(node.op, visitExpression(argument)); |
1215 } else if (argument is js.PropertyAccess) { | 1218 } else if (argument is js.PropertyAccess) { |
1216 return withExpression2(argument.receiver, argument.selector, | 1219 return withExpression2(argument.receiver, argument.selector, |
1217 (receiver, selector) { | 1220 (receiver, selector) { |
1218 return new js.Postfix( | 1221 return new js.Postfix( |
1219 node.op, new js.PropertyAccess(receiver, selector)); | 1222 node.op, new js.PropertyAccess(receiver, selector)); |
1220 }); | 1223 }); |
1221 } else { | 1224 } else { |
1222 throw "Unexpected postfix ${node.op} " | 1225 throw "Unexpected postfix ${node.op} " |
1223 "operator argument ${node.argument}"; | 1226 "operator argument ${node.argument}"; |
1224 } | 1227 } |
1225 } | 1228 } |
1226 return withExpression(node.argument, | 1229 return withExpression(node.argument, |
1227 (js.Expression argument) => new js.Postfix(node.op, argument), | 1230 (js.Expression argument) => new js.Postfix(node.op, argument), |
1228 store: false); | 1231 store: false); |
1229 } | 1232 } |
1230 | 1233 |
1231 @override | 1234 @override |
1232 js.Expression visitPrefix(js.Prefix node) { | 1235 js.Expression visitPrefix(js.Prefix node) { |
1233 if (node.op == "++" || node.op == "--") { | 1236 if (node.op == "++" || node.op == "--") { |
1234 js.Expression argument = node.argument; | 1237 js.Expression argument = node.argument; |
1235 if (argument is js.VariableUse) { | 1238 if (argument is js.VariableUse) { |
1236 return new js.Prefix(node.op, argument); | 1239 return new js.Prefix(node.op, visitExpression(argument)); |
1237 } else if (argument is js.PropertyAccess) { | 1240 } else if (argument is js.PropertyAccess) { |
1238 return withExpression2(argument.receiver, argument.selector, | 1241 return withExpression2(argument.receiver, argument.selector, |
1239 (receiver, selector) { | 1242 (receiver, selector) { |
1240 return new js.Prefix( | 1243 return new js.Prefix( |
1241 node.op, new js.PropertyAccess(receiver, selector)); | 1244 node.op, new js.PropertyAccess(receiver, selector)); |
1242 }); | 1245 }); |
1243 } else { | 1246 } else { |
1244 throw "Unexpected prefix ${node.op} operator " | 1247 throw "Unexpected prefix ${node.op} operator " |
1245 "argument ${node.argument}"; | 1248 "argument ${node.argument}"; |
1246 } | 1249 } |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1521 beginLabel(afterFinallyLabel); | 1524 beginLabel(afterFinallyLabel); |
1522 } | 1525 } |
1523 | 1526 |
1524 @override | 1527 @override |
1525 visitVariableDeclaration(js.VariableDeclaration node) { | 1528 visitVariableDeclaration(js.VariableDeclaration node) { |
1526 unreachable(node); | 1529 unreachable(node); |
1527 } | 1530 } |
1528 | 1531 |
1529 @override | 1532 @override |
1530 js.Expression visitVariableDeclarationList(js.VariableDeclarationList node) { | 1533 js.Expression visitVariableDeclarationList(js.VariableDeclarationList node) { |
1531 List<js.Assignment> initializations = new List<js.Assignment>(); | 1534 List<js.Expression> initializations = new List<js.Assignment>(); |
1532 | 1535 |
1533 // Declaration of local variables is hoisted outside the helper but the | 1536 // Declaration of local variables is hoisted outside the helper but the |
1534 // initialization is done here. | 1537 // initialization is done here. |
1535 for (js.VariableInitialization initialization in node.declarations) { | 1538 for (js.VariableInitialization initialization in node.declarations) { |
1536 js.VariableDeclaration declaration = initialization.declaration; | 1539 js.VariableDeclaration declaration = initialization.declaration; |
1537 localVariables.add(declaration); | 1540 localVariables.add(declaration); |
1538 if (initialization.value != null) { | 1541 if (initialization.value != null) { |
1539 withExpression(initialization.value, (js.Expression value) { | 1542 withExpression(initialization.value, (js.Expression value) { |
1540 initializations.add( | 1543 initializations.add( |
1541 new js.Assignment(new js.VariableUse(declaration.name), value)); | 1544 new js.Assignment(new js.VariableUse(declaration.name), value)); |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2529 return condition || body; | 2532 return condition || body; |
2530 } | 2533 } |
2531 | 2534 |
2532 @override | 2535 @override |
2533 bool visitDartYield(js.DartYield node) { | 2536 bool visitDartYield(js.DartYield node) { |
2534 hasYield = true; | 2537 hasYield = true; |
2535 visit(node.expression); | 2538 visit(node.expression); |
2536 return true; | 2539 return true; |
2537 } | 2540 } |
2538 } | 2541 } |
OLD | NEW |