| 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.compiler_base; | 5 library dart2js.compiler_base; |
| 6 | 6 |
| 7 import 'dart:async' show | 7 import 'dart:async' show |
| 8 EventSink, | 8 EventSink, |
| 9 Future; | 9 Future; |
| 10 | 10 |
| 11 import '../compiler_new.dart' as api; | 11 import '../compiler_new.dart' as api; |
| 12 import 'cache_strategy.dart' show | 12 import 'cache_strategy.dart' show |
| 13 CacheStrategy; | 13 CacheStrategy; |
| 14 import 'closure.dart' as closureMapping show | 14 import 'closure.dart' as closureMapping show |
| 15 ClosureTask; | 15 ClosureTask; |
| 16 import 'common/backend_api.dart' show | 16 import 'common/backend_api.dart' show |
| 17 Backend; | 17 Backend; |
| 18 import 'common/codegen.dart' show | 18 import 'common/codegen.dart' show |
| 19 CodegenRegistry, | 19 CodegenRegistry, |
| 20 CodegenWorkItem; | 20 CodegenWorkItem; |
| 21 import 'common/names.dart' show | 21 import 'common/names.dart' show |
| 22 Identifiers; | 22 Identifiers, |
| 23 Uris; |
| 23 import 'common/registry.dart' show | 24 import 'common/registry.dart' show |
| 24 Registry; | 25 Registry; |
| 25 import 'common/resolution.dart' show | 26 import 'common/resolution.dart' show |
| 26 ResolutionWorkItem; | 27 ResolutionWorkItem; |
| 27 import 'common/tasks.dart' show | 28 import 'common/tasks.dart' show |
| 28 CompilerTask, | 29 CompilerTask, |
| 29 GenericTask; | 30 GenericTask; |
| 30 import 'common/work.dart' show | 31 import 'common/work.dart' show |
| 31 WorkItem; | 32 WorkItem; |
| 32 import 'compile_time_constants.dart'; | 33 import 'compile_time_constants.dart'; |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 CallStructure, | 127 CallStructure, |
| 127 Selector, | 128 Selector, |
| 128 Universe; | 129 Universe; |
| 129 import 'util/characters.dart' show $_; | 130 import 'util/characters.dart' show $_; |
| 130 import 'util/util.dart' show | 131 import 'util/util.dart' show |
| 131 Link; | 132 Link; |
| 132 import 'world.dart' show | 133 import 'world.dart' show |
| 133 World; | 134 World; |
| 134 | 135 |
| 135 abstract class Compiler implements DiagnosticListener { | 136 abstract class Compiler implements DiagnosticListener { |
| 136 static final Uri DART_CORE = new Uri(scheme: 'dart', path: 'core'); | |
| 137 static final Uri DART_MIRRORS = new Uri(scheme: 'dart', path: 'mirrors'); | |
| 138 static final Uri DART_NATIVE_TYPED_DATA = | |
| 139 new Uri(scheme: 'dart', path: '_native_typed_data'); | |
| 140 static final Uri DART_INTERNAL = new Uri(scheme: 'dart', path: '_internal'); | |
| 141 static final Uri DART_ASYNC = new Uri(scheme: 'dart', path: 'async'); | |
| 142 | 137 |
| 143 final Stopwatch totalCompileTime = new Stopwatch(); | 138 final Stopwatch totalCompileTime = new Stopwatch(); |
| 144 int nextFreeClassId = 0; | 139 int nextFreeClassId = 0; |
| 145 World world; | 140 World world; |
| 146 Types types; | 141 Types types; |
| 147 _CompilerCoreTypes _coreTypes; | 142 _CompilerCoreTypes _coreTypes; |
| 148 | 143 |
| 149 final CacheStrategy cacheStrategy; | 144 final CacheStrategy cacheStrategy; |
| 150 | 145 |
| 151 /** | 146 /** |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 } | 716 } |
| 722 | 717 |
| 723 /// This method is called immediately after the [LibraryElement] [library] has | 718 /// This method is called immediately after the [LibraryElement] [library] has |
| 724 /// been created. | 719 /// been created. |
| 725 /// | 720 /// |
| 726 /// Use this callback method to store references to specific libraries. | 721 /// Use this callback method to store references to specific libraries. |
| 727 /// Note that [library] has not been scanned yet, nor has its imports/exports | 722 /// Note that [library] has not been scanned yet, nor has its imports/exports |
| 728 /// been resolved. | 723 /// been resolved. |
| 729 void onLibraryCreated(LibraryElement library) { | 724 void onLibraryCreated(LibraryElement library) { |
| 730 Uri uri = library.canonicalUri; | 725 Uri uri = library.canonicalUri; |
| 731 if (uri == DART_CORE) { | 726 if (uri == Uris.dart_core) { |
| 732 coreLibrary = library; | 727 coreLibrary = library; |
| 733 } else if (uri == DART_NATIVE_TYPED_DATA) { | 728 } else if (uri == Uris.dart__native_typed_data) { |
| 734 typedDataLibrary = library; | 729 typedDataLibrary = library; |
| 735 } else if (uri == DART_MIRRORS) { | 730 } else if (uri == Uris.dart_mirrors) { |
| 736 mirrorsLibrary = library; | 731 mirrorsLibrary = library; |
| 737 } | 732 } |
| 738 backend.onLibraryCreated(library); | 733 backend.onLibraryCreated(library); |
| 739 } | 734 } |
| 740 | 735 |
| 741 /// This method is called immediately after the [library] and its parts have | 736 /// This method is called immediately after the [library] and its parts have |
| 742 /// been scanned. | 737 /// been scanned. |
| 743 /// | 738 /// |
| 744 /// Use this callback method to store references to specific member declared | 739 /// Use this callback method to store references to specific member declared |
| 745 /// in certain libraries. Note that [library] has not been patched yet, nor | 740 /// in certain libraries. Note that [library] has not been patched yet, nor |
| 746 /// has its imports/exports been resolved. | 741 /// has its imports/exports been resolved. |
| 747 /// | 742 /// |
| 748 /// Use [loader] to register the creation and scanning of a patch library | 743 /// Use [loader] to register the creation and scanning of a patch library |
| 749 /// for [library]. | 744 /// for [library]. |
| 750 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { | 745 Future onLibraryScanned(LibraryElement library, LibraryLoader loader) { |
| 751 Uri uri = library.canonicalUri; | 746 Uri uri = library.canonicalUri; |
| 752 if (uri == DART_CORE) { | 747 if (uri == Uris.dart_core) { |
| 753 initializeCoreClasses(); | 748 initializeCoreClasses(); |
| 754 identicalFunction = coreLibrary.find('identical'); | 749 identicalFunction = coreLibrary.find('identical'); |
| 755 } else if (uri == DART_INTERNAL) { | 750 } else if (uri == Uris.dart__internal) { |
| 756 symbolImplementationClass = findRequiredElement(library, 'Symbol'); | 751 symbolImplementationClass = findRequiredElement(library, 'Symbol'); |
| 757 } else if (uri == DART_MIRRORS) { | 752 } else if (uri == Uris.dart_mirrors) { |
| 758 mirrorSystemClass = findRequiredElement(library, 'MirrorSystem'); | 753 mirrorSystemClass = findRequiredElement(library, 'MirrorSystem'); |
| 759 mirrorsUsedClass = findRequiredElement(library, 'MirrorsUsed'); | 754 mirrorsUsedClass = findRequiredElement(library, 'MirrorsUsed'); |
| 760 } else if (uri == DART_ASYNC) { | 755 } else if (uri == Uris.dart_async) { |
| 761 asyncLibrary = library; | 756 asyncLibrary = library; |
| 762 deferredLibraryClass = findRequiredElement(library, 'DeferredLibrary'); | 757 deferredLibraryClass = findRequiredElement(library, 'DeferredLibrary'); |
| 763 _coreTypes.futureClass = findRequiredElement(library, 'Future'); | 758 _coreTypes.futureClass = findRequiredElement(library, 'Future'); |
| 764 _coreTypes.streamClass = findRequiredElement(library, 'Stream'); | 759 _coreTypes.streamClass = findRequiredElement(library, 'Stream'); |
| 765 } else if (uri == DART_NATIVE_TYPED_DATA) { | 760 } else if (uri == Uris.dart__native_typed_data) { |
| 766 typedDataClass = findRequiredElement(library, 'NativeTypedData'); | 761 typedDataClass = findRequiredElement(library, 'NativeTypedData'); |
| 767 } else if (uri == js_backend.JavaScriptBackend.DART_JS_HELPER) { | 762 } else if (uri == js_backend.JavaScriptBackend.DART_JS_HELPER) { |
| 768 patchAnnotationClass = findRequiredElement(library, '_Patch'); | 763 patchAnnotationClass = findRequiredElement(library, '_Patch'); |
| 769 nativeAnnotationClass = findRequiredElement(library, 'Native'); | 764 nativeAnnotationClass = findRequiredElement(library, 'Native'); |
| 770 } | 765 } |
| 771 return backend.onLibraryScanned(library, loader); | 766 return backend.onLibraryScanned(library, loader); |
| 772 } | 767 } |
| 773 | 768 |
| 774 /// This method is called when all new libraries loaded through | 769 /// This method is called when all new libraries loaded through |
| 775 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports | 770 /// [LibraryLoader.loadLibrary] has been loaded and their imports/exports |
| 776 /// have been computed. | 771 /// have been computed. |
| 777 /// | 772 /// |
| 778 /// [loadedLibraries] contains the newly loaded libraries. | 773 /// [loadedLibraries] contains the newly loaded libraries. |
| 779 /// | 774 /// |
| 780 /// The method returns a [Future] allowing for the loading of additional | 775 /// The method returns a [Future] allowing for the loading of additional |
| 781 /// libraries. | 776 /// libraries. |
| 782 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { | 777 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
| 783 return new Future.sync(() { | 778 return new Future.sync(() { |
| 784 if (!loadedLibraries.containsLibrary(DART_CORE)) { | 779 if (!loadedLibraries.containsLibrary(Uris.dart_core)) { |
| 785 return null; | 780 return null; |
| 786 } | 781 } |
| 787 if (!enableExperimentalMirrors && | 782 if (!enableExperimentalMirrors && |
| 788 loadedLibraries.containsLibrary(DART_MIRRORS)) { | 783 loadedLibraries.containsLibrary(Uris.dart_mirrors)) { |
| 789 // TODO(johnniwinther): Move computation of dependencies to the library | 784 // TODO(johnniwinther): Move computation of dependencies to the library |
| 790 // loader. | 785 // loader. |
| 791 Uri rootUri = loadedLibraries.rootUri; | 786 Uri rootUri = loadedLibraries.rootUri; |
| 792 Set<String> importChains = new Set<String>(); | 787 Set<String> importChains = new Set<String>(); |
| 793 // The maximum number of full imports chains to process. | 788 // The maximum number of full imports chains to process. |
| 794 final int chainLimit = 10000; | 789 final int chainLimit = 10000; |
| 795 // The maximum number of imports chains to show. | 790 // The maximum number of imports chains to show. |
| 796 final int compactChainLimit = verbose ? 20 : 10; | 791 final int compactChainLimit = verbose ? 20 : 10; |
| 797 int chainCount = 0; | 792 int chainCount = 0; |
| 798 loadedLibraries.forEachImportChain(DART_MIRRORS, | 793 loadedLibraries.forEachImportChain(Uris.dart_mirrors, |
| 799 callback: (Link<Uri> importChainReversed) { | 794 callback: (Link<Uri> importChainReversed) { |
| 800 Link<CodeLocation> compactImportChain = const Link<CodeLocation>(); | 795 Link<CodeLocation> compactImportChain = const Link<CodeLocation>(); |
| 801 CodeLocation currentCodeLocation = | 796 CodeLocation currentCodeLocation = |
| 802 new UriLocation(importChainReversed.head); | 797 new UriLocation(importChainReversed.head); |
| 803 compactImportChain = compactImportChain.prepend(currentCodeLocation); | 798 compactImportChain = compactImportChain.prepend(currentCodeLocation); |
| 804 for (Link<Uri> link = importChainReversed.tail; | 799 for (Link<Uri> link = importChainReversed.tail; |
| 805 !link.isEmpty; | 800 !link.isEmpty; |
| 806 link = link.tail) { | 801 link = link.tail) { |
| 807 Uri uri = link.head; | 802 Uri uri = link.head; |
| 808 if (!currentCodeLocation.inSameLocation(uri)) { | 803 if (!currentCodeLocation.inSameLocation(uri)) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 848 | 843 |
| 849 functionClass.ensureResolved(this); | 844 functionClass.ensureResolved(this); |
| 850 functionApplyMethod = functionClass.lookupLocalMember('apply'); | 845 functionApplyMethod = functionClass.lookupLocalMember('apply'); |
| 851 | 846 |
| 852 proxyConstant = | 847 proxyConstant = |
| 853 constants.getConstantValue( | 848 constants.getConstantValue( |
| 854 resolver.constantCompiler.compileConstant( | 849 resolver.constantCompiler.compileConstant( |
| 855 coreLibrary.find('proxy'))); | 850 coreLibrary.find('proxy'))); |
| 856 | 851 |
| 857 if (preserveComments) { | 852 if (preserveComments) { |
| 858 return libraryLoader.loadLibrary(DART_MIRRORS) | 853 return libraryLoader.loadLibrary(Uris.dart_mirrors) |
| 859 .then((LibraryElement libraryElement) { | 854 .then((LibraryElement libraryElement) { |
| 860 documentClass = libraryElement.find('Comment'); | 855 documentClass = libraryElement.find('Comment'); |
| 861 }); | 856 }); |
| 862 } | 857 } |
| 863 }).then((_) => backend.onLibrariesLoaded(loadedLibraries)); | 858 }).then((_) => backend.onLibrariesLoaded(loadedLibraries)); |
| 864 } | 859 } |
| 865 | 860 |
| 866 Element findRequiredElement(LibraryElement library, String name) { | 861 Element findRequiredElement(LibraryElement library, String name) { |
| 867 var element = library.find(name); | 862 var element = library.find(name); |
| 868 if (element == null) { | 863 if (element == null) { |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 | 1755 |
| 1761 @override | 1756 @override |
| 1762 InterfaceType streamType([DartType elementType]) { | 1757 InterfaceType streamType([DartType elementType]) { |
| 1763 InterfaceType type = streamClass.computeType(compiler); | 1758 InterfaceType type = streamClass.computeType(compiler); |
| 1764 if (elementType == null) { | 1759 if (elementType == null) { |
| 1765 return streamClass.rawType; | 1760 return streamClass.rawType; |
| 1766 } | 1761 } |
| 1767 return type.createInstantiation([elementType]); | 1762 return type.createInstantiation([elementType]); |
| 1768 } | 1763 } |
| 1769 } | 1764 } |
| OLD | NEW |