Chromium Code Reviews| 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 '../core_types.dart'; | 10 import '../core_types.dart'; |
| 11 import '../visitor.dart'; | 11 import '../visitor.dart'; |
| 12 | 12 |
| 13 import 'async.dart'; | 13 import 'async.dart'; |
| 14 | 14 |
| 15 Program transformProgram(Program program) { | 15 Program transformProgram(Program program, |
|
Siggi Cherem (dart-lang)
2017/05/23 22:06:17
API design question for Kevin/Peter:
Would you ra
| |
| 16 {bool libraryFilter(Library library)}) { | |
| 16 var helper = new HelperNodes.fromProgram(program); | 17 var helper = new HelperNodes.fromProgram(program); |
| 17 var rewriter = new RecursiveContinuationRewriter(helper); | 18 var rewriter = new RecursiveContinuationRewriter(helper); |
| 18 return rewriter.rewriteProgram(program); | 19 for (var library in program.libraries) { |
| 20 if (libraryFilter == null || libraryFilter(library)) { | |
| 21 rewriter.rewriteLibrary(library); | |
| 22 } | |
| 23 } | |
| 24 return program; | |
| 19 } | 25 } |
| 20 | 26 |
| 21 class RecursiveContinuationRewriter extends Transformer { | 27 class RecursiveContinuationRewriter extends Transformer { |
| 22 final HelperNodes helper; | 28 final HelperNodes helper; |
| 23 final VariableDeclaration asyncJumpVariable = new VariableDeclaration( | 29 final VariableDeclaration asyncJumpVariable = new VariableDeclaration( |
| 24 ":await_jump_var", | 30 ":await_jump_var", |
| 25 initializer: new IntLiteral(0)); | 31 initializer: new IntLiteral(0)); |
| 26 final VariableDeclaration asyncContextVariable = | 32 final VariableDeclaration asyncContextVariable = |
| 27 new VariableDeclaration(":await_ctx_var"); | 33 new VariableDeclaration(":await_ctx_var"); |
| 28 | 34 |
| 29 RecursiveContinuationRewriter(this.helper); | 35 RecursiveContinuationRewriter(this.helper); |
| 30 | 36 |
| 31 Program rewriteProgram(Program node) { | 37 Program rewriteProgram(Program node) { |
| 32 return node.accept(this); | 38 return node.accept(this); |
| 33 } | 39 } |
| 34 | 40 |
| 41 Library rewriteLibrary(Library node) { | |
| 42 return node.accept(this); | |
| 43 } | |
| 44 | |
| 35 visitFunctionNode(FunctionNode node) { | 45 visitFunctionNode(FunctionNode node) { |
| 36 switch (node.asyncMarker) { | 46 switch (node.asyncMarker) { |
| 37 case AsyncMarker.Sync: | 47 case AsyncMarker.Sync: |
| 38 case AsyncMarker.SyncYielding: | 48 case AsyncMarker.SyncYielding: |
| 39 node.transformChildren(new RecursiveContinuationRewriter(helper)); | 49 node.transformChildren(new RecursiveContinuationRewriter(helper)); |
| 40 return node; | 50 return node; |
| 41 case AsyncMarker.SyncStar: | 51 case AsyncMarker.SyncStar: |
| 42 return new SyncStarFunctionRewriter(helper, node).rewrite(); | 52 return new SyncStarFunctionRewriter(helper, node).rewrite(); |
| 43 case AsyncMarker.Async: | 53 case AsyncMarker.Async: |
| 44 return new AsyncFunctionRewriter(helper, node).rewrite(); | 54 return new AsyncFunctionRewriter(helper, node).rewrite(); |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 926 coreTypes.syncIterableDefaultConstructor, | 936 coreTypes.syncIterableDefaultConstructor, |
| 927 coreTypes.streamIteratorDefaultConstructor, | 937 coreTypes.streamIteratorDefaultConstructor, |
| 928 coreTypes.futureMicrotaskConstructor, | 938 coreTypes.futureMicrotaskConstructor, |
| 929 coreTypes.asyncStarStreamControllerDefaultConstructor, | 939 coreTypes.asyncStarStreamControllerDefaultConstructor, |
| 930 coreTypes.asyncThenWrapperHelperProcedure, | 940 coreTypes.asyncThenWrapperHelperProcedure, |
| 931 coreTypes.asyncErrorWrapperHelperProcedure, | 941 coreTypes.asyncErrorWrapperHelperProcedure, |
| 932 coreTypes.awaitHelperProcedure, | 942 coreTypes.awaitHelperProcedure, |
| 933 coreTypes); | 943 coreTypes); |
| 934 } | 944 } |
| 935 } | 945 } |
| OLD | NEW |