| 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 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 Uri readableUri = uriTranslator.translate(null, resolvedUri, null); | 839 Uri readableUri = uriTranslator.translate(null, resolvedUri, null); |
| 840 return measure(() async { | 840 return measure(() async { |
| 841 Script script = await scriptLoader.readScript(readableUri, null); | 841 Script script = await scriptLoader.readScript(readableUri, null); |
| 842 ir.Program program = new ir.Program(); | 842 ir.Program program = new ir.Program(); |
| 843 // Hack because the existing file has a terminating 0 and the | 843 // Hack because the existing file has a terminating 0 and the |
| 844 // BinaryBuilder doesn't expect that. | 844 // BinaryBuilder doesn't expect that. |
| 845 var bytes = new List<int>.from(script.file.slowUtf8ZeroTerminatedBytes()); | 845 var bytes = new List<int>.from(script.file.slowUtf8ZeroTerminatedBytes()); |
| 846 bytes.removeLast(); | 846 bytes.removeLast(); |
| 847 new BinaryBuilder(bytes).readProgram(program); | 847 new BinaryBuilder(bytes).readProgram(program); |
| 848 return measure(() { | 848 return measure(() { |
| 849 _elementMap.addProgram(program); | 849 return createLoadedLibraries(program); |
| 850 program.libraries.forEach((ir.Library library) => _allLoadedLibraries | |
| 851 .add(_elementMap.lookupLibrary(library.importUri))); | |
| 852 LibraryEntity rootLibrary = null; | |
| 853 if (program.mainMethod != null) { | |
| 854 rootLibrary = _elementMap | |
| 855 .lookupLibrary(program.mainMethod.enclosingLibrary.importUri); | |
| 856 } | |
| 857 return new _LoadedLibrariesAdapter( | |
| 858 rootLibrary, _allLoadedLibraries, _elementMap); | |
| 859 }); | 850 }); |
| 860 }); | 851 }); |
| 861 } | 852 } |
| 862 | 853 |
| 854 LoadedLibraries createLoadedLibraries(ir.Program program) { |
| 855 _elementMap.addProgram(program); |
| 856 program.libraries.forEach((ir.Library library) => |
| 857 _allLoadedLibraries.add(_elementMap.lookupLibrary(library.importUri))); |
| 858 LibraryEntity rootLibrary = null; |
| 859 if (program.mainMethod != null) { |
| 860 rootLibrary = _elementMap |
| 861 .lookupLibrary(program.mainMethod.enclosingLibrary.importUri); |
| 862 } |
| 863 return new _LoadedLibrariesAdapter( |
| 864 rootLibrary, _allLoadedLibraries, _elementMap); |
| 865 } |
| 866 |
| 863 KernelToElementMap get elementMap => _elementMap; | 867 KernelToElementMap get elementMap => _elementMap; |
| 864 | 868 |
| 865 void reset({bool reuseLibrary(LibraryElement library)}) { | 869 void reset({bool reuseLibrary(LibraryElement library)}) { |
| 866 throw new UnimplementedError('DillLibraryLoaderTask.reset'); | 870 throw new UnimplementedError('DillLibraryLoaderTask.reset'); |
| 867 } | 871 } |
| 868 | 872 |
| 869 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)) { | 873 Future resetAsync(Future<bool> reuseLibrary(LibraryElement library)) { |
| 870 throw new UnimplementedError('DillLibraryLoaderTask.resetAsync'); | 874 throw new UnimplementedError('DillLibraryLoaderTask.resetAsync'); |
| 871 } | 875 } |
| 872 | 876 |
| 873 Iterable<LibraryEntity> get libraries => _allLoadedLibraries; | 877 Iterable<LibraryEntity> get libraries => _allLoadedLibraries; |
| 874 | 878 |
| 875 LibraryEntity lookupLibrary(Uri canonicalUri) { | 879 LibraryEntity lookupLibrary(Uri canonicalUri) { |
| 876 return _elementMap?.lookupLibrary(canonicalUri); | 880 return _elementMap?.lookupLibrary(canonicalUri); |
| 877 } | 881 } |
| 878 | 882 |
| 879 Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries) { | 883 Future<Null> resetLibraries(ReuseLibrariesFunction reuseLibraries) { |
| 880 throw new UnimplementedError('DillLibraryLoaderTask.reuseLibraries'); | 884 throw new UnimplementedError('DillLibraryLoaderTask.reuseLibraries'); |
| 881 } | 885 } |
| 882 | 886 |
| 883 void registerDeferredAction(DeferredAction action) { | 887 void registerDeferredAction(DeferredAction action) { |
| 884 throw new UnimplementedError( | 888 throw new UnimplementedError( |
| 885 'DillLibraryLoaderTask.registerDeferredAction'); | 889 'DillLibraryLoaderTask.registerDeferredAction'); |
| 886 } | 890 } |
| 887 | 891 |
| 888 Iterable<DeferredAction> pullDeferredActions() { | 892 Iterable<DeferredAction> pullDeferredActions() => const <DeferredAction>[]; |
| 889 throw new UnimplementedError('DillLibraryLoaderTask.pullDeferredActions'); | |
| 890 } | |
| 891 } | 893 } |
| 892 | 894 |
| 893 /// A state machine for checking script tags come in the correct order. | 895 /// A state machine for checking script tags come in the correct order. |
| 894 class TagState { | 896 class TagState { |
| 895 /// Initial state. | 897 /// Initial state. |
| 896 static const int NO_TAG_SEEN = 0; | 898 static const int NO_TAG_SEEN = 0; |
| 897 | 899 |
| 898 /// Passed to [checkTag] when a library declaration (the syntax "library | 900 /// Passed to [checkTag] when a library declaration (the syntax "library |
| 899 /// name;") has been seen. Not an actual state. | 901 /// name;") has been seen. Not an actual state. |
| 900 static const int LIBRARY = 1; | 902 static const int LIBRARY = 1; |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 } | 1659 } |
| 1658 | 1660 |
| 1659 /// API used by the library loader to synchronously scan a library or | 1661 /// API used by the library loader to synchronously scan a library or |
| 1660 /// compilation unit and ensure that their library tags are computed. | 1662 /// compilation unit and ensure that their library tags are computed. |
| 1661 abstract class ElementScanner { | 1663 abstract class ElementScanner { |
| 1662 void scanLibrary(LibraryElement library); | 1664 void scanLibrary(LibraryElement library); |
| 1663 void scanUnit(CompilationUnitElement unit); | 1665 void scanUnit(CompilationUnitElement unit); |
| 1664 } | 1666 } |
| 1665 | 1667 |
| 1666 const _reuseLibrarySubtaskName = "Reuse library"; | 1668 const _reuseLibrarySubtaskName = "Reuse library"; |
| OLD | NEW |