Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(310)

Side by Side Diff: pkg/compiler/lib/src/deferred_load.dart

Issue 2620023002: Use elements/types in constants/values (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 Backend; 7 import 'common/backend_api.dart' show Backend;
8 import 'common/tasks.dart' show CompilerTask; 8 import 'common/tasks.dart' show CompilerTask;
9 import 'common.dart'; 9 import 'common.dart';
10 import 'compiler.dart' show Compiler; 10 import 'compiler.dart' show Compiler;
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
486 } 486 }
487 487
488 /// Add all dependencies of [constant] to the mapping of [import]. 488 /// Add all dependencies of [constant] to the mapping of [import].
489 void _mapConstantDependencies( 489 void _mapConstantDependencies(
490 ConstantValue constant, _DeferredImport import) { 490 ConstantValue constant, _DeferredImport import) {
491 Set<ConstantValue> constants = _constantsDeferredBy.putIfAbsent( 491 Set<ConstantValue> constants = _constantsDeferredBy.putIfAbsent(
492 import, () => new Set<ConstantValue>()); 492 import, () => new Set<ConstantValue>());
493 if (constants.contains(constant)) return; 493 if (constants.contains(constant)) return;
494 constants.add(constant); 494 constants.add(constant);
495 if (constant is ConstructedConstantValue) { 495 if (constant is ConstructedConstantValue) {
496 _mapDependencies(element: constant.type.element, import: import); 496 ClassElement cls = constant.type.element;
497 _mapDependencies(element: cls, import: import);
497 } 498 }
498 constant.getDependencies().forEach((ConstantValue dependency) { 499 constant.getDependencies().forEach((ConstantValue dependency) {
499 _mapConstantDependencies(dependency, import); 500 _mapConstantDependencies(dependency, import);
500 }); 501 });
501 } 502 }
502 503
503 /// Recursively traverses the graph of dependencies from one of [element] 504 /// Recursively traverses the graph of dependencies from one of [element]
504 /// or [constant], mapping deferred imports to each dependency it needs in the 505 /// or [constant], mapping deferred imports to each dependency it needs in the
505 /// sets [_importedDeferredBy] and [_constantsDeferredBy]. 506 /// sets [_importedDeferredBy] and [_constantsDeferredBy].
506 /// Only one of [element] and [constant] should be given. 507 /// Only one of [element] and [constant] should be given.
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List 792 // TODO(sigurdm): Make helper getLibraryImportTags when tags is a List
792 // instead of a Link. 793 // instead of a Link.
793 for (ImportElement import in library.imports) { 794 for (ImportElement import in library.imports) {
794 /// Give an error if the old annotation-based syntax has been used. 795 /// Give an error if the old annotation-based syntax has been used.
795 List<MetadataAnnotation> metadataList = import.metadata; 796 List<MetadataAnnotation> metadataList = import.metadata;
796 if (metadataList != null) { 797 if (metadataList != null) {
797 for (MetadataAnnotation metadata in metadataList) { 798 for (MetadataAnnotation metadata in metadataList) {
798 metadata.ensureResolved(compiler.resolution); 799 metadata.ensureResolved(compiler.resolution);
799 ConstantValue value = 800 ConstantValue value =
800 compiler.constants.getConstantValue(metadata.constant); 801 compiler.constants.getConstantValue(metadata.constant);
801 Element element = value.getType(compiler.commonElements).element; 802 ResolutionDartType type = value.getType(compiler.commonElements);
803 Element element = type.element;
802 if (element == deferredLibraryClass) { 804 if (element == deferredLibraryClass) {
803 reporter.reportErrorMessage( 805 reporter.reportErrorMessage(
804 import, MessageKind.DEFERRED_OLD_SYNTAX); 806 import, MessageKind.DEFERRED_OLD_SYNTAX);
805 } 807 }
806 } 808 }
807 } 809 }
808 810
809 String prefix = (import.prefix != null) ? import.prefix.name : null; 811 String prefix = (import.prefix != null) ? import.prefix.name : null;
810 // The last import we saw with the same prefix. 812 // The last import we saw with the same prefix.
811 ImportElement previousDeferredImport = prefixDeferredImport[prefix]; 813 ImportElement previousDeferredImport = prefixDeferredImport[prefix];
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 result = ''; 1029 result = '';
1028 } 1030 }
1029 } else { 1031 } else {
1030 // Finds the first argument to the [DeferredLibrary] annotation 1032 // Finds the first argument to the [DeferredLibrary] annotation
1031 List<MetadataAnnotation> metadatas = declaration.metadata; 1033 List<MetadataAnnotation> metadatas = declaration.metadata;
1032 assert(metadatas != null); 1034 assert(metadatas != null);
1033 for (MetadataAnnotation metadata in metadatas) { 1035 for (MetadataAnnotation metadata in metadatas) {
1034 metadata.ensureResolved(compiler.resolution); 1036 metadata.ensureResolved(compiler.resolution);
1035 ConstantValue value = 1037 ConstantValue value =
1036 compiler.constants.getConstantValue(metadata.constant); 1038 compiler.constants.getConstantValue(metadata.constant);
1037 Element element = value.getType(compiler.commonElements).element; 1039 ResolutionDartType type = value.getType(compiler.commonElements);
1040 Element element = type.element;
1038 if (element == compiler.commonElements.deferredLibraryClass) { 1041 if (element == compiler.commonElements.deferredLibraryClass) {
1039 ConstructedConstantValue constant = value; 1042 ConstructedConstantValue constant = value;
1040 StringConstantValue s = constant.fields.values.single; 1043 StringConstantValue s = constant.fields.values.single;
1041 result = s.primitiveValue.slowToString(); 1044 result = s.primitiveValue.slowToString();
1042 break; 1045 break;
1043 } 1046 }
1044 } 1047 }
1045 } 1048 }
1046 assert(result != null); 1049 assert(result != null);
1047 return result; 1050 return result;
1048 } 1051 }
1049 1052
1050 bool operator ==(other) { 1053 bool operator ==(other) {
1051 if (other is! _DeclaredDeferredImport) return false; 1054 if (other is! _DeclaredDeferredImport) return false;
1052 return declaration == other.declaration; 1055 return declaration == other.declaration;
1053 } 1056 }
1054 1057
1055 int get hashCode => declaration.hashCode * 17; 1058 int get hashCode => declaration.hashCode * 17;
1056 1059
1057 String toString() => '$declaration'; 1060 String toString() => '$declaration';
1058 } 1061 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698