OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 deferred_load; | 5 library deferred_load; |
6 | 6 |
7 import 'common/backend_api.dart' show | 7 import 'common/backend_api.dart' show |
8 Backend; | 8 Backend; |
9 import 'common/tasks.dart' show | 9 import 'common/tasks.dart' show |
10 CompilerTask; | 10 CompilerTask; |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 for (ImportElement import in library.imports) { | 722 for (ImportElement import in library.imports) { |
723 /// Give an error if the old annotation-based syntax has been used. | 723 /// Give an error if the old annotation-based syntax has been used. |
724 List<MetadataAnnotation> metadataList = import.metadata; | 724 List<MetadataAnnotation> metadataList = import.metadata; |
725 if (metadataList != null) { | 725 if (metadataList != null) { |
726 for (MetadataAnnotation metadata in metadataList) { | 726 for (MetadataAnnotation metadata in metadataList) { |
727 metadata.ensureResolved(compiler); | 727 metadata.ensureResolved(compiler); |
728 ConstantValue value = | 728 ConstantValue value = |
729 compiler.constants.getConstantValue(metadata.constant); | 729 compiler.constants.getConstantValue(metadata.constant); |
730 Element element = value.getType(compiler.coreTypes).element; | 730 Element element = value.getType(compiler.coreTypes).element; |
731 if (element == deferredLibraryClass) { | 731 if (element == deferredLibraryClass) { |
732 compiler.reportError( | 732 compiler.reportErrorMessage( |
733 import, MessageKind.DEFERRED_OLD_SYNTAX); | 733 import, MessageKind.DEFERRED_OLD_SYNTAX); |
734 } | 734 } |
735 } | 735 } |
736 } | 736 } |
737 | 737 |
738 String prefix = (import.prefix != null) | 738 String prefix = (import.prefix != null) |
739 ? import.prefix.name | 739 ? import.prefix.name |
740 : null; | 740 : null; |
741 // The last import we saw with the same prefix. | 741 // The last import we saw with the same prefix. |
742 ImportElement previousDeferredImport = prefixDeferredImport[prefix]; | 742 ImportElement previousDeferredImport = prefixDeferredImport[prefix]; |
743 if (import.isDeferred) { | 743 if (import.isDeferred) { |
744 _DeferredImport key = new _DeclaredDeferredImport(import); | 744 _DeferredImport key = new _DeclaredDeferredImport(import); |
745 LibraryElement importedLibrary = import.importedLibrary; | 745 LibraryElement importedLibrary = import.importedLibrary; |
746 _allDeferredImports[key] = importedLibrary; | 746 _allDeferredImports[key] = importedLibrary; |
747 | 747 |
748 if (prefix == null) { | 748 if (prefix == null) { |
749 compiler.reportError(import, | 749 compiler.reportErrorMessage( |
| 750 import, |
750 MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX); | 751 MessageKind.DEFERRED_LIBRARY_WITHOUT_PREFIX); |
751 } else { | 752 } else { |
752 prefixDeferredImport[prefix] = import; | 753 prefixDeferredImport[prefix] = import; |
753 _deferredImportDescriptions[key] = | 754 _deferredImportDescriptions[key] = |
754 new ImportDescription(import, library, compiler); | 755 new ImportDescription(import, library, compiler); |
755 } | 756 } |
756 isProgramSplit = true; | 757 isProgramSplit = true; |
757 lastDeferred = import; | 758 lastDeferred = import; |
758 } | 759 } |
759 if (prefix != null) { | 760 if (prefix != null) { |
760 if (previousDeferredImport != null || | 761 if (previousDeferredImport != null || |
761 (import.isDeferred && usedPrefixes.contains(prefix))) { | 762 (import.isDeferred && usedPrefixes.contains(prefix))) { |
762 ImportElement failingImport = (previousDeferredImport != null) | 763 ImportElement failingImport = (previousDeferredImport != null) |
763 ? previousDeferredImport | 764 ? previousDeferredImport |
764 : import; | 765 : import; |
765 compiler.reportError(failingImport.prefix, | 766 compiler.reportErrorMessage( |
| 767 failingImport.prefix, |
766 MessageKind.DEFERRED_LIBRARY_DUPLICATE_PREFIX); | 768 MessageKind.DEFERRED_LIBRARY_DUPLICATE_PREFIX); |
767 } | 769 } |
768 usedPrefixes.add(prefix); | 770 usedPrefixes.add(prefix); |
769 } | 771 } |
770 } | 772 } |
771 }); | 773 }); |
772 } | 774 } |
773 if (isProgramSplit) { | 775 if (isProgramSplit) { |
774 isProgramSplit = compiler.backend.enableDeferredLoadingIfSupported( | 776 isProgramSplit = compiler.backend.enableDeferredLoadingIfSupported( |
775 lastDeferred, compiler.globalDependencies); | 777 lastDeferred, compiler.globalDependencies); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 return result; | 938 return result; |
937 } | 939 } |
938 | 940 |
939 bool operator ==(other) { | 941 bool operator ==(other) { |
940 if (other is! _DeclaredDeferredImport) return false; | 942 if (other is! _DeclaredDeferredImport) return false; |
941 return declaration == other.declaration; | 943 return declaration == other.declaration; |
942 } | 944 } |
943 | 945 |
944 int get hashCode => declaration.hashCode * 17; | 946 int get hashCode => declaration.hashCode * 17; |
945 } | 947 } |
OLD | NEW |