| 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 'constants/expressions.dart'; | 7 import 'constants/expressions.dart'; |
| 8 import 'constants/values.dart' show | 8 import 'constants/values.dart' show |
| 9 ConstantValue, | 9 ConstantValue, |
| 10 ConstructedConstantValue, | 10 ConstructedConstantValue, |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 for (Element dependency in treeElements.allElements) { | 280 for (Element dependency in treeElements.allElements) { |
| 281 if (dependency.isLocal && !dependency.isFunction) continue; | 281 if (dependency.isLocal && !dependency.isFunction) continue; |
| 282 if (dependency.isErroneous) continue; | 282 if (dependency.isErroneous) continue; |
| 283 if (dependency.isTypeVariable) continue; | 283 if (dependency.isTypeVariable) continue; |
| 284 | 284 |
| 285 elements.add(dependency); | 285 elements.add(dependency); |
| 286 } | 286 } |
| 287 treeElements.forEachConstantNode((Node node, _) { | 287 treeElements.forEachConstantNode((Node node, _) { |
| 288 // Explicitly depend on the backend constants. | 288 // Explicitly depend on the backend constants. |
| 289 constants.add( | 289 constants.add( |
| 290 backend.constants.getConstantForNode(node, treeElements).value); | 290 backend.constants.getConstantValueForNode(node, treeElements)); |
| 291 }); | 291 }); |
| 292 elements.addAll(treeElements.otherDependencies); | 292 elements.addAll(treeElements.otherDependencies); |
| 293 } | 293 } |
| 294 | 294 |
| 295 // TODO(sigurdm): How is metadata on a patch-class handled? | 295 // TODO(sigurdm): How is metadata on a patch-class handled? |
| 296 for (MetadataAnnotation metadata in element.metadata) { | 296 for (MetadataAnnotation metadata in element.metadata) { |
| 297 ConstantExpression constant = | 297 ConstantValue constant = |
| 298 backend.constants.getConstantForMetadata(metadata); | 298 backend.constants.getConstantValueForMetadata(metadata); |
| 299 if (constant != null) { | 299 if (constant != null) { |
| 300 constants.add(constant.value); | 300 constants.add(constant); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 collectTypeDependencies(DartType type) { | 304 collectTypeDependencies(DartType type) { |
| 305 if (type is FunctionType) { | 305 if (type is FunctionType) { |
| 306 for (DartType argumentType in type.parameterTypes) { | 306 for (DartType argumentType in type.parameterTypes) { |
| 307 collectTypeDependencies(argumentType); | 307 collectTypeDependencies(argumentType); |
| 308 } | 308 } |
| 309 for (DartType argumentType in type.optionalParameterTypes) { | 309 for (DartType argumentType in type.optionalParameterTypes) { |
| 310 collectTypeDependencies(argumentType); | 310 collectTypeDependencies(argumentType); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 } | 484 } |
| 485 | 485 |
| 486 // For each deferred import we analyze all elements reachable from the | 486 // For each deferred import we analyze all elements reachable from the |
| 487 // imported library through non-deferred imports. | 487 // imported library through non-deferred imports. |
| 488 handleLibrary(LibraryElement library, Import deferredImport) { | 488 handleLibrary(LibraryElement library, Import deferredImport) { |
| 489 library.implementation.forEachLocalMember((Element element) { | 489 library.implementation.forEachLocalMember((Element element) { |
| 490 mapDependenciesIfResolved(element, deferredImport); | 490 mapDependenciesIfResolved(element, deferredImport); |
| 491 }); | 491 }); |
| 492 | 492 |
| 493 for (MetadataAnnotation metadata in library.metadata) { | 493 for (MetadataAnnotation metadata in library.metadata) { |
| 494 ConstantExpression constant = | 494 ConstantValue constant = |
| 495 backend.constants.getConstantForMetadata(metadata); | 495 backend.constants.getConstantValueForMetadata(metadata); |
| 496 if (constant != null) { | 496 if (constant != null) { |
| 497 _mapConstantDependencies(constant.value, | 497 _mapConstantDependencies(constant, deferredImport); |
| 498 deferredImport); | |
| 499 } | 498 } |
| 500 } | 499 } |
| 501 for (LibraryTag tag in library.tags) { | 500 for (LibraryTag tag in library.tags) { |
| 502 for (MetadataAnnotation metadata in tag.metadata) { | 501 for (MetadataAnnotation metadata in tag.metadata) { |
| 503 ConstantExpression constant = | 502 ConstantValue constant = |
| 504 backend.constants.getConstantForMetadata(metadata); | 503 backend.constants.getConstantValueForMetadata(metadata); |
| 505 if (constant != null) { | 504 if (constant != null) { |
| 506 _mapConstantDependencies(constant.value, | 505 _mapConstantDependencies(constant, deferredImport); |
| 507 deferredImport); | |
| 508 } | 506 } |
| 509 } | 507 } |
| 510 } | 508 } |
| 511 } | 509 } |
| 512 | 510 |
| 513 for (Import deferredImport in _allDeferredImports.keys) { | 511 for (Import deferredImport in _allDeferredImports.keys) { |
| 514 LibraryElement deferredLibrary = _allDeferredImports[deferredImport]; | 512 LibraryElement deferredLibrary = _allDeferredImports[deferredImport]; |
| 515 for (LibraryElement library in | 513 for (LibraryElement library in |
| 516 _nonDeferredReachableLibraries(deferredLibrary)) { | 514 _nonDeferredReachableLibraries(deferredLibrary)) { |
| 517 handleLibrary(library, deferredImport); | 515 handleLibrary(library, deferredImport); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 530 String result; | 528 String result; |
| 531 if (import == _fakeMainImport) { | 529 if (import == _fakeMainImport) { |
| 532 result = "main"; | 530 result = "main"; |
| 533 } else if (import.isDeferred) { | 531 } else if (import.isDeferred) { |
| 534 result = import.prefix.toString(); | 532 result = import.prefix.toString(); |
| 535 } else { | 533 } else { |
| 536 Link<MetadataAnnotation> metadatas = import.metadata; | 534 Link<MetadataAnnotation> metadatas = import.metadata; |
| 537 assert(metadatas != null); | 535 assert(metadatas != null); |
| 538 for (MetadataAnnotation metadata in metadatas) { | 536 for (MetadataAnnotation metadata in metadatas) { |
| 539 metadata.ensureResolved(compiler); | 537 metadata.ensureResolved(compiler); |
| 540 Element element = | 538 ConstantValue value = |
| 541 metadata.constant.value.getType(compiler.coreTypes).element; | 539 compiler.constants.getConstantValue(metadata.constant); |
| 540 Element element = value.getType(compiler.coreTypes).element; |
| 542 if (element == deferredLibraryClass) { | 541 if (element == deferredLibraryClass) { |
| 543 ConstructedConstantValue constant = metadata.constant.value; | 542 ConstructedConstantValue constant = value; |
| 544 StringConstantValue s = constant.fields.values.single; | 543 StringConstantValue s = constant.fields.values.single; |
| 545 result = s.primitiveValue.slowToString(); | 544 result = s.primitiveValue.slowToString(); |
| 546 break; | 545 break; |
| 547 } | 546 } |
| 548 } | 547 } |
| 549 } | 548 } |
| 550 assert(result != null); | 549 assert(result != null); |
| 551 importDeferName[import] = makeUnique(result, usedImportNames);; | 550 importDeferName[import] = makeUnique(result, usedImportNames);; |
| 552 } | 551 } |
| 553 | 552 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 // instead of a Link. | 719 // instead of a Link. |
| 721 for (LibraryTag tag in library.tags) { | 720 for (LibraryTag tag in library.tags) { |
| 722 if (tag is! Import) continue; | 721 if (tag is! Import) continue; |
| 723 Import import = tag; | 722 Import import = tag; |
| 724 | 723 |
| 725 /// Give an error if the old annotation-based syntax has been used. | 724 /// Give an error if the old annotation-based syntax has been used. |
| 726 Link<MetadataAnnotation> metadataList = import.metadata; | 725 Link<MetadataAnnotation> metadataList = import.metadata; |
| 727 if (metadataList != null) { | 726 if (metadataList != null) { |
| 728 for (MetadataAnnotation metadata in metadataList) { | 727 for (MetadataAnnotation metadata in metadataList) { |
| 729 metadata.ensureResolved(compiler); | 728 metadata.ensureResolved(compiler); |
| 730 Element element = | 729 ConstantValue value = |
| 731 metadata.constant.value.getType(compiler.coreTypes).element; | 730 compiler.constants.getConstantValue(metadata.constant); |
| 731 Element element = value.getType(compiler.coreTypes).element; |
| 732 if (element == deferredLibraryClass) { | 732 if (element == deferredLibraryClass) { |
| 733 compiler.reportError( | 733 compiler.reportError( |
| 734 import, MessageKind.DEFERRED_OLD_SYNTAX); | 734 import, MessageKind.DEFERRED_OLD_SYNTAX); |
| 735 } | 735 } |
| 736 } | 736 } |
| 737 } | 737 } |
| 738 | 738 |
| 739 String prefix = (import.prefix != null) | 739 String prefix = (import.prefix != null) |
| 740 ? import.prefix.toString() | 740 ? import.prefix.toString() |
| 741 : null; | 741 : null; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 890 _importingLibrary = importingLibrary; | 890 _importingLibrary = importingLibrary; |
| 891 | 891 |
| 892 String get importingLibraryName { | 892 String get importingLibraryName { |
| 893 String libraryName = _importingLibrary.getLibraryName(); | 893 String libraryName = _importingLibrary.getLibraryName(); |
| 894 return libraryName == "" | 894 return libraryName == "" |
| 895 ? "<unnamed>" | 895 ? "<unnamed>" |
| 896 : libraryName; | 896 : libraryName; |
| 897 } | 897 } |
| 898 | 898 |
| 899 } | 899 } |
| OLD | NEW |