| 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 'cps_ir/const_expression.dart'; |
| 8 |
| 7 import 'dart2jslib.dart' show | 9 import 'dart2jslib.dart' show |
| 8 Backend, | 10 Backend, |
| 9 Compiler, | 11 Compiler, |
| 10 CompilerTask, | 12 CompilerTask, |
| 11 Constant, | 13 Constant, |
| 12 ConstructedConstant, | 14 ConstructedConstant, |
| 13 MessageKind, | 15 MessageKind, |
| 14 DeferredConstant, | 16 DeferredConstant, |
| 15 StringConstant, | 17 StringConstant, |
| 16 invariant; | 18 invariant; |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 for (Element dependency in treeElements.allElements) { | 309 for (Element dependency in treeElements.allElements) { |
| 308 if (dependency.isLocal && !dependency.isFunction) continue; | 310 if (dependency.isLocal && !dependency.isFunction) continue; |
| 309 if (dependency.isErroneous) continue; | 311 if (dependency.isErroneous) continue; |
| 310 if (dependency.isTypeVariable) continue; | 312 if (dependency.isTypeVariable) continue; |
| 311 | 313 |
| 312 elements.add(dependency); | 314 elements.add(dependency); |
| 313 } | 315 } |
| 314 treeElements.forEachConstantNode((Node node, _) { | 316 treeElements.forEachConstantNode((Node node, _) { |
| 315 // Explicitly depend on the backend constants. | 317 // Explicitly depend on the backend constants. |
| 316 addConstants( | 318 addConstants( |
| 317 backend.constants.getConstantForNode(node, treeElements)); | 319 backend.constants.getConstantForNode(node, treeElements).value); |
| 318 }); | 320 }); |
| 319 elements.addAll(treeElements.otherDependencies); | 321 elements.addAll(treeElements.otherDependencies); |
| 320 } | 322 } |
| 321 | 323 |
| 322 // TODO(sigurdm): How is metadata on a patch-class handled? | 324 // TODO(sigurdm): How is metadata on a patch-class handled? |
| 323 for (MetadataAnnotation metadata in element.metadata) { | 325 for (MetadataAnnotation metadata in element.metadata) { |
| 324 Constant constant = backend.constants.getConstantForMetadata(metadata); | 326 ConstExp constant = backend.constants.getConstantForMetadata(metadata); |
| 325 if (constant != null) { | 327 if (constant != null) { |
| 326 addConstants(constant); | 328 addConstants(constant.value); |
| 327 } | 329 } |
| 328 } | 330 } |
| 329 if (element.isClass) { | 331 if (element.isClass) { |
| 330 // If we see a class, add everything its live instance members refer | 332 // If we see a class, add everything its live instance members refer |
| 331 // to. Static members are not relevant, unless we are processing | 333 // to. Static members are not relevant, unless we are processing |
| 332 // extra dependencies due to mirrors. | 334 // extra dependencies due to mirrors. |
| 333 void addLiveInstanceMember(Element element) { | 335 void addLiveInstanceMember(Element element) { |
| 334 if (!compiler.enqueuer.resolution.isLive(element)) return; | 336 if (!compiler.enqueuer.resolution.isLive(element)) return; |
| 335 if (!isMirrorUsage && !element.isInstanceMember) return; | 337 if (!isMirrorUsage && !element.isInstanceMember) return; |
| 336 collectDependencies(element.implementation); | 338 collectDependencies(element.implementation); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 } | 452 } |
| 451 | 453 |
| 452 // For each deferred import we analyze all elements reachable from the | 454 // For each deferred import we analyze all elements reachable from the |
| 453 // imported library through non-deferred imports. | 455 // imported library through non-deferred imports. |
| 454 handleLibrary(LibraryElement library, Import deferredImport) { | 456 handleLibrary(LibraryElement library, Import deferredImport) { |
| 455 library.implementation.forEachLocalMember((Element element) { | 457 library.implementation.forEachLocalMember((Element element) { |
| 456 mapDependenciesIfResolved(element, deferredImport); | 458 mapDependenciesIfResolved(element, deferredImport); |
| 457 }); | 459 }); |
| 458 | 460 |
| 459 for (MetadataAnnotation metadata in library.metadata) { | 461 for (MetadataAnnotation metadata in library.metadata) { |
| 460 Constant constant = | 462 ConstExp constant = |
| 461 backend.constants.getConstantForMetadata(metadata); | 463 backend.constants.getConstantForMetadata(metadata); |
| 462 if (constant != null) { | 464 if (constant != null) { |
| 463 _mapDependencies(constant.computeType(compiler).element, | 465 _mapDependencies(constant.value.computeType(compiler).element, |
| 464 deferredImport); | 466 deferredImport); |
| 465 } | 467 } |
| 466 } | 468 } |
| 467 for (LibraryTag tag in library.tags) { | 469 for (LibraryTag tag in library.tags) { |
| 468 for (MetadataAnnotation metadata in tag.metadata) { | 470 for (MetadataAnnotation metadata in tag.metadata) { |
| 469 Constant constant = | 471 ConstExp constant = |
| 470 backend.constants.getConstantForMetadata(metadata); | 472 backend.constants.getConstantForMetadata(metadata); |
| 471 if (constant != null) { | 473 if (constant != null) { |
| 472 _mapDependencies(constant.computeType(compiler).element, | 474 _mapDependencies(constant.value.computeType(compiler).element, |
| 473 deferredImport); | 475 deferredImport); |
| 474 } | 476 } |
| 475 } | 477 } |
| 476 } | 478 } |
| 477 } | 479 } |
| 478 | 480 |
| 479 for (Import deferredImport in _allDeferredImports.keys) { | 481 for (Import deferredImport in _allDeferredImports.keys) { |
| 480 LibraryElement deferredLibrary = _allDeferredImports[deferredImport]; | 482 LibraryElement deferredLibrary = _allDeferredImports[deferredImport]; |
| 481 for (LibraryElement library in | 483 for (LibraryElement library in |
| 482 _nonDeferredReachableLibraries(deferredLibrary)) { | 484 _nonDeferredReachableLibraries(deferredLibrary)) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 496 String result; | 498 String result; |
| 497 if (import == _fakeMainImport) { | 499 if (import == _fakeMainImport) { |
| 498 result = "main"; | 500 result = "main"; |
| 499 } else if (import.isDeferred) { | 501 } else if (import.isDeferred) { |
| 500 result = import.prefix.toString(); | 502 result = import.prefix.toString(); |
| 501 } else { | 503 } else { |
| 502 Link<MetadataAnnotation> metadatas = import.metadata; | 504 Link<MetadataAnnotation> metadatas = import.metadata; |
| 503 assert(metadatas != null); | 505 assert(metadatas != null); |
| 504 for (MetadataAnnotation metadata in metadatas) { | 506 for (MetadataAnnotation metadata in metadatas) { |
| 505 metadata.ensureResolved(compiler); | 507 metadata.ensureResolved(compiler); |
| 506 Element element = metadata.value.computeType(compiler).element; | 508 Element element = metadata.constant.value.computeType(compiler).elemen
t; |
| 507 if (element == deferredLibraryClass) { | 509 if (element == deferredLibraryClass) { |
| 508 ConstructedConstant constant = metadata.value; | 510 ConstructedConstant constant = metadata.constant.value; |
| 509 StringConstant s = constant.fields[0]; | 511 StringConstant s = constant.fields[0]; |
| 510 result = s.value.slowToString(); | 512 result = s.value.slowToString(); |
| 511 break; | 513 break; |
| 512 } | 514 } |
| 513 } | 515 } |
| 514 } | 516 } |
| 515 assert(result != null); | 517 assert(result != null); |
| 516 importDeferName[import] = makeUnique(result, usedImportNames);; | 518 importDeferName[import] = makeUnique(result, usedImportNames);; |
| 517 } | 519 } |
| 518 | 520 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 // instead of a Link. | 652 // instead of a Link. |
| 651 for (LibraryTag tag in library.tags) { | 653 for (LibraryTag tag in library.tags) { |
| 652 if (tag is! Import) continue; | 654 if (tag is! Import) continue; |
| 653 Import import = tag; | 655 Import import = tag; |
| 654 | 656 |
| 655 /// Give an error if the old annotation-based syntax has been used. | 657 /// Give an error if the old annotation-based syntax has been used. |
| 656 Link<MetadataAnnotation> metadataList = import.metadata; | 658 Link<MetadataAnnotation> metadataList = import.metadata; |
| 657 if (metadataList != null) { | 659 if (metadataList != null) { |
| 658 for (MetadataAnnotation metadata in metadataList) { | 660 for (MetadataAnnotation metadata in metadataList) { |
| 659 metadata.ensureResolved(compiler); | 661 metadata.ensureResolved(compiler); |
| 660 Element element = metadata.value.computeType(compiler).element; | 662 Element element = |
| 663 metadata.constant.value.computeType(compiler).element; |
| 661 if (element == deferredLibraryClass) { | 664 if (element == deferredLibraryClass) { |
| 662 compiler.reportFatalError(import, MessageKind.DEFERRED_OLD_SYNT
AX); | 665 compiler.reportFatalError(import, MessageKind.DEFERRED_OLD_SYNT
AX); |
| 663 } | 666 } |
| 664 } | 667 } |
| 665 } | 668 } |
| 666 | 669 |
| 667 String prefix = (import.prefix != null) | 670 String prefix = (import.prefix != null) |
| 668 ? import.prefix.toString() | 671 ? import.prefix.toString() |
| 669 : null; | 672 : null; |
| 670 // The last import we saw with the same prefix. | 673 // The last import we saw with the same prefix. |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 Element maybePrefix = elements[identifier]; | 760 Element maybePrefix = elements[identifier]; |
| 758 if (maybePrefix != null && maybePrefix.isPrefix) { | 761 if (maybePrefix != null && maybePrefix.isPrefix) { |
| 759 PrefixElement prefixElement = maybePrefix; | 762 PrefixElement prefixElement = maybePrefix; |
| 760 if (prefixElement.isDeferred) { | 763 if (prefixElement.isDeferred) { |
| 761 return prefixElement; | 764 return prefixElement; |
| 762 } | 765 } |
| 763 } | 766 } |
| 764 return null; | 767 return null; |
| 765 } | 768 } |
| 766 } | 769 } |
| OLD | NEW |