| 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/backend_api.dart' show | 7 import 'common/backend_api.dart' show |
| 8 Backend; | 8 Backend; |
| 9 import 'common/resolution.dart' show |
| 10 Resolution; |
| 9 import 'common/tasks.dart' show | 11 import 'common/tasks.dart' show |
| 10 CompilerTask; | 12 CompilerTask; |
| 11 import 'compiler.dart' show | 13 import 'compiler.dart' show |
| 12 Compiler; | 14 Compiler; |
| 13 import 'constants/values.dart' show | 15 import 'constants/values.dart' show |
| 14 ConstantValue, | 16 ConstantValue, |
| 15 ConstructedConstantValue, | 17 ConstructedConstantValue, |
| 16 DeferredConstantValue, | 18 DeferredConstantValue, |
| 17 StringConstantValue; | 19 StringConstantValue; |
| 18 import 'dart_types.dart'; | 20 import 'dart_types.dart'; |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 } | 278 } |
| 277 for (DartType argumentType in type.optionalParameterTypes) { | 279 for (DartType argumentType in type.optionalParameterTypes) { |
| 278 collectTypeDependencies(argumentType); | 280 collectTypeDependencies(argumentType); |
| 279 } | 281 } |
| 280 for (DartType argumentType in type.namedParameterTypes) { | 282 for (DartType argumentType in type.namedParameterTypes) { |
| 281 collectTypeDependencies(argumentType); | 283 collectTypeDependencies(argumentType); |
| 282 } | 284 } |
| 283 collectTypeDependencies(type.returnType); | 285 collectTypeDependencies(type.returnType); |
| 284 } else if (type is TypedefType) { | 286 } else if (type is TypedefType) { |
| 285 elements.add(type.element); | 287 elements.add(type.element); |
| 286 collectTypeDependencies(type.unalias(compiler)); | 288 collectTypeDependencies(type.unalias(compiler.resolution)); |
| 287 } else if (type is InterfaceType) { | 289 } else if (type is InterfaceType) { |
| 288 elements.add(type.element); | 290 elements.add(type.element); |
| 289 } | 291 } |
| 290 } | 292 } |
| 291 | 293 |
| 292 /// Collects all direct dependencies of [element]. | 294 /// Collects all direct dependencies of [element]. |
| 293 /// | 295 /// |
| 294 /// The collected dependent elements and constants are are added to | 296 /// The collected dependent elements and constants are are added to |
| 295 /// [elements] and [constants] respectively. | 297 /// [elements] and [constants] respectively. |
| 296 void collectDependencies(Element element) { | 298 void collectDependencies(Element element) { |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 compiler.withCurrentElement(library, () { | 719 compiler.withCurrentElement(library, () { |
| 718 prefixDeferredImport.clear(); | 720 prefixDeferredImport.clear(); |
| 719 usedPrefixes.clear(); | 721 usedPrefixes.clear(); |
| 720 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List | 722 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List |
| 721 // instead of a Link. | 723 // instead of a Link. |
| 722 for (ImportElement import in library.imports) { | 724 for (ImportElement import in library.imports) { |
| 723 /// Give an error if the old annotation-based syntax has been used. | 725 /// Give an error if the old annotation-based syntax has been used. |
| 724 List<MetadataAnnotation> metadataList = import.metadata; | 726 List<MetadataAnnotation> metadataList = import.metadata; |
| 725 if (metadataList != null) { | 727 if (metadataList != null) { |
| 726 for (MetadataAnnotation metadata in metadataList) { | 728 for (MetadataAnnotation metadata in metadataList) { |
| 727 metadata.ensureResolved(compiler); | 729 metadata.ensureResolved(compiler.resolution); |
| 728 ConstantValue value = | 730 ConstantValue value = |
| 729 compiler.constants.getConstantValue(metadata.constant); | 731 compiler.constants.getConstantValue(metadata.constant); |
| 730 Element element = value.getType(compiler.coreTypes).element; | 732 Element element = value.getType(compiler.coreTypes).element; |
| 731 if (element == deferredLibraryClass) { | 733 if (element == deferredLibraryClass) { |
| 732 compiler.reportErrorMessage( | 734 compiler.reportErrorMessage( |
| 733 import, MessageKind.DEFERRED_OLD_SYNTAX); | 735 import, MessageKind.DEFERRED_OLD_SYNTAX); |
| 734 } | 736 } |
| 735 } | 737 } |
| 736 } | 738 } |
| 737 | 739 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 } else { | 917 } else { |
| 916 // This happens when the deferred import isn't declared with a prefix. | 918 // This happens when the deferred import isn't declared with a prefix. |
| 917 assert(compiler.compilationFailed); | 919 assert(compiler.compilationFailed); |
| 918 result = ''; | 920 result = ''; |
| 919 } | 921 } |
| 920 } else { | 922 } else { |
| 921 // Finds the first argument to the [DeferredLibrary] annotation | 923 // Finds the first argument to the [DeferredLibrary] annotation |
| 922 List<MetadataAnnotation> metadatas = declaration.metadata; | 924 List<MetadataAnnotation> metadatas = declaration.metadata; |
| 923 assert(metadatas != null); | 925 assert(metadatas != null); |
| 924 for (MetadataAnnotation metadata in metadatas) { | 926 for (MetadataAnnotation metadata in metadatas) { |
| 925 metadata.ensureResolved(compiler); | 927 metadata.ensureResolved(compiler.resolution); |
| 926 ConstantValue value = | 928 ConstantValue value = |
| 927 compiler.constants.getConstantValue(metadata.constant); | 929 compiler.constants.getConstantValue(metadata.constant); |
| 928 Element element = value.getType(compiler.coreTypes).element; | 930 Element element = value.getType(compiler.coreTypes).element; |
| 929 if (element == compiler.deferredLibraryClass) { | 931 if (element == compiler.deferredLibraryClass) { |
| 930 ConstructedConstantValue constant = value; | 932 ConstructedConstantValue constant = value; |
| 931 StringConstantValue s = constant.fields.values.single; | 933 StringConstantValue s = constant.fields.values.single; |
| 932 result = s.primitiveValue.slowToString(); | 934 result = s.primitiveValue.slowToString(); |
| 933 break; | 935 break; |
| 934 } | 936 } |
| 935 } | 937 } |
| 936 } | 938 } |
| 937 assert(result != null); | 939 assert(result != null); |
| 938 return result; | 940 return result; |
| 939 } | 941 } |
| 940 | 942 |
| 941 bool operator ==(other) { | 943 bool operator ==(other) { |
| 942 if (other is! _DeclaredDeferredImport) return false; | 944 if (other is! _DeclaredDeferredImport) return false; |
| 943 return declaration == other.declaration; | 945 return declaration == other.declaration; |
| 944 } | 946 } |
| 945 | 947 |
| 946 int get hashCode => declaration.hashCode * 17; | 948 int get hashCode => declaration.hashCode * 17; |
| 947 } | 949 } |
| OLD | NEW |