Chromium Code Reviews| 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 | |
| 265 /// [library]. | |
| 266 bool _isExplicitlyDeferred(Element element, LibraryElement library) { | |
| 267 Iterable<ImportElement> imports = _getImports(element, library); | |
| 268 // If the element is not imported explicitly, it is implicitly imported | |
| 269 // not deferred. | |
| 270 if (imports.isEmpty) return false; | |
| 271 // An element could potentially be loaded by several imports. If all of them | |
| 272 // 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 | |
| 274 // agree. | |
| 275 return imports.every((ImportElement import) => import.isDeferred); | |
| 276 } | |
| 277 | |
| 278 /// Returns every [ImportElement] that imports [element] into [library]. | 264 /// Returns every [ImportElement] that imports [element] into [library]. |
| 279 Iterable<ImportElement> _getImports(Element element, LibraryElement library) { | 265 Iterable<ImportElement> _getImports(Element element, LibraryElement library) { |
| 280 if (element.isClassMember) { | 266 if (element.isClassMember) { |
| 281 element = element.enclosingClass; | 267 element = element.enclosingClass; |
| 282 } | 268 } |
| 283 if (element.isAccessor) { | 269 if (element.isAccessor) { |
| 284 element = (element as AccessorElement).abstractField; | 270 element = (element as AccessorElement).abstractField; |
| 285 } | 271 } |
| 286 return library.getImportsFor(element); | 272 return library.getImportsFor(element); |
| 287 } | 273 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 elements.add(element); | 537 elements.add(element); |
| 552 | 538 |
| 553 // This call can modify [dependentElements] and [dependentConstants]. | 539 // This call can modify [dependentElements] and [dependentConstants]. |
| 554 _collectAllElementsAndConstantsResolvedFrom( | 540 _collectAllElementsAndConstantsResolvedFrom( |
| 555 element, dependentElements, dependentConstants, isMirrorUsage); | 541 element, dependentElements, dependentConstants, isMirrorUsage); |
| 556 | 542 |
| 557 library = element.library; | 543 library = element.library; |
| 558 } | 544 } |
| 559 | 545 |
| 560 for (Element dependency in dependentElements) { | 546 for (Element dependency in dependentElements) { |
| 561 if (_isExplicitlyDeferred(dependency, library)) { | 547 Iterable<ImportElement> imports = _getImports(dependency, library); |
|
sra1
2017/08/16 01:09:22
Presumably this is actually a List.
Siggi Cherem (dart-lang)
2017/08/16 01:18:20
Ack - I'm using the declared type for now. I feel
| |
| 562 for (ImportElement deferredImport in _getImports(dependency, library)) { | 548 bool isExplicitlyDeferred = |
|
sra1
2017/08/16 01:09:22
This can still be a function, just taking the iter
Siggi Cherem (dart-lang)
2017/08/16 01:18:20
Done. Moved it was it used to be, but made the lis
| |
| 549 // If the element is not imported explicitly, it is implicitly | |
| 550 // imported not deferred. | |
| 551 !imports.isEmpty && | |
| 552 // An element could potentially be loaded by several imports. If | |
| 553 // all of them are explicitly deferred, we say the element is | |
| 554 // explicitly deferred. | |
| 555 // TODO(sigurdm): We might want to give a warning if the imports | |
| 556 // do not agree. | |
| 557 imports.every((i) => i.isDeferred); | |
| 558 if (isExplicitlyDeferred) { | |
| 559 for (ImportElement deferredImport in imports) { | |
| 563 _mapDependencies( | 560 _mapDependencies( |
| 564 element: dependency, | 561 element: dependency, |
| 565 import: new _DeclaredDeferredImport(deferredImport)); | 562 import: new _DeclaredDeferredImport(deferredImport)); |
| 566 } | 563 } |
| 567 } else { | 564 } else { |
| 568 _mapDependencies(element: dependency, import: import); | 565 _mapDependencies(element: dependency, import: import); |
| 569 } | 566 } |
| 570 } | 567 } |
| 571 | 568 |
| 572 for (ConstantValue dependency in dependentConstants) { | 569 for (ConstantValue dependency in dependentConstants) { |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1118 | 1115 |
| 1119 bool operator ==(other) { | 1116 bool operator ==(other) { |
| 1120 if (other is! _DeclaredDeferredImport) return false; | 1117 if (other is! _DeclaredDeferredImport) return false; |
| 1121 return declaration == other.declaration; | 1118 return declaration == other.declaration; |
| 1122 } | 1119 } |
| 1123 | 1120 |
| 1124 int get hashCode => declaration.hashCode * 17; | 1121 int get hashCode => declaration.hashCode * 17; |
| 1125 | 1122 |
| 1126 String toString() => '$declaration'; | 1123 String toString() => '$declaration'; |
| 1127 } | 1124 } |
| OLD | NEW |