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

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

Issue 1633863002: Support for constructor references in constant serializer and prelinker. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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) 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 11 matching lines...) Expand all
22 LibrarySerializationResult serializeLibrary( 22 LibrarySerializationResult serializeLibrary(
23 LibraryElement lib, TypeProvider typeProvider, bool strongMode) { 23 LibraryElement lib, TypeProvider typeProvider, bool strongMode) {
24 var serializer = new _LibrarySerializer(lib, typeProvider, strongMode); 24 var serializer = new _LibrarySerializer(lib, typeProvider, strongMode);
25 LinkedLibraryBuilder linked = serializer.serializeLibrary(); 25 LinkedLibraryBuilder linked = serializer.serializeLibrary();
26 return new LibrarySerializationResult( 26 return new LibrarySerializationResult(
27 linked, serializer.unlinkedUnits, serializer.unitUris); 27 linked, serializer.unlinkedUnits, serializer.unitUris);
28 } 28 }
29 29
30 ReferenceKind _getReferenceKind(Element element) { 30 ReferenceKind _getReferenceKind(Element element) {
31 ReferenceKind kind; 31 ReferenceKind kind;
32 if (element is PropertyAccessorElement) { 32 if (element == null ||
33 kind = ReferenceKind.topLevelPropertyAccessor;
34 } else if (element is FunctionTypeAliasElement) {
35 kind = ReferenceKind.typedef;
36 } else if (element == null ||
37 element is ClassElement || 33 element is ClassElement ||
38 element is DynamicElementImpl) { 34 element is DynamicElementImpl) {
39 kind = ReferenceKind.classOrEnum; 35 kind = ReferenceKind.classOrEnum;
36 } else if (element is ConstructorElement) {
37 kind = ReferenceKind.constructor;
40 } else if (element is FunctionElement) { 38 } else if (element is FunctionElement) {
41 kind = ReferenceKind.topLevelFunction; 39 kind = ReferenceKind.topLevelFunction;
40 } else if (element is FunctionTypeAliasElement) {
41 kind = ReferenceKind.typedef;
42 } else if (element is PropertyAccessorElement) {
43 kind = ReferenceKind.topLevelPropertyAccessor;
42 } else { 44 } else {
43 throw new Exception('Unexpected element kind: ${element.runtimeType}'); 45 throw new Exception('Unexpected element kind: ${element.runtimeType}');
44 } 46 }
45 return kind; 47 return kind;
46 } 48 }
47 49
48 /** 50 /**
49 * Type of closures used by [_LibrarySerializer] to defer generation of 51 * Type of closures used by [_LibrarySerializer] to defer generation of
50 * [EntityRefBuilder] objects until the end of serialization of a 52 * [EntityRefBuilder] objects until the end of serialization of a
51 * compilation unit. 53 * compilation unit.
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 LinkedReferenceBuilder linkedReference = new LinkedReferenceBuilder( 807 LinkedReferenceBuilder linkedReference = new LinkedReferenceBuilder(
806 dependency: librarySerializer.serializeDependency(dependentLibrary), 808 dependency: librarySerializer.serializeDependency(dependentLibrary),
807 kind: _getReferenceKind(element), 809 kind: _getReferenceKind(element),
808 unit: unit, 810 unit: unit,
809 numTypeParameters: numTypeParameters); 811 numTypeParameters: numTypeParameters);
810 String name = element == null ? 'void' : element.name; 812 String name = element == null ? 'void' : element.name;
811 if (linked) { 813 if (linked) {
812 linkedReference.name = name; 814 linkedReference.name = name;
813 } else { 815 } else {
814 assert(unlinkedReferences.length == linkedReferences.length); 816 assert(unlinkedReferences.length == linkedReferences.length);
815 // Figure out a prefix that may be used to refer to the given type.
816 // TODO(paulberry): to avoid subtle relinking inconsistencies we
817 // should use the actual prefix from the AST (a given type may be
818 // reachable via multiple prefixes), but sadly, this information is
819 // not recorded in the element model.
820 int prefixReference = 0; 817 int prefixReference = 0;
821 PrefixElement prefix = librarySerializer.prefixMap[element]; 818 Element enclosing = element?.enclosingElement;
822 if (prefix != null) { 819 if (enclosing == null || enclosing is CompilationUnitElement) {
823 prefixReference = serializePrefix(prefix); 820 // Figure out a prefix that may be used to refer to the given element.
821 // TODO(paulberry): to avoid subtle relinking inconsistencies we
822 // should use the actual prefix from the AST (a given type may be
823 // reachable via multiple prefixes), but sadly, this information is
824 // not recorded in the element model.
825 PrefixElement prefix = librarySerializer.prefixMap[element];
826 if (prefix != null) {
827 prefixReference = serializePrefix(prefix);
828 }
829 } else {
830 prefixReference = _getElementReferenceId(enclosing, linked: linked);
824 } 831 }
825 unlinkedReferences.add(new UnlinkedReferenceBuilder( 832 unlinkedReferences.add(new UnlinkedReferenceBuilder(
826 name: name, prefixReference: prefixReference)); 833 name: name, prefixReference: prefixReference));
827 } 834 }
828 int index = linkedReferences.length; 835 int index = linkedReferences.length;
829 linkedReferences.add(linkedReference); 836 linkedReferences.add(linkedReference);
830 return index; 837 return index;
831 }); 838 });
832 } 839 }
833 } 840 }
834 841
835 /** 842 /**
836 * Instances of this class keep track of intermediate state during 843 * Instances of this class keep track of intermediate state during
837 * serialization of a single constant [Expression]. 844 * serialization of a single constant [Expression].
838 */ 845 */
839 class _ConstExprSerializer extends AbstractConstExprSerializer { 846 class _ConstExprSerializer extends AbstractConstExprSerializer {
840 final _CompilationUnitSerializer serializer; 847 final _CompilationUnitSerializer serializer;
841 848
842 _ConstExprSerializer(this.serializer); 849 _ConstExprSerializer(this.serializer);
843 850
851 @override
852 EntityRefBuilder serializeConstructorName(ConstructorName constructor) {
853 ConstructorElement element = constructor.staticElement;
854 assert(element != null);
855 int referenceId = serializer._getElementReferenceId(element);
856 return new EntityRefBuilder(reference: referenceId);
857 }
858
844 EntityRefBuilder serializeIdentifier(Identifier identifier) { 859 EntityRefBuilder serializeIdentifier(Identifier identifier) {
845 Element element = identifier.staticElement; 860 Element element = identifier.staticElement;
846 assert(element != null); 861 assert(element != null);
847 // TODO(scheglov) how to serialize element references? 862 // TODO(scheglov) how to serialize element references?
848 return new EntityRefBuilder( 863 return new EntityRefBuilder(
849 reference: serializer._getElementReferenceId(element)); 864 reference: serializer._getElementReferenceId(element));
850 } 865 }
851 866
852 @override 867 @override
853 EntityRefBuilder serializeType(TypeName typeName) { 868 EntityRefBuilder serializeType(TypeName typeName) {
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 exportNames.add(new LinkedExportNameBuilder( 1054 exportNames.add(new LinkedExportNameBuilder(
1040 name: name, 1055 name: name,
1041 dependency: serializeDependency(dependentLibrary), 1056 dependency: serializeDependency(dependentLibrary),
1042 unit: unit, 1057 unit: unit,
1043 kind: kind)); 1058 kind: kind));
1044 } 1059 }
1045 pb.exportNames = exportNames; 1060 pb.exportNames = exportNames;
1046 return pb; 1061 return pb;
1047 } 1062 }
1048 } 1063 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698