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 Backend; | 7 import 'common/backend_api.dart' show Backend; |
8 import 'common/tasks.dart' show CompilerTask; | 8 import 'common/tasks.dart' show CompilerTask; |
9 import 'common.dart'; | 9 import 'common.dart'; |
10 import 'compiler.dart' show Compiler; | 10 import 'compiler.dart' show Compiler; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 } | 82 } |
83 | 83 |
84 /// For each deferred import, find elements and constants to be loaded when that | 84 /// For each deferred import, find elements and constants to be loaded when that |
85 /// import is loaded. Elements that are used by several deferred imports are in | 85 /// import is loaded. Elements that are used by several deferred imports are in |
86 /// shared OutputUnits. | 86 /// shared OutputUnits. |
87 class DeferredLoadTask extends CompilerTask { | 87 class DeferredLoadTask extends CompilerTask { |
88 /// The name of this task. | 88 /// The name of this task. |
89 String get name => 'Deferred Loading'; | 89 String get name => 'Deferred Loading'; |
90 | 90 |
91 /// DeferredLibrary from dart:async | 91 /// DeferredLibrary from dart:async |
92 ClassElement get deferredLibraryClass => compiler.deferredLibraryClass; | 92 ClassElement get deferredLibraryClass => |
| 93 compiler.commonElements.deferredLibraryClass; |
93 | 94 |
94 /// A synthetic import representing the loading of the main program. | 95 /// A synthetic import representing the loading of the main program. |
95 final _DeferredImport _fakeMainImport = const _DeferredImport(); | 96 final _DeferredImport _fakeMainImport = const _DeferredImport(); |
96 | 97 |
97 /// The OutputUnit that will be loaded when the program starts. | 98 /// The OutputUnit that will be loaded when the program starts. |
98 final OutputUnit mainOutputUnit = new OutputUnit(isMainOutput: true); | 99 final OutputUnit mainOutputUnit = new OutputUnit(isMainOutput: true); |
99 | 100 |
100 /// A set containing (eventually) all output units that will result from the | 101 /// A set containing (eventually) all output units that will result from the |
101 /// program. | 102 /// program. |
102 final Set<OutputUnit> allOutputUnits = new Set<OutputUnit>(); | 103 final Set<OutputUnit> allOutputUnits = new Set<OutputUnit>(); |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 } | 457 } |
457 } | 458 } |
458 | 459 |
459 iterateTags(library); | 460 iterateTags(library); |
460 if (library.isPatched) { | 461 if (library.isPatched) { |
461 iterateTags(library.implementation); | 462 iterateTags(library.implementation); |
462 } | 463 } |
463 } | 464 } |
464 | 465 |
465 traverseLibrary(root); | 466 traverseLibrary(root); |
466 result.add(compiler.coreLibrary); | 467 result.add(compiler.commonElements.coreLibrary); |
467 return result; | 468 return result; |
468 } | 469 } |
469 | 470 |
470 /// Add all dependencies of [constant] to the mapping of [import]. | 471 /// Add all dependencies of [constant] to the mapping of [import]. |
471 void _mapConstantDependencies( | 472 void _mapConstantDependencies( |
472 ConstantValue constant, _DeferredImport import) { | 473 ConstantValue constant, _DeferredImport import) { |
473 Set<ConstantValue> constants = _constantsDeferredBy.putIfAbsent( | 474 Set<ConstantValue> constants = _constantsDeferredBy.putIfAbsent( |
474 import, () => new Set<ConstantValue>()); | 475 import, () => new Set<ConstantValue>()); |
475 if (constants.contains(constant)) return; | 476 if (constants.contains(constant)) return; |
476 constants.add(constant); | 477 constants.add(constant); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 // are things that the backend needs but cannot associate with a | 662 // are things that the backend needs but cannot associate with a |
662 // particular element, for example, startRootIsolate. This set | 663 // particular element, for example, startRootIsolate. This set |
663 // also contains elements for which we lack precise information. | 664 // also contains elements for which we lack precise information. |
664 for (Element element | 665 for (Element element |
665 in compiler.globalDependencies.otherDependencies) { | 666 in compiler.globalDependencies.otherDependencies) { |
666 _mapDependencies(element: element, import: _fakeMainImport); | 667 _mapDependencies(element: element, import: _fakeMainImport); |
667 } | 668 } |
668 | 669 |
669 // Now check to see if we have to add more elements due to | 670 // Now check to see if we have to add more elements due to |
670 // mirrors. | 671 // mirrors. |
671 if (compiler.mirrorsLibrary != null) { | 672 if (compiler.commonElements.mirrorsLibrary != null) { |
672 _addMirrorElements(); | 673 _addMirrorElements(); |
673 } | 674 } |
674 | 675 |
675 // Build the OutputUnits using these two maps. | 676 // Build the OutputUnits using these two maps. |
676 Map<Element, OutputUnit> elementToOutputUnitBuilder = | 677 Map<Element, OutputUnit> elementToOutputUnitBuilder = |
677 new Map<Element, OutputUnit>(); | 678 new Map<Element, OutputUnit>(); |
678 Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder = | 679 Map<ConstantValue, OutputUnit> constantToOutputUnitBuilder = |
679 new Map<ConstantValue, OutputUnit>(); | 680 new Map<ConstantValue, OutputUnit>(); |
680 | 681 |
681 // Reverse the mappings. For each element record an OutputUnit | 682 // Reverse the mappings. For each element record an OutputUnit |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 } | 1015 } |
1015 } else { | 1016 } else { |
1016 // Finds the first argument to the [DeferredLibrary] annotation | 1017 // Finds the first argument to the [DeferredLibrary] annotation |
1017 List<MetadataAnnotation> metadatas = declaration.metadata; | 1018 List<MetadataAnnotation> metadatas = declaration.metadata; |
1018 assert(metadatas != null); | 1019 assert(metadatas != null); |
1019 for (MetadataAnnotation metadata in metadatas) { | 1020 for (MetadataAnnotation metadata in metadatas) { |
1020 metadata.ensureResolved(compiler.resolution); | 1021 metadata.ensureResolved(compiler.resolution); |
1021 ConstantValue value = | 1022 ConstantValue value = |
1022 compiler.constants.getConstantValue(metadata.constant); | 1023 compiler.constants.getConstantValue(metadata.constant); |
1023 Element element = value.getType(compiler.coreTypes).element; | 1024 Element element = value.getType(compiler.coreTypes).element; |
1024 if (element == compiler.deferredLibraryClass) { | 1025 if (element == compiler.commonElements.deferredLibraryClass) { |
1025 ConstructedConstantValue constant = value; | 1026 ConstructedConstantValue constant = value; |
1026 StringConstantValue s = constant.fields.values.single; | 1027 StringConstantValue s = constant.fields.values.single; |
1027 result = s.primitiveValue.slowToString(); | 1028 result = s.primitiveValue.slowToString(); |
1028 break; | 1029 break; |
1029 } | 1030 } |
1030 } | 1031 } |
1031 } | 1032 } |
1032 assert(result != null); | 1033 assert(result != null); |
1033 return result; | 1034 return result; |
1034 } | 1035 } |
1035 | 1036 |
1036 bool operator ==(other) { | 1037 bool operator ==(other) { |
1037 if (other is! _DeclaredDeferredImport) return false; | 1038 if (other is! _DeclaredDeferredImport) return false; |
1038 return declaration == other.declaration; | 1039 return declaration == other.declaration; |
1039 } | 1040 } |
1040 | 1041 |
1041 int get hashCode => declaration.hashCode * 17; | 1042 int get hashCode => declaration.hashCode * 17; |
1042 | 1043 |
1043 String toString() => '$declaration'; | 1044 String toString() => '$declaration'; |
1044 } | 1045 } |
OLD | NEW |