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

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

Issue 1841603003: Serialize references to type parameters in final fields. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 'dart:convert'; 7 import 'dart:convert';
8 8
9 import 'package:analyzer/dart/ast/ast.dart'; 9 import 'package:analyzer/dart/ast/ast.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 498
499 /** 499 /**
500 * Serialize annotations from the given [element]. If [element] has no 500 * Serialize annotations from the given [element]. If [element] has no
501 * annotations, the empty list is returned. 501 * annotations, the empty list is returned.
502 */ 502 */
503 List<UnlinkedConstBuilder> serializeAnnotations(Element element) { 503 List<UnlinkedConstBuilder> serializeAnnotations(Element element) {
504 if (element.metadata.isEmpty) { 504 if (element.metadata.isEmpty) {
505 return const <UnlinkedConstBuilder>[]; 505 return const <UnlinkedConstBuilder>[];
506 } 506 }
507 return element.metadata.map((ElementAnnotationImpl a) { 507 return element.metadata.map((ElementAnnotationImpl a) {
508 _ConstExprSerializer serializer = new _ConstExprSerializer(this, null); 508 _ConstExprSerializer serializer =
509 new _ConstExprSerializer(this, element, null);
509 serializer.serializeAnnotation(a.annotationAst); 510 serializer.serializeAnnotation(a.annotationAst);
510 return serializer.toBuilder(); 511 return serializer.toBuilder();
511 }).toList(); 512 }).toList();
512 } 513 }
513 514
514 /** 515 /**
515 * Return the index of the entry in the references table 516 * Return the index of the entry in the references table
516 * ([LinkedLibrary.references]) used for the "bottom" type. A new entry is 517 * ([LinkedLibrary.references]) used for the "bottom" type. A new entry is
517 * added to the table if necessary to satisfy the request. 518 * added to the table if necessary to satisfy the request.
518 */ 519 */
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
644 b.end = combinator.end; 645 b.end = combinator.end;
645 } else if (combinator is HideElementCombinator) { 646 } else if (combinator is HideElementCombinator) {
646 b.hides = combinator.hiddenNames; 647 b.hides = combinator.hiddenNames;
647 } 648 }
648 return b; 649 return b;
649 } 650 }
650 651
651 /** 652 /**
652 * Serialize the given [expression], creating an [UnlinkedConstBuilder]. 653 * Serialize the given [expression], creating an [UnlinkedConstBuilder].
653 */ 654 */
654 UnlinkedConstBuilder serializeConstExpr(Expression expression, 655 UnlinkedConstBuilder serializeConstExpr(
656 Element context, Expression expression,
655 [Set<String> constructorParameterNames]) { 657 [Set<String> constructorParameterNames]) {
656 _ConstExprSerializer serializer = 658 _ConstExprSerializer serializer =
657 new _ConstExprSerializer(this, constructorParameterNames); 659 new _ConstExprSerializer(this, context, constructorParameterNames);
658 serializer.serialize(expression); 660 serializer.serialize(expression);
659 return serializer.toBuilder(); 661 return serializer.toBuilder();
660 } 662 }
661 663
662 /** 664 /**
663 * Serialize documentation from the given [element], creating an 665 * Serialize documentation from the given [element], creating an
664 * [UnlinkedDocumentationComment]. 666 * [UnlinkedDocumentationComment].
665 * 667 *
666 * If [element] has no documentation, `null` is returned. 668 * If [element] has no documentation, `null` is returned.
667 */ 669 */
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 } 764 }
763 if (executableElement.isConst) { 765 if (executableElement.isConst) {
764 b.constCycleSlot = storeConstCycle(!executableElement.isCycleFree); 766 b.constCycleSlot = storeConstCycle(!executableElement.isCycleFree);
765 if (executableElement.constantInitializers != null) { 767 if (executableElement.constantInitializers != null) {
766 Set<String> constructorParameterNames = 768 Set<String> constructorParameterNames =
767 executableElement.parameters.map((p) => p.name).toSet(); 769 executableElement.parameters.map((p) => p.name).toSet();
768 b.constantInitializers = executableElement.constantInitializers 770 b.constantInitializers = executableElement.constantInitializers
769 .map((ConstructorInitializer initializer) => 771 .map((ConstructorInitializer initializer) =>
770 serializeConstructorInitializer( 772 serializeConstructorInitializer(
771 initializer, 773 initializer,
772 (expr) => 774 (expr) => serializeConstExpr(
773 serializeConstExpr(expr, constructorParameterNames))) 775 executableElement, expr, constructorParameterNames)))
774 .toList(); 776 .toList();
775 } 777 }
776 } 778 }
777 } else { 779 } else {
778 b.kind = UnlinkedExecutableKind.functionOrMethod; 780 b.kind = UnlinkedExecutableKind.functionOrMethod;
779 } 781 }
780 b.isAbstract = executableElement.isAbstract; 782 b.isAbstract = executableElement.isAbstract;
781 b.isStatic = executableElement.isStatic && 783 b.isStatic = executableElement.isStatic &&
782 executableElement.enclosingElement is ClassElement; 784 executableElement.enclosingElement is ClassElement;
783 b.isExternal = executableElement.isExternal; 785 b.isExternal = executableElement.isExternal;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
899 .map((parameter) => serializeParam(parameter, context)) 901 .map((parameter) => serializeParam(parameter, context))
900 .toList(); 902 .toList();
901 } else { 903 } else {
902 b.type = serializeTypeRef(type, context); 904 b.type = serializeTypeRef(type, context);
903 } 905 }
904 } 906 }
905 if (parameter is ConstVariableElement) { 907 if (parameter is ConstVariableElement) {
906 ConstVariableElement constParameter = parameter as ConstVariableElement; 908 ConstVariableElement constParameter = parameter as ConstVariableElement;
907 Expression initializer = constParameter.constantInitializer; 909 Expression initializer = constParameter.constantInitializer;
908 if (initializer != null) { 910 if (initializer != null) {
909 b.defaultValue = serializeConstExpr(initializer); 911 b.defaultValue = serializeConstExpr(parameter, initializer);
910 b.defaultValueCode = parameter.defaultValueCode; 912 b.defaultValueCode = parameter.defaultValueCode;
911 } 913 }
912 } 914 }
913 // TODO(scheglov) VariableMember.initializer is not implemented 915 // TODO(scheglov) VariableMember.initializer is not implemented
914 if (parameter is! VariableMember && parameter.initializer != null) { 916 if (parameter is! VariableMember && parameter.initializer != null) {
915 b.initializer = serializeExecutable(parameter.initializer); 917 b.initializer = serializeExecutable(parameter.initializer);
916 } 918 }
917 { 919 {
918 SourceRange visibleRange = parameter.visibleRange; 920 SourceRange visibleRange = parameter.visibleRange;
919 if (visibleRange != null) { 921 if (visibleRange != null) {
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1113 } 1115 }
1114 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement; 1116 b.isStatic = variable.isStatic && variable.enclosingElement is ClassElement;
1115 b.isFinal = variable.isFinal; 1117 b.isFinal = variable.isFinal;
1116 b.isConst = variable.isConst; 1118 b.isConst = variable.isConst;
1117 b.documentationComment = serializeDocumentation(variable); 1119 b.documentationComment = serializeDocumentation(variable);
1118 b.annotations = serializeAnnotations(variable); 1120 b.annotations = serializeAnnotations(variable);
1119 if (variable is ConstVariableElement) { 1121 if (variable is ConstVariableElement) {
1120 ConstVariableElement constVariable = variable as ConstVariableElement; 1122 ConstVariableElement constVariable = variable as ConstVariableElement;
1121 Expression initializer = constVariable.constantInitializer; 1123 Expression initializer = constVariable.constantInitializer;
1122 if (initializer != null) { 1124 if (initializer != null) {
1123 b.constExpr = serializeConstExpr(initializer); 1125 b.constExpr = serializeConstExpr(variable, initializer);
1124 } 1126 }
1125 } 1127 }
1126 if (variable is PropertyInducingElement) { 1128 if (variable is PropertyInducingElement) {
1127 if (b.isFinal || b.isConst) { 1129 if (b.isFinal || b.isConst) {
1128 b.propagatedTypeSlot = 1130 b.propagatedTypeSlot =
1129 storeLinkedType(variable.propagatedType, variable); 1131 storeLinkedType(variable.propagatedType, variable);
1130 } else { 1132 } else {
1131 // Variable is not propagable. 1133 // Variable is not propagable.
1132 assert(variable.propagatedType == null); 1134 assert(variable.propagatedType == null);
1133 } 1135 }
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
1277 prefixReference: prefix); 1279 prefixReference: prefix);
1278 } 1280 }
1279 } 1281 }
1280 1282
1281 /** 1283 /**
1282 * Instances of this class keep track of intermediate state during 1284 * Instances of this class keep track of intermediate state during
1283 * serialization of a single constant [Expression]. 1285 * serialization of a single constant [Expression].
1284 */ 1286 */
1285 class _ConstExprSerializer extends AbstractConstExprSerializer { 1287 class _ConstExprSerializer extends AbstractConstExprSerializer {
1286 final _CompilationUnitSerializer serializer; 1288 final _CompilationUnitSerializer serializer;
1289 final Element context;
1287 1290
1288 /** 1291 /**
1289 * If a constructor initializer expression is being serialized, the names of 1292 * If a constructor initializer expression is being serialized, the names of
1290 * the constructor parameters. Otherwise `null`. 1293 * the constructor parameters. Otherwise `null`.
1291 */ 1294 */
1292 final Set<String> constructorParameterNames; 1295 final Set<String> constructorParameterNames;
1293 1296
1294 _ConstExprSerializer(this.serializer, this.constructorParameterNames); 1297 _ConstExprSerializer(
1298 this.serializer, this.context, this.constructorParameterNames);
1295 1299
1296 @override 1300 @override
1297 bool isConstructorParameterName(String name) { 1301 bool isConstructorParameterName(String name) {
1298 return constructorParameterNames?.contains(name) ?? false; 1302 return constructorParameterNames?.contains(name) ?? false;
1299 } 1303 }
1300 1304
1301 @override 1305 @override
1302 void serializeAnnotation(Annotation annotation) { 1306 void serializeAnnotation(Annotation annotation) {
1303 if (annotation.arguments == null) { 1307 if (annotation.arguments == null) {
1304 assert(annotation.constructorName == null); 1308 assert(annotation.constructorName == null);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 1419
1416 @override 1420 @override
1417 EntityRefBuilder serializeType(TypeName typeName) { 1421 EntityRefBuilder serializeType(TypeName typeName) {
1418 if (typeName != null) { 1422 if (typeName != null) {
1419 DartType type = typeName.type; 1423 DartType type = typeName.type;
1420 if (type == null || type.isUndefined) { 1424 if (type == null || type.isUndefined) {
1421 return serializeIdentifier(typeName.name); 1425 return serializeIdentifier(typeName.name);
1422 } 1426 }
1423 } 1427 }
1424 DartType type = typeName != null ? typeName.type : DynamicTypeImpl.instance; 1428 DartType type = typeName != null ? typeName.type : DynamicTypeImpl.instance;
1425 return serializer.serializeTypeRef(type, null); 1429 return serializer.serializeTypeRef(type, context);
1426 } 1430 }
1427 } 1431 }
1428 1432
1429 /** 1433 /**
1430 * Instances of this class keep track of intermediate state during 1434 * Instances of this class keep track of intermediate state during
1431 * serialization of a single library. 1435 * serialization of a single library.
1432 */ 1436 */
1433 class _LibrarySerializer { 1437 class _LibrarySerializer {
1434 /** 1438 /**
1435 * The library to be serialized. 1439 * The library to be serialized.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 exportNames.add(new LinkedExportNameBuilder( 1620 exportNames.add(new LinkedExportNameBuilder(
1617 name: name, 1621 name: name,
1618 dependency: serializeDependency(dependentLibrary), 1622 dependency: serializeDependency(dependentLibrary),
1619 unit: unit, 1623 unit: unit,
1620 kind: kind)); 1624 kind: kind));
1621 } 1625 }
1622 pb.exportNames = exportNames; 1626 pb.exportNames = exportNames;
1623 return pb; 1627 return pb;
1624 } 1628 }
1625 } 1629 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/summary/resynthesize_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698