| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 dart2js.library_loader; | 5 library dart2js.library_loader; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'common/names.dart' show Uris; | 9 import 'common/names.dart' show Uris; |
| 10 import 'common/tasks.dart' show CompilerTask, Measurer; | 10 import 'common/tasks.dart' show CompilerTask, Measurer; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 DeferredLoaderGetterElementX, | 23 DeferredLoaderGetterElementX, |
| 24 ErroneousElementX, | 24 ErroneousElementX, |
| 25 ExportElementX, | 25 ExportElementX, |
| 26 ImportElementX, | 26 ImportElementX, |
| 27 LibraryElementX, | 27 LibraryElementX, |
| 28 LibraryDependencyElementX, | 28 LibraryDependencyElementX, |
| 29 PrefixElementX, | 29 PrefixElementX, |
| 30 SyntheticImportElement; | 30 SyntheticImportElement; |
| 31 import 'enqueue.dart' show DeferredAction; | 31 import 'enqueue.dart' show DeferredAction; |
| 32 import 'environment.dart'; | 32 import 'environment.dart'; |
| 33 import 'io/source_file.dart' show Binary; |
| 33 import 'kernel/element_map_impl.dart' show KernelToElementMapImpl; | 34 import 'kernel/element_map_impl.dart' show KernelToElementMapImpl; |
| 34 import 'patch_parser.dart' show PatchParserTask; | 35 import 'patch_parser.dart' show PatchParserTask; |
| 35 import 'resolved_uri_translator.dart'; | 36 import 'resolved_uri_translator.dart'; |
| 36 import 'script.dart'; | 37 import 'script.dart'; |
| 37 import 'serialization/serialization.dart' show LibraryDeserializer; | 38 import 'serialization/serialization.dart' show LibraryDeserializer; |
| 38 import 'tree/tree.dart'; | 39 import 'tree/tree.dart'; |
| 39 import 'util/util.dart' show Link, LinkBuilder; | 40 import 'util/util.dart' show Link, LinkBuilder; |
| 40 | 41 |
| 41 import 'package:kernel/ast.dart' as ir; | 42 import 'package:kernel/ast.dart' as ir; |
| 42 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; | 43 import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; |
| (...skipping 789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 /// Loads an entire Kernel [Program] from a file on disk (note, not just a | 833 /// Loads an entire Kernel [Program] from a file on disk (note, not just a |
| 833 /// library, so this name is actually a bit of a misnomer). | 834 /// library, so this name is actually a bit of a misnomer). |
| 834 // TODO(efortuna): Rename this once the Element library loader class goes | 835 // TODO(efortuna): Rename this once the Element library loader class goes |
| 835 // away. | 836 // away. |
| 836 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, | 837 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, |
| 837 {bool skipFileWithPartOfTag: false}) { | 838 {bool skipFileWithPartOfTag: false}) { |
| 838 assert(resolvedUri.pathSegments.last.endsWith('.dill'), | 839 assert(resolvedUri.pathSegments.last.endsWith('.dill'), |
| 839 'Invalid uri: $resolvedUri'); | 840 'Invalid uri: $resolvedUri'); |
| 840 Uri readableUri = uriTranslator.translate(null, resolvedUri, null); | 841 Uri readableUri = uriTranslator.translate(null, resolvedUri, null); |
| 841 return measure(() async { | 842 return measure(() async { |
| 842 Script script = await scriptLoader.readScript(readableUri, null); | 843 Binary binary = await scriptLoader.readBinary(readableUri, null); |
| 843 ir.Program program = new ir.Program(); | 844 ir.Program program = new ir.Program(); |
| 844 // Hack because the existing file has a terminating 0 and the | 845 new BinaryBuilder(binary.data).readProgram(program); |
| 845 // BinaryBuilder doesn't expect that. | |
| 846 var bytes = new List<int>.from(script.file.slowUtf8ZeroTerminatedBytes()); | |
| 847 bytes.removeLast(); | |
| 848 new BinaryBuilder(bytes).readProgram(program); | |
| 849 return measure(() { | 846 return measure(() { |
| 850 return createLoadedLibraries(program); | 847 return createLoadedLibraries(program); |
| 851 }); | 848 }); |
| 852 }); | 849 }); |
| 853 } | 850 } |
| 854 | 851 |
| 855 LoadedLibraries createLoadedLibraries(ir.Program program) { | 852 LoadedLibraries createLoadedLibraries(ir.Program program) { |
| 856 _elementMap.addProgram(program); | 853 _elementMap.addProgram(program); |
| 857 program.libraries.forEach((ir.Library library) => | 854 program.libraries.forEach((ir.Library library) => |
| 858 _allLoadedLibraries.add(_elementMap.lookupLibrary(library.importUri))); | 855 _allLoadedLibraries.add(_elementMap.lookupLibrary(library.importUri))); |
| (...skipping 791 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 // | 1647 // |
| 1651 // Each subloader would internally create what they need (a scanner, a | 1648 // Each subloader would internally create what they need (a scanner, a |
| 1652 // deserializer), and we wouldn't need to create abstractions to pass in | 1649 // deserializer), and we wouldn't need to create abstractions to pass in |
| 1653 // something that is only used by the loader. | 1650 // something that is only used by the loader. |
| 1654 | 1651 |
| 1655 /// API used by the library loader to request scripts from the compiler system. | 1652 /// API used by the library loader to request scripts from the compiler system. |
| 1656 abstract class ScriptLoader { | 1653 abstract class ScriptLoader { |
| 1657 /// Load script from a readable [uri], report any errors using the location of | 1654 /// Load script from a readable [uri], report any errors using the location of |
| 1658 /// the given [spannable]. | 1655 /// the given [spannable]. |
| 1659 Future<Script> readScript(Uri uri, [Spannable spannable]); | 1656 Future<Script> readScript(Uri uri, [Spannable spannable]); |
| 1657 |
| 1658 /// Load a binary from a readable [uri], report any errors using the location |
| 1659 /// of the given [spannable]. |
| 1660 Future<Binary> readBinary(Uri uri, [Spannable spannable]); |
| 1660 } | 1661 } |
| 1661 | 1662 |
| 1662 /// API used by the library loader to synchronously scan a library or | 1663 /// API used by the library loader to synchronously scan a library or |
| 1663 /// compilation unit and ensure that their library tags are computed. | 1664 /// compilation unit and ensure that their library tags are computed. |
| 1664 abstract class ElementScanner { | 1665 abstract class ElementScanner { |
| 1665 void scanLibrary(LibraryElement library); | 1666 void scanLibrary(LibraryElement library); |
| 1666 void scanUnit(CompilationUnitElement unit); | 1667 void scanUnit(CompilationUnitElement unit); |
| 1667 } | 1668 } |
| 1668 | 1669 |
| 1669 const _reuseLibrarySubtaskName = "Reuse library"; | 1670 const _reuseLibrarySubtaskName = "Reuse library"; |
| OLD | NEW |