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

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

Issue 1679493002: Serialize initializers for final fields. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: 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
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/summarize_elements.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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.summarize_ast; 5 library serialization.summarize_ast;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/visitor.dart'; 8 import 'package:analyzer/dart/ast/visitor.dart';
9 import 'package:analyzer/src/generated/scanner.dart'; 9 import 'package:analyzer/src/generated/scanner.dart';
10 import 'package:analyzer/src/generated/utilities_dart.dart'; 10 import 'package:analyzer/src/generated/utilities_dart.dart';
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 * (if any). Otherwise `null`. 240 * (if any). Otherwise `null`.
241 */ 241 */
242 UnlinkedDocumentationCommentBuilder libraryDocumentationComment; 242 UnlinkedDocumentationCommentBuilder libraryDocumentationComment;
243 243
244 /** 244 /**
245 * The number of slot ids which have been assigned to this compilation unit. 245 * The number of slot ids which have been assigned to this compilation unit.
246 */ 246 */
247 int numSlots = 0; 247 int numSlots = 0;
248 248
249 /** 249 /**
250 * A flag indicating whether a variable declaration is in the context of a
251 * field declaration.
252 */
253 bool inFieldContext = false;
254
255 /**
250 * Create a slot id for storing a propagated or inferred type. 256 * Create a slot id for storing a propagated or inferred type.
251 */ 257 */
252 int assignTypeSlot() => ++numSlots; 258 int assignTypeSlot() => ++numSlots;
253 259
254 /** 260 /**
255 * Build a [_Scope] object containing the names defined within the body of a 261 * Build a [_Scope] object containing the names defined within the body of a
256 * class declaration. 262 * class declaration.
257 */ 263 */
258 _Scope buildClassMemberScope(NodeList<ClassMember> members) { 264 _Scope buildClassMemberScope(NodeList<ClassMember> members) {
259 _Scope scope = new _Scope(); 265 _Scope scope = new _Scope();
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 bool isDeclaredStatic, Comment documentationComment, bool isField) { 620 bool isDeclaredStatic, Comment documentationComment, bool isField) {
615 for (VariableDeclaration variable in variables.variables) { 621 for (VariableDeclaration variable in variables.variables) {
616 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); 622 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder();
617 b.isFinal = variables.isFinal; 623 b.isFinal = variables.isFinal;
618 b.isConst = variables.isConst; 624 b.isConst = variables.isConst;
619 b.isStatic = isDeclaredStatic; 625 b.isStatic = isDeclaredStatic;
620 b.name = variable.name.name; 626 b.name = variable.name.name;
621 b.nameOffset = variable.name.offset; 627 b.nameOffset = variable.name.offset;
622 b.type = serializeTypeName(variables.type); 628 b.type = serializeTypeName(variables.type);
623 b.documentationComment = serializeDocumentation(documentationComment); 629 b.documentationComment = serializeDocumentation(documentationComment);
624 if (variable.isConst) { 630 if (variable.isConst || variable.isFinal && inFieldContext) {
625 Expression initializer = variable.initializer; 631 Expression initializer = variable.initializer;
626 if (initializer != null) { 632 if (initializer != null) {
627 b.constExpr = serializeConstExpr(initializer); 633 b.constExpr = serializeConstExpr(initializer);
628 } 634 }
629 } 635 }
630 if (variable.initializer != null && 636 if (variable.initializer != null &&
631 (variables.isFinal || variables.isConst)) { 637 (variables.isFinal || variables.isConst)) {
632 b.propagatedTypeSlot = assignTypeSlot(); 638 b.propagatedTypeSlot = assignTypeSlot();
633 } 639 }
634 bool isSemanticallyStatic = !isField || isDeclaredStatic; 640 bool isSemanticallyStatic = !isField || isDeclaredStatic;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 723
718 @override 724 @override
719 void visitExportDirective(ExportDirective node) { 725 void visitExportDirective(ExportDirective node) {
720 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder( 726 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder(
721 uriOffset: node.uri.offset, uriEnd: node.uri.end, offset: node.offset); 727 uriOffset: node.uri.offset, uriEnd: node.uri.end, offset: node.offset);
722 exports.add(b); 728 exports.add(b);
723 } 729 }
724 730
725 @override 731 @override
726 void visitFieldDeclaration(FieldDeclaration node) { 732 void visitFieldDeclaration(FieldDeclaration node) {
727 serializeVariables(node.fields, node.staticKeyword != null, 733 try {
728 node.documentationComment, true); 734 inFieldContext = true;
735 serializeVariables(node.fields, node.staticKeyword != null,
736 node.documentationComment, true);
737 } finally {
738 inFieldContext = false;
739 }
729 } 740 }
730 741
731 @override 742 @override
732 UnlinkedParamBuilder visitFieldFormalParameter(FieldFormalParameter node) { 743 UnlinkedParamBuilder visitFieldFormalParameter(FieldFormalParameter node) {
733 UnlinkedParamBuilder b = serializeParameter(node); 744 UnlinkedParamBuilder b = serializeParameter(node);
734 b.isInitializingFormal = true; 745 b.isInitializingFormal = true;
735 if (node.type != null || node.parameters != null) { 746 if (node.type != null || node.parameters != null) {
736 b.isFunctionTyped = node.parameters != null; 747 b.isFunctionTyped = node.parameters != null;
737 if (node.parameters != null) { 748 if (node.parameters != null) {
738 serializeFunctionTypedParameterDetails(b, node.type, node.parameters); 749 serializeFunctionTypedParameterDetails(b, node.type, node.parameters);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
880 /** 891 /**
881 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. 892 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s.
882 */ 893 */
883 class _TypeParameterScope extends _Scope { 894 class _TypeParameterScope extends _Scope {
884 /** 895 /**
885 * Get the number of [_ScopedTypeParameter]s defined in this 896 * Get the number of [_ScopedTypeParameter]s defined in this
886 * [_TypeParameterScope]. 897 * [_TypeParameterScope].
887 */ 898 */
888 int get length => _definedNames.length; 899 int get length => _definedNames.length;
889 } 900 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698