| 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.setup_builtin_library; | 5 library kernel.transformations.setup_builtin_library; |
| 6 | 6 |
| 7 import '../ast.dart'; | 7 import '../ast.dart'; |
| 8 | 8 |
| 9 // The DartVM has a special `dart:_builtin` library which exposes a | 9 // The DartVM has a special `dart:_builtin` library which exposes a |
| 10 // `_getMainClosure()` method. We need to change this method to return a | 10 // `_getMainClosure()` method. We need to change this method to return a |
| 11 // closure of `main()`. | 11 // closure of `main()`. |
| 12 Program transformProgram(Program program, | 12 Program transformProgram(Program program, |
| 13 {String libraryUri: 'dart:_builtin'}) { | 13 {String libraryUri: 'dart:_builtin'}) { |
| 14 Procedure mainMethod = program.mainMethod; | 14 Procedure mainMethod = program.mainMethod; |
| 15 | 15 |
| 16 if (mainMethod == null) return program; |
| 17 |
| 16 Library builtinLibrary; | 18 Library builtinLibrary; |
| 17 for (Library library in program.libraries) { | 19 for (Library library in program.libraries) { |
| 18 if (library.importUri.toString() == libraryUri) { | 20 if (library.importUri.toString() == libraryUri) { |
| 19 builtinLibrary = library; | 21 builtinLibrary = library; |
| 20 break; | 22 break; |
| 21 } | 23 } |
| 22 } | 24 } |
| 23 | 25 |
| 24 if (builtinLibrary == null) { | 26 if (builtinLibrary == null) { |
| 25 throw new Exception('Could not find "dart:_builtin" library'); | 27 throw new Exception('Could not find "dart:_builtin" library'); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 if (getMainClosure == null) { | 38 if (getMainClosure == null) { |
| 37 throw new Exception('Could not find "_getMainClosure" in "$libraryUri"'); | 39 throw new Exception('Could not find "_getMainClosure" in "$libraryUri"'); |
| 38 } | 40 } |
| 39 | 41 |
| 40 var returnMainStatement = new ReturnStatement(new StaticGet(mainMethod)); | 42 var returnMainStatement = new ReturnStatement(new StaticGet(mainMethod)); |
| 41 getMainClosure.body = returnMainStatement; | 43 getMainClosure.body = returnMainStatement; |
| 42 returnMainStatement.parent = getMainClosure; | 44 returnMainStatement.parent = getMainClosure; |
| 43 | 45 |
| 44 return program; | 46 return program; |
| 45 } | 47 } |
| OLD | NEW |