Chromium Code Reviews| 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 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 397 /// where tempX is a fresh temporary variable. | 397 /// where tempX is a fresh temporary variable. |
| 398 js.Expression _storeIfNecessary(js.Expression result) { | 398 js.Expression _storeIfNecessary(js.Expression result) { |
| 399 // Note that RegExes, js.ArrayInitializer and js.ObjectInitializer are not | 399 // Note that RegExes, js.ArrayInitializer and js.ObjectInitializer are not |
| 400 // [js.Literal]s. | 400 // [js.Literal]s. |
| 401 if (result is js.Literal) return result; | 401 if (result is js.Literal) return result; |
| 402 js.Expression tempVar = useTempVar(allocateTempVar()); | 402 js.Expression tempVar = useTempVar(allocateTempVar()); |
| 403 addStatement(js.js.statement('# = #;', [tempVar, result])); | 403 addStatement(js.js.statement('# = #;', [tempVar, result])); |
| 404 return tempVar; | 404 return tempVar; |
| 405 } | 405 } |
| 406 | 406 |
| 407 withExpression(js.Expression node, fn(js.Expression result), {bool store}) { | 407 withExpression(js.Expression node, fn(js.Expression result), {bool store}) { |
|
floitsch
2015/03/03 13:40:41
Please add documentation what it does. (and what t
| |
| 408 int oldTempVarIndex = currentTempVarIndex; | 408 int oldTempVarIndex = currentTempVarIndex; |
| 409 js.Expression visited = visitExpression(node); | 409 js.Expression visited = visitExpression(node); |
| 410 if (store) { | 410 if (store) { |
| 411 visited = _storeIfNecessary(visited); | 411 visited = _storeIfNecessary(visited); |
| 412 } | 412 } |
| 413 var result = fn(visited); | 413 var result = fn(visited); |
| 414 currentTempVarIndex = oldTempVarIndex; | 414 currentTempVarIndex = oldTempVarIndex; |
| 415 return result; | 415 return result; |
| 416 } | 416 } |
| 417 | 417 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 824 @override | 824 @override |
| 825 void visitComment(js.Comment node) { | 825 void visitComment(js.Comment node) { |
| 826 addStatement(node); | 826 addStatement(node); |
| 827 } | 827 } |
| 828 | 828 |
| 829 @override | 829 @override |
| 830 js.Expression visitConditional(js.Conditional node) { | 830 js.Expression visitConditional(js.Conditional node) { |
| 831 if (!shouldTransform(node.then) && !shouldTransform(node.otherwise)) { | 831 if (!shouldTransform(node.then) && !shouldTransform(node.otherwise)) { |
| 832 return withExpression(node.condition, (js.Expression condition) { | 832 return withExpression(node.condition, (js.Expression condition) { |
| 833 return js.js('# ? # : #', [condition, node.then, node.otherwise]); | 833 return js.js('# ? # : #', [condition, node.then, node.otherwise]); |
| 834 }); | 834 }, store: false); |
| 835 } | 835 } |
| 836 int thenLabel = newLabel("then"); | 836 int thenLabel = newLabel("then"); |
| 837 int joinLabel = newLabel("join"); | 837 int joinLabel = newLabel("join"); |
| 838 int elseLabel = newLabel("else"); | 838 int elseLabel = newLabel("else"); |
| 839 withExpression(node.condition, (js.Expression condition) { | 839 withExpression(node.condition, (js.Expression condition) { |
| 840 addStatement(js.js.statement('# = # ? # : #;', | 840 addStatement(js.js.statement('# = # ? # : #;', |
| 841 [goto, condition, js.number(thenLabel), js.number(elseLabel)])); | 841 [goto, condition, js.number(thenLabel), js.number(elseLabel)])); |
| 842 }, store: false); | 842 }, store: false); |
| 843 addBreak(); | 843 addBreak(); |
| 844 beginLabel(thenLabel); | 844 beginLabel(thenLabel); |
| (...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2451 return condition || body; | 2451 return condition || body; |
| 2452 } | 2452 } |
| 2453 | 2453 |
| 2454 @override | 2454 @override |
| 2455 bool visitDartYield(js.DartYield node) { | 2455 bool visitDartYield(js.DartYield node) { |
| 2456 hasYield = true; | 2456 hasYield = true; |
| 2457 visit(node.expression); | 2457 visit(node.expression); |
| 2458 return true; | 2458 return true; |
| 2459 } | 2459 } |
| 2460 } | 2460 } |
| OLD | NEW |