| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 kernel.transformations.continuation; | 5 library kernel.transformations.continuation; |
| 6 | 6 |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import '../ast.dart'; | 9 import '../ast.dart'; |
| 10 import '../visitor.dart'; | 10 import '../visitor.dart'; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // The body will insert calls to | 146 // The body will insert calls to |
| 147 // :iterator.current_= | 147 // :iterator.current_= |
| 148 // :iterator.isYieldEach= | 148 // :iterator.isYieldEach= |
| 149 // and return `true` as long as it did something and `false` when it's done. | 149 // and return `true` as long as it did something and `false` when it's done. |
| 150 return enclosingFunction.body.accept(this); | 150 return enclosingFunction.body.accept(this); |
| 151 } | 151 } |
| 152 | 152 |
| 153 visitYieldStatement(YieldStatement node) { | 153 visitYieldStatement(YieldStatement node) { |
| 154 var transformedExpression = node.expression.accept(this); | 154 var transformedExpression = node.expression.accept(this); |
| 155 | 155 |
| 156 var statements = []; | 156 var statements = <Statement>[]; |
| 157 if (node.isYieldStar) { | 157 if (node.isYieldStar) { |
| 158 var markYieldEach = new ExpressionStatement(new PropertySet( | 158 var markYieldEach = new ExpressionStatement(new PropertySet( |
| 159 new VariableGet(iteratorVariable), | 159 new VariableGet(iteratorVariable), |
| 160 new Name("isYieldEach", helper.coreLibrary), | 160 new Name("isYieldEach", helper.coreLibrary), |
| 161 new BoolLiteral(true))); | 161 new BoolLiteral(true))); |
| 162 statements.add(markYieldEach); | 162 statements.add(markYieldEach); |
| 163 } | 163 } |
| 164 | 164 |
| 165 var setCurrentIteratorValue = new ExpressionStatement(new PropertySet( | 165 var setCurrentIteratorValue = new ExpressionStatement(new PropertySet( |
| 166 new VariableGet(iteratorVariable), | 166 new VariableGet(iteratorVariable), |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 new Block(initializers), new Block(updates))); | 491 new Block(initializers), new Block(updates))); |
| 492 | 492 |
| 493 LabeledStatement labeled = new LabeledStatement(null); | 493 LabeledStatement labeled = new LabeledStatement(null); |
| 494 if (cond != null) { | 494 if (cond != null) { |
| 495 loopBody.addAll(condEffects); | 495 loopBody.addAll(condEffects); |
| 496 } else { | 496 } else { |
| 497 cond = new BoolLiteral(true); | 497 cond = new BoolLiteral(true); |
| 498 } | 498 } |
| 499 loopBody.add( | 499 loopBody.add( |
| 500 new IfStatement(cond, new Block(newBody), new BreakStatement(labeled))); | 500 new IfStatement(cond, new Block(newBody), new BreakStatement(labeled))); |
| 501 labeled.body = | 501 labeled.body = new WhileStatement( |
| 502 new WhileStatement(new BoolLiteral(true), new Block(loopBody)) | 502 new BoolLiteral(true), new Block(loopBody))..parent = labeled; |
| 503 ..parent = labeled; | |
| 504 statements.add(new Block(<Statement>[] | 503 statements.add(new Block(<Statement>[] |
| 505 ..addAll(temps) | 504 ..addAll(temps) |
| 506 ..add(labeled))); | 505 ..add(labeled))); |
| 507 return null; | 506 return null; |
| 508 } | 507 } |
| 509 | 508 |
| 510 TreeNode visitForInStatement(ForInStatement stmt) { | 509 TreeNode visitForInStatement(ForInStatement stmt) { |
| 511 if (stmt.isAsync) { | 510 if (stmt.isAsync) { |
| 512 // Transform | 511 // Transform |
| 513 // | 512 // |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 this.awaitHelper); | 823 this.awaitHelper); |
| 825 | 824 |
| 826 factory HelperNodes.fromProgram(Program program) { | 825 factory HelperNodes.fromProgram(Program program) { |
| 827 Library findLibrary(String name) { | 826 Library findLibrary(String name) { |
| 828 Uri uri = Uri.parse(name); | 827 Uri uri = Uri.parse(name); |
| 829 for (var library in program.libraries) { | 828 for (var library in program.libraries) { |
| 830 if (library.importUri == uri) return library; | 829 if (library.importUri == uri) return library; |
| 831 } | 830 } |
| 832 throw 'Library "$name" not found'; | 831 throw 'Library "$name" not found'; |
| 833 } | 832 } |
| 833 |
| 834 Class findClass(Library library, String name) { | 834 Class findClass(Library library, String name) { |
| 835 for (var klass in library.classes) { | 835 for (var klass in library.classes) { |
| 836 if (klass.name == name) return klass; | 836 if (klass.name == name) return klass; |
| 837 } | 837 } |
| 838 throw 'Class "$name" not found'; | 838 throw 'Class "$name" not found'; |
| 839 } | 839 } |
| 840 |
| 840 Procedure findFactoryConstructor(Class klass, String name) { | 841 Procedure findFactoryConstructor(Class klass, String name) { |
| 841 for (var procedure in klass.procedures) { | 842 for (var procedure in klass.procedures) { |
| 842 if (procedure.isStatic && procedure.name.name == name) return procedure; | 843 if (procedure.isStatic && procedure.name.name == name) return procedure; |
| 843 } | 844 } |
| 844 throw 'Factory constructor "$klass.$name" not found'; | 845 throw 'Factory constructor "$klass.$name" not found'; |
| 845 } | 846 } |
| 847 |
| 846 Constructor findConstructor(Class klass, String name) { | 848 Constructor findConstructor(Class klass, String name) { |
| 847 for (var constructor in klass.constructors) { | 849 for (var constructor in klass.constructors) { |
| 848 if (constructor.name.name == name) return constructor; | 850 if (constructor.name.name == name) return constructor; |
| 849 } | 851 } |
| 850 throw 'Constructor "$klass.$name" not found'; | 852 throw 'Constructor "$klass.$name" not found'; |
| 851 } | 853 } |
| 854 |
| 852 Procedure findProcedure(Library library, String name) { | 855 Procedure findProcedure(Library library, String name) { |
| 853 for (var procedure in library.procedures) { | 856 for (var procedure in library.procedures) { |
| 854 if (procedure.name.name == name || | 857 if (procedure.name.name == name || |
| 855 procedure.name.name == '${library.name}::${name}') { | 858 procedure.name.name == '${library.name}::${name}') { |
| 856 return procedure; | 859 return procedure; |
| 857 } | 860 } |
| 858 } | 861 } |
| 859 throw 'Procedure "$name" not found'; | 862 throw 'Procedure "$name" not found'; |
| 860 } | 863 } |
| 861 | 864 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 890 findFactoryConstructor(completerClass, 'sync'), | 893 findFactoryConstructor(completerClass, 'sync'), |
| 891 findConstructor(syncIterableClass, ''), | 894 findConstructor(syncIterableClass, ''), |
| 892 findConstructor(streamIteratorClass, ''), | 895 findConstructor(streamIteratorClass, ''), |
| 893 findFactoryConstructor(futureClass, 'microtask'), | 896 findFactoryConstructor(futureClass, 'microtask'), |
| 894 findConstructor(streamControllerClass, ''), | 897 findConstructor(streamControllerClass, ''), |
| 895 findProcedure(asyncLibrary, '_asyncThenWrapperHelper'), | 898 findProcedure(asyncLibrary, '_asyncThenWrapperHelper'), |
| 896 findProcedure(asyncLibrary, '_asyncErrorWrapperHelper'), | 899 findProcedure(asyncLibrary, '_asyncErrorWrapperHelper'), |
| 897 findProcedure(asyncLibrary, '_awaitHelper')); | 900 findProcedure(asyncLibrary, '_awaitHelper')); |
| 898 } | 901 } |
| 899 } | 902 } |
| OLD | NEW |