| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 254 |
| 255 void registerConstantDeferredUse( | 255 void registerConstantDeferredUse( |
| 256 DeferredConstantValue constant, PrefixElement prefix) { | 256 DeferredConstantValue constant, PrefixElement prefix) { |
| 257 OutputUnit outputUnit = new OutputUnit(); | 257 OutputUnit outputUnit = new OutputUnit(); |
| 258 outputUnit.imports.add(new _DeclaredDeferredImport(prefix.deferredImport)); | 258 outputUnit.imports.add(new _DeclaredDeferredImport(prefix.deferredImport)); |
| 259 | 259 |
| 260 // Check to see if there is already a canonical output unit registered. | 260 // Check to see if there is already a canonical output unit registered. |
| 261 _constantToOutputUnit[constant] = _getCanonicalUnit(outputUnit); | 261 _constantToOutputUnit[constant] = _getCanonicalUnit(outputUnit); |
| 262 } | 262 } |
| 263 | 263 |
| 264 /// Answers whether [element] is explicitly deferred when referred to from | 264 /// Given [imports] that refer to an element from a library, determine whether |
| 265 /// [library]. | 265 /// the element is explicitly deferred. |
| 266 bool _isExplicitlyDeferred(Element element, LibraryElement library) { | 266 static bool _isExplicitlyDeferred(Iterable<ImportElement> imports) { |
| 267 Iterable<ImportElement> imports = _getImports(element, library); | |
| 268 // If the element is not imported explicitly, it is implicitly imported | 267 // If the element is not imported explicitly, it is implicitly imported |
| 269 // not deferred. | 268 // not deferred. |
| 270 if (imports.isEmpty) return false; | 269 if (imports.isEmpty) return false; |
| 271 // An element could potentially be loaded by several imports. If all of them | 270 // An element could potentially be loaded by several imports. If all of them |
| 272 // is explicitly deferred, we say the element is explicitly deferred. | 271 // is explicitly deferred, we say the element is explicitly deferred. |
| 273 // TODO(sigurdm): We might want to give a warning if the imports do not | 272 // TODO(sigurdm): We might want to give a warning if the imports do not |
| 274 // agree. | 273 // agree. |
| 275 return imports.every((ImportElement import) => import.isDeferred); | 274 return imports.every((ImportElement import) => import.isDeferred); |
| 276 } | 275 } |
| 277 | 276 |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 elements.add(element); | 550 elements.add(element); |
| 552 | 551 |
| 553 // This call can modify [dependentElements] and [dependentConstants]. | 552 // This call can modify [dependentElements] and [dependentConstants]. |
| 554 _collectAllElementsAndConstantsResolvedFrom( | 553 _collectAllElementsAndConstantsResolvedFrom( |
| 555 element, dependentElements, dependentConstants, isMirrorUsage); | 554 element, dependentElements, dependentConstants, isMirrorUsage); |
| 556 | 555 |
| 557 library = element.library; | 556 library = element.library; |
| 558 } | 557 } |
| 559 | 558 |
| 560 for (Element dependency in dependentElements) { | 559 for (Element dependency in dependentElements) { |
| 561 if (_isExplicitlyDeferred(dependency, library)) { | 560 Iterable<ImportElement> imports = _getImports(dependency, library); |
| 562 for (ImportElement deferredImport in _getImports(dependency, library)) { | 561 if (_isExplicitlyDeferred(imports)) { |
| 562 for (ImportElement deferredImport in imports) { |
| 563 _mapDependencies( | 563 _mapDependencies( |
| 564 element: dependency, | 564 element: dependency, |
| 565 import: new _DeclaredDeferredImport(deferredImport)); | 565 import: new _DeclaredDeferredImport(deferredImport)); |
| 566 } | 566 } |
| 567 } else { | 567 } else { |
| 568 _mapDependencies(element: dependency, import: import); | 568 _mapDependencies(element: dependency, import: import); |
| 569 } | 569 } |
| 570 } | 570 } |
| 571 | 571 |
| 572 for (ConstantValue dependency in dependentConstants) { | 572 for (ConstantValue dependency in dependentConstants) { |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 | 1118 |
| 1119 bool operator ==(other) { | 1119 bool operator ==(other) { |
| 1120 if (other is! _DeclaredDeferredImport) return false; | 1120 if (other is! _DeclaredDeferredImport) return false; |
| 1121 return declaration == other.declaration; | 1121 return declaration == other.declaration; |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 int get hashCode => declaration.hashCode * 17; | 1124 int get hashCode => declaration.hashCode * 17; |
| 1125 | 1125 |
| 1126 String toString() => '$declaration'; | 1126 String toString() => '$declaration'; |
| 1127 } | 1127 } |
| OLD | NEW |