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/tasks.dart' show CompilerTask; | 7 import 'common/tasks.dart' show CompilerTask; |
8 import 'common.dart'; | 8 import 'common.dart'; |
9 import 'compiler.dart' show Compiler; | 9 import 'compiler.dart' show Compiler; |
10 import 'constants/expressions.dart' show ConstantExpression; | 10 import 'constants/expressions.dart' show ConstantExpression; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 /// For each deferred import, find elements and constants to be loaded when that | 87 /// For each deferred import, find elements and constants to be loaded when that |
88 /// import is loaded. Elements that are used by several deferred imports are in | 88 /// import is loaded. Elements that are used by several deferred imports are in |
89 /// shared OutputUnits. | 89 /// shared OutputUnits. |
90 class DeferredLoadTask extends CompilerTask { | 90 class DeferredLoadTask extends CompilerTask { |
91 /// The name of this task. | 91 /// The name of this task. |
92 String get name => 'Deferred Loading'; | 92 String get name => 'Deferred Loading'; |
93 | 93 |
94 /// DeferredLibrary from dart:async | 94 /// DeferredLibrary from dart:async |
95 ClassElement get deferredLibraryClass => | 95 ClassElement get deferredLibraryClass => |
96 compiler.commonElements.deferredLibraryClass; | 96 compiler.resolution.commonElements.deferredLibraryClass; |
97 | 97 |
98 /// A synthetic import representing the loading of the main program. | 98 /// A synthetic import representing the loading of the main program. |
99 final _DeferredImport _fakeMainImport = const _DeferredImport(); | 99 final _DeferredImport _fakeMainImport = const _DeferredImport(); |
100 | 100 |
101 /// The OutputUnit that will be loaded when the program starts. | 101 /// The OutputUnit that will be loaded when the program starts. |
102 final OutputUnit mainOutputUnit = new OutputUnit(isMainOutput: true); | 102 final OutputUnit mainOutputUnit = new OutputUnit(isMainOutput: true); |
103 | 103 |
104 /// A set containing (eventually) all output units that will result from the | 104 /// A set containing (eventually) all output units that will result from the |
105 /// program. | 105 /// program. |
106 final Set<OutputUnit> allOutputUnits = new Set<OutputUnit>(); | 106 final Set<OutputUnit> allOutputUnits = new Set<OutputUnit>(); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 } | 498 } |
499 } | 499 } |
500 | 500 |
501 iterateTags(library); | 501 iterateTags(library); |
502 if (library.isPatched) { | 502 if (library.isPatched) { |
503 iterateTags(library.implementation); | 503 iterateTags(library.implementation); |
504 } | 504 } |
505 } | 505 } |
506 | 506 |
507 traverseLibrary(root); | 507 traverseLibrary(root); |
508 result.add(compiler.commonElements.coreLibrary); | 508 result.add(compiler.resolution.commonElements.coreLibrary); |
509 return result; | 509 return result; |
510 } | 510 } |
511 | 511 |
512 /// Add all dependencies of [constant] to the mapping of [import]. | 512 /// Add all dependencies of [constant] to the mapping of [import]. |
513 void _mapConstantDependencies( | 513 void _mapConstantDependencies( |
514 ConstantValue constant, _DeferredImport import) { | 514 ConstantValue constant, _DeferredImport import) { |
515 Set<ConstantValue> constants = _constantsDeferredBy.putIfAbsent( | 515 Set<ConstantValue> constants = _constantsDeferredBy.putIfAbsent( |
516 import, () => new Set<ConstantValue>()); | 516 import, () => new Set<ConstantValue>()); |
517 if (constants.contains(constant)) return; | 517 if (constants.contains(constant)) return; |
518 constants.add(constant); | 518 constants.add(constant); |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 element: element.implementation, import: _fakeMainImport); | 711 element: element.implementation, import: _fakeMainImport); |
712 } | 712 } |
713 for (ClassElement element | 713 for (ClassElement element |
714 in closedWorld.backendUsage.globalClassDependencies) { | 714 in closedWorld.backendUsage.globalClassDependencies) { |
715 _mapDependencies( | 715 _mapDependencies( |
716 element: element.implementation, import: _fakeMainImport); | 716 element: element.implementation, import: _fakeMainImport); |
717 } | 717 } |
718 | 718 |
719 // Now check to see if we have to add more elements due to | 719 // Now check to see if we have to add more elements due to |
720 // mirrors. | 720 // mirrors. |
721 if (compiler.commonElements.mirrorsLibrary != null) { | 721 if (compiler.resolution.commonElements.mirrorsLibrary != null) { |
722 _addMirrorElements(); | 722 _addMirrorElements(); |
723 } | 723 } |
724 | 724 |
725 // Build the OutputUnits using these two maps. | 725 // Build the OutputUnits using these two maps. |
726 Map<Element, OutputUnit> elementToOutputUnitBuilder = | 726 Map<Element, OutputUnit> elementToOutputUnitBuilder = |
727 new Map<Element, OutputUnit>(); | 727 new Map<Element, OutputUnit>(); |
728 Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder = | 728 Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder = |
729 new Map<ConstantValue, OutputUnit>(); | 729 new Map<ConstantValue, OutputUnit>(); |
730 | 730 |
731 // Add all constants that may have been registered during | 731 // Add all constants that may have been registered during |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
824 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List | 824 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List |
825 // instead of a Link. | 825 // instead of a Link. |
826 for (ImportElement import in library.imports) { | 826 for (ImportElement import in library.imports) { |
827 /// Give an error if the old annotation-based syntax has been used. | 827 /// Give an error if the old annotation-based syntax has been used. |
828 List<MetadataAnnotation> metadataList = import.metadata; | 828 List<MetadataAnnotation> metadataList = import.metadata; |
829 if (metadataList != null) { | 829 if (metadataList != null) { |
830 for (MetadataAnnotation metadata in metadataList) { | 830 for (MetadataAnnotation metadata in metadataList) { |
831 metadata.ensureResolved(compiler.resolution); | 831 metadata.ensureResolved(compiler.resolution); |
832 ConstantValue value = | 832 ConstantValue value = |
833 compiler.constants.getConstantValue(metadata.constant); | 833 compiler.constants.getConstantValue(metadata.constant); |
834 ResolutionDartType type = value.getType(compiler.commonElements); | 834 ResolutionDartType type = |
| 835 value.getType(compiler.resolution.commonElements); |
835 Element element = type.element; | 836 Element element = type.element; |
836 if (element == deferredLibraryClass) { | 837 if (element == deferredLibraryClass) { |
837 reporter.reportErrorMessage( | 838 reporter.reportErrorMessage( |
838 import, MessageKind.DEFERRED_OLD_SYNTAX); | 839 import, MessageKind.DEFERRED_OLD_SYNTAX); |
839 } | 840 } |
840 } | 841 } |
841 } | 842 } |
842 | 843 |
843 String prefix = (import.prefix != null) ? import.prefix.name : null; | 844 String prefix = (import.prefix != null) ? import.prefix.name : null; |
844 // The last import we saw with the same prefix. | 845 // The last import we saw with the same prefix. |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 result = ''; | 1075 result = ''; |
1075 } | 1076 } |
1076 } else { | 1077 } else { |
1077 // Finds the first argument to the [DeferredLibrary] annotation | 1078 // Finds the first argument to the [DeferredLibrary] annotation |
1078 List<MetadataAnnotation> metadatas = declaration.metadata; | 1079 List<MetadataAnnotation> metadatas = declaration.metadata; |
1079 assert(metadatas != null); | 1080 assert(metadatas != null); |
1080 for (MetadataAnnotation metadata in metadatas) { | 1081 for (MetadataAnnotation metadata in metadatas) { |
1081 metadata.ensureResolved(compiler.resolution); | 1082 metadata.ensureResolved(compiler.resolution); |
1082 ConstantValue value = | 1083 ConstantValue value = |
1083 compiler.constants.getConstantValue(metadata.constant); | 1084 compiler.constants.getConstantValue(metadata.constant); |
1084 ResolutionDartType type = value.getType(compiler.commonElements); | 1085 ResolutionDartType type = |
| 1086 value.getType(compiler.resolution.commonElements); |
1085 Element element = type.element; | 1087 Element element = type.element; |
1086 if (element == compiler.commonElements.deferredLibraryClass) { | 1088 if (element == |
| 1089 compiler.resolution.commonElements.deferredLibraryClass) { |
1087 ConstructedConstantValue constant = value; | 1090 ConstructedConstantValue constant = value; |
1088 StringConstantValue s = constant.fields.values.single; | 1091 StringConstantValue s = constant.fields.values.single; |
1089 result = s.primitiveValue; | 1092 result = s.primitiveValue; |
1090 break; | 1093 break; |
1091 } | 1094 } |
1092 } | 1095 } |
1093 } | 1096 } |
1094 assert(result != null); | 1097 assert(result != null); |
1095 return result; | 1098 return result; |
1096 } | 1099 } |
1097 | 1100 |
1098 bool operator ==(other) { | 1101 bool operator ==(other) { |
1099 if (other is! _DeclaredDeferredImport) return false; | 1102 if (other is! _DeclaredDeferredImport) return false; |
1100 return declaration == other.declaration; | 1103 return declaration == other.declaration; |
1101 } | 1104 } |
1102 | 1105 |
1103 int get hashCode => declaration.hashCode * 17; | 1106 int get hashCode => declaration.hashCode * 17; |
1104 | 1107 |
1105 String toString() => '$declaration'; | 1108 String toString() => '$declaration'; |
1106 } | 1109 } |
OLD | NEW |