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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/lib/src/summary/summarize_elements.dart
diff --git a/pkg/analyzer/lib/src/summary/summarize_elements.dart b/pkg/analyzer/lib/src/summary/summarize_elements.dart
index 7de478b0dd6ee7edba158fdaa75b09ecfbd22efc..786563b6133799ebac45dee42d9b1b4d1b44978f 100644
--- a/pkg/analyzer/lib/src/summary/summarize_elements.dart
+++ b/pkg/analyzer/lib/src/summary/summarize_elements.dart
@@ -29,16 +29,18 @@ LibrarySerializationResult serializeLibrary(
ReferenceKind _getReferenceKind(Element element) {
ReferenceKind kind;
- if (element is PropertyAccessorElement) {
- kind = ReferenceKind.topLevelPropertyAccessor;
- } else if (element is FunctionTypeAliasElement) {
- kind = ReferenceKind.typedef;
- } else if (element == null ||
+ if (element == null ||
element is ClassElement ||
element is DynamicElementImpl) {
kind = ReferenceKind.classOrEnum;
+ } else if (element is ConstructorElement) {
+ kind = ReferenceKind.constructor;
} else if (element is FunctionElement) {
kind = ReferenceKind.topLevelFunction;
+ } else if (element is FunctionTypeAliasElement) {
+ kind = ReferenceKind.typedef;
+ } else if (element is PropertyAccessorElement) {
+ kind = ReferenceKind.topLevelPropertyAccessor;
} else {
throw new Exception('Unexpected element kind: ${element.runtimeType}');
}
@@ -812,15 +814,20 @@ class _CompilationUnitSerializer {
linkedReference.name = name;
} else {
assert(unlinkedReferences.length == linkedReferences.length);
- // Figure out a prefix that may be used to refer to the given type.
- // TODO(paulberry): to avoid subtle relinking inconsistencies we
- // should use the actual prefix from the AST (a given type may be
- // reachable via multiple prefixes), but sadly, this information is
- // not recorded in the element model.
int prefixReference = 0;
- PrefixElement prefix = librarySerializer.prefixMap[element];
- if (prefix != null) {
- prefixReference = serializePrefix(prefix);
+ Element enclosing = element?.enclosingElement;
+ if (enclosing == null || enclosing is CompilationUnitElement) {
+ // Figure out a prefix that may be used to refer to the given element.
+ // TODO(paulberry): to avoid subtle relinking inconsistencies we
+ // should use the actual prefix from the AST (a given type may be
+ // reachable via multiple prefixes), but sadly, this information is
+ // not recorded in the element model.
+ PrefixElement prefix = librarySerializer.prefixMap[element];
+ if (prefix != null) {
+ prefixReference = serializePrefix(prefix);
+ }
+ } else {
+ prefixReference = _getElementReferenceId(enclosing, linked: linked);
}
unlinkedReferences.add(new UnlinkedReferenceBuilder(
name: name, prefixReference: prefixReference));
@@ -841,6 +848,14 @@ class _ConstExprSerializer extends AbstractConstExprSerializer {
_ConstExprSerializer(this.serializer);
+ @override
+ EntityRefBuilder serializeConstructorName(ConstructorName constructor) {
+ ConstructorElement element = constructor.staticElement;
+ assert(element != null);
+ int referenceId = serializer._getElementReferenceId(element);
+ return new EntityRefBuilder(reference: referenceId);
+ }
+
EntityRefBuilder serializeIdentifier(Identifier identifier) {
Element element = identifier.staticElement;
assert(element != null);

Powered by Google App Engine
This is Rietveld 408576698