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

Side by Side Diff: pkg/analyzer/lib/src/summary/summarize_elements.dart

Issue 1658253002: Serialize constant instance creation of generic classes. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Remove the special case for unnamed constructors from _getElementReferenceId(). Created 4 years, 10 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) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 serialization.elements; 5 library serialization.elements;
6 6
7 import 'package:analyzer/dart/element/element.dart'; 7 import 'package:analyzer/dart/element/element.dart';
8 import 'package:analyzer/dart/element/type.dart'; 8 import 'package:analyzer/dart/element/type.dart';
9 import 'package:analyzer/src/dart/element/element.dart'; 9 import 'package:analyzer/src/dart/element/element.dart';
10 import 'package:analyzer/src/dart/element/type.dart'; 10 import 'package:analyzer/src/dart/element/type.dart';
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 if (typeParameter.bound != null) { 671 if (typeParameter.bound != null) {
672 b.bound = serializeTypeRef(typeParameter.bound, typeParameter); 672 b.bound = serializeTypeRef(typeParameter.bound, typeParameter);
673 } 673 }
674 return b; 674 return b;
675 } 675 }
676 676
677 /** 677 /**
678 * Serialize the given [type] into a [EntityRef]. If [slot] is provided, 678 * Serialize the given [type] into a [EntityRef]. If [slot] is provided,
679 * it should be included in the [EntityRef]. If [linked] is true, any 679 * it should be included in the [EntityRef]. If [linked] is true, any
680 * references that are created will be populated into [linkedReferences] but 680 * references that are created will be populated into [linkedReferences] but
681 * [not [unlinkedReferences]. 681 * not [unlinkedReferences].
682 * 682 *
683 * [context] is the element within which the [EntityRef] will be 683 * [context] is the element within which the [EntityRef] will be
684 * interpreted; this is used to serialize type parameters. 684 * interpreted; this is used to serialize type parameters.
685 */ 685 */
686 EntityRefBuilder serializeTypeRef(DartType type, Element context, 686 EntityRefBuilder serializeTypeRef(DartType type, Element context,
687 {bool linked: false, int slot}) { 687 {bool linked: false, int slot}) {
688 EntityRefBuilder b = new EntityRefBuilder(slot: slot); 688 EntityRefBuilder b = new EntityRefBuilder(slot: slot);
689 if (type is TypeParameterType) { 689 if (type is TypeParameterType) {
690 b.paramReference = findTypeParameterIndex(type, context); 690 b.paramReference = findTypeParameterIndex(type, context);
691 } else { 691 } else {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 int slot = ++numSlots; 823 int slot = ++numSlots;
824 if (type != null) { 824 if (type != null) {
825 deferredLinkedTypes 825 deferredLinkedTypes
826 .add(() => serializeTypeRef(type, context, linked: true, slot: slot)); 826 .add(() => serializeTypeRef(type, context, linked: true, slot: slot));
827 } 827 }
828 return slot; 828 return slot;
829 } 829 }
830 830
831 int _getElementReferenceId(Element element, {bool linked: false}) { 831 int _getElementReferenceId(Element element, {bool linked: false}) {
832 return referenceMap.putIfAbsent(element, () { 832 return referenceMap.putIfAbsent(element, () {
833 if (element is ConstructorElement && element.displayName.isEmpty) {
834 return _getElementReferenceId(element.enclosingElement, linked: linked);
835 }
836 LibraryElement dependentLibrary = element?.library; 833 LibraryElement dependentLibrary = element?.library;
837 int unit; 834 int unit;
838 if (dependentLibrary == null) { 835 if (dependentLibrary == null) {
839 assert(element == librarySerializer.typeProvider.dynamicType.element || 836 assert(element == librarySerializer.typeProvider.dynamicType.element ||
840 element == null); 837 element == null);
841 unit = 0; 838 unit = 0;
842 dependentLibrary = librarySerializer.libraryElement; 839 dependentLibrary = librarySerializer.libraryElement;
843 } else { 840 } else {
844 CompilationUnitElement unitElement = 841 CompilationUnitElement unitElement =
845 element.getAncestor((Element e) => e is CompilationUnitElement); 842 element.getAncestor((Element e) => e is CompilationUnitElement);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 * Instances of this class keep track of intermediate state during 901 * Instances of this class keep track of intermediate state during
905 * serialization of a single constant [Expression]. 902 * serialization of a single constant [Expression].
906 */ 903 */
907 class _ConstExprSerializer extends AbstractConstExprSerializer { 904 class _ConstExprSerializer extends AbstractConstExprSerializer {
908 final _CompilationUnitSerializer serializer; 905 final _CompilationUnitSerializer serializer;
909 906
910 _ConstExprSerializer(this.serializer); 907 _ConstExprSerializer(this.serializer);
911 908
912 @override 909 @override
913 EntityRefBuilder serializeConstructorName(ConstructorName constructor) { 910 EntityRefBuilder serializeConstructorName(ConstructorName constructor) {
914 ConstructorElement element = constructor.staticElement; 911 DartType type = constructor.type.type;
915 assert(element != null); 912 EntityRefBuilder typeRef = serializer.serializeTypeRef(type, null);
916 int referenceId = serializer._getElementReferenceId(element); 913 if (constructor.name == null) {
917 return new EntityRefBuilder(reference: referenceId); 914 return typeRef;
915 } else {
916 int typeId = typeRef.reference;
917 LinkedReference typeLinkedRef = serializer.linkedReferences[typeId];
918 serializer.unlinkedReferences.add(new UnlinkedReferenceBuilder(
919 name: constructor.name.name, prefixReference: typeId));
920 int refId = serializer.linkedReferences.length;
921 serializer.linkedReferences.add(new LinkedReferenceBuilder(
922 kind: ReferenceKind.constructor,
923 dependency: typeLinkedRef.dependency,
924 unit: typeLinkedRef.unit));
925 return new EntityRefBuilder(
926 reference: refId, typeArguments: typeRef.typeArguments);
927 }
918 } 928 }
919 929
920 EntityRefBuilder serializeIdentifier(Identifier identifier) { 930 EntityRefBuilder serializeIdentifier(Identifier identifier) {
921 Element element = identifier.staticElement; 931 Element element = identifier.staticElement;
922 assert(element != null); 932 assert(element != null);
923 // The only supported instance property accessor - `length`. 933 // The only supported instance property accessor - `length`.
924 if (identifier is PrefixedIdentifier && 934 if (identifier is PrefixedIdentifier &&
925 element is PropertyAccessorElement && 935 element is PropertyAccessorElement &&
926 !element.isStatic) { 936 !element.isStatic) {
927 assert(element.name == 'length'); 937 assert(element.name == 'length');
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1143 exportNames.add(new LinkedExportNameBuilder( 1153 exportNames.add(new LinkedExportNameBuilder(
1144 name: name, 1154 name: name,
1145 dependency: serializeDependency(dependentLibrary), 1155 dependency: serializeDependency(dependentLibrary),
1146 unit: unit, 1156 unit: unit,
1147 kind: kind)); 1157 kind: kind));
1148 } 1158 }
1149 pb.exportNames = exportNames; 1159 pb.exportNames = exportNames;
1150 return pb; 1160 return pb;
1151 } 1161 }
1152 } 1162 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_ast.dart ('k') | pkg/analyzer/test/src/summary/summary_common.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698