| 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 'dart2jslib.dart' show | 7 import 'dart2jslib.dart' show |
| 8 Compiler, | 8 Compiler, |
| 9 CompilerTask, | 9 CompilerTask, |
| 10 Constant, | 10 Constant, |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 264 |
| 265 /// Finds all elements and constants that [element] depends directly on. | 265 /// Finds all elements and constants that [element] depends directly on. |
| 266 /// (not the transitive closure.) | 266 /// (not the transitive closure.) |
| 267 /// | 267 /// |
| 268 /// Adds the results to [elements] and [constants]. | 268 /// Adds the results to [elements] and [constants]. |
| 269 void _collectAllElementsAndConstantsResolvedFrom(Element element, | 269 void _collectAllElementsAndConstantsResolvedFrom(Element element, |
| 270 Set<Element> elements, | 270 Set<Element> elements, |
| 271 Set<Constant> constants) { | 271 Set<Constant> constants) { |
| 272 element = element.implementation; | 272 element = element.implementation; |
| 273 for (MetadataAnnotation metadata in element.metadata) { | 273 for (MetadataAnnotation metadata in element.metadata) { |
| 274 if (metadata.value != null) constants.add(metadata.value); | 274 if (metadata.value != null) { |
| 275 constants.add(metadata.value); |
| 276 elements.add(metadata.value.computeType(compiler).element); |
| 277 } |
| 275 } | 278 } |
| 276 if (element.isClass()) { | 279 if (element.isClass()) { |
| 277 // If we see a class, add everything its instance members refer | 280 // If we see a class, add everything its instance members refer |
| 278 // to. Static members are not relevant. | 281 // to. Static members are not relevant. |
| 279 ClassElement cls = element.declaration; | 282 ClassElement cls = element.declaration; |
| 280 cls.forEachLocalMember((Element e) { | 283 cls.forEachLocalMember((Element e) { |
| 281 if (!e.isInstanceMember()) return; | 284 if (!e.isInstanceMember()) return; |
| 282 _collectDependencies(e.implementation, elements, constants); | 285 _collectDependencies(e.implementation, elements, constants); |
| 283 }); | 286 }); |
| 284 if (cls.implementation != cls) { | 287 if (cls.implementation != cls) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 /// | 375 /// |
| 373 /// The elements are added with [_mapDependencies]. | 376 /// The elements are added with [_mapDependencies]. |
| 374 void _addMirrorElements() { | 377 void _addMirrorElements() { |
| 375 MirrorUsageAnalyzerTask mirrorTask = compiler.mirrorUsageAnalyzerTask; | 378 MirrorUsageAnalyzerTask mirrorTask = compiler.mirrorUsageAnalyzerTask; |
| 376 // For each import we record all mirrors-used elements from all the | 379 // For each import we record all mirrors-used elements from all the |
| 377 // libraries reached directly from that import. | 380 // libraries reached directly from that import. |
| 378 for (Import deferredImport in _allDeferredImports.keys) { | 381 for (Import deferredImport in _allDeferredImports.keys) { |
| 379 LibraryElement deferredLibrary = _allDeferredImports[deferredImport]; | 382 LibraryElement deferredLibrary = _allDeferredImports[deferredImport]; |
| 380 for (LibraryElement library in | 383 for (LibraryElement library in |
| 381 _nonDeferredReachableLibraries(deferredLibrary)) { | 384 _nonDeferredReachableLibraries(deferredLibrary)) { |
| 385 // TODO(sigurdm): The metadata should go to the right output unit. |
| 386 // For now they all go to the main output unit. |
| 387 for (MetadataAnnotation metadata in library.metadata) { |
| 388 if (metadata.value != null) { |
| 389 _mapDependencies(metadata.value.computeType(compiler).element, |
| 390 _fakeMainImport); |
| 391 } |
| 392 } |
| 393 for (LibraryTag tag in library.tags) { |
| 394 for (MetadataAnnotation metadata in tag.metadata) { |
| 395 if (metadata.value != null) { |
| 396 _mapDependencies(metadata.value.computeType(compiler).element, |
| 397 _fakeMainImport); |
| 398 } |
| 399 } |
| 400 } |
| 401 |
| 382 if (mirrorTask.librariesWithUsage.contains(library)) { | 402 if (mirrorTask.librariesWithUsage.contains(library)) { |
| 383 | 403 |
| 384 Map<LibraryElement, List<MirrorUsage>> mirrorsResult = | 404 Map<LibraryElement, List<MirrorUsage>> mirrorsResult = |
| 385 mirrorTask.analyzer.collectMirrorsUsedAnnotation(); | 405 mirrorTask.analyzer.collectMirrorsUsedAnnotation(); |
| 386 | 406 |
| 387 // If there is a MirrorsUsed annotation we add only the needed | 407 // If there is a MirrorsUsed annotation we add only the needed |
| 388 // things to the output units for the library. | 408 // things to the output units for the library. |
| 389 List<MirrorUsage> mirrorUsages = mirrorsResult[library]; | 409 List<MirrorUsage> mirrorUsages = mirrorsResult[library]; |
| 390 if (mirrorUsages == null) continue; | 410 if (mirrorUsages == null) continue; |
| 391 for (MirrorUsage usage in mirrorUsages) { | 411 for (MirrorUsage usage in mirrorUsages) { |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 }); | 701 }); |
| 682 } | 702 } |
| 683 if (splitProgram && !deferredUsedFromMain) { | 703 if (splitProgram && !deferredUsedFromMain) { |
| 684 compiler.reportInfo( | 704 compiler.reportInfo( |
| 685 lastDeferred, | 705 lastDeferred, |
| 686 MessageKind.DEFERRED_LIBRARY_NOT_FROM_MAIN); | 706 MessageKind.DEFERRED_LIBRARY_NOT_FROM_MAIN); |
| 687 splitProgram = false; | 707 splitProgram = false; |
| 688 } | 708 } |
| 689 } | 709 } |
| 690 } | 710 } |
| OLD | NEW |