| OLD | NEW |
| 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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 * The number of slot ids which have been assigned to this compilation unit. | 282 * The number of slot ids which have been assigned to this compilation unit. |
| 283 */ | 283 */ |
| 284 int numSlots = 0; | 284 int numSlots = 0; |
| 285 | 285 |
| 286 /** | 286 /** |
| 287 * The [Block] that is being visited now, or `null` for non-local contexts. | 287 * The [Block] that is being visited now, or `null` for non-local contexts. |
| 288 */ | 288 */ |
| 289 Block enclosingBlock = null; | 289 Block enclosingBlock = null; |
| 290 | 290 |
| 291 /** | 291 /** |
| 292 * A flag indicating whether a variable declaration is in the context of a | |
| 293 * field declaration. | |
| 294 */ | |
| 295 bool inFieldContext = false; | |
| 296 | |
| 297 /** | |
| 298 * Create a slot id for storing a propagated or inferred type. | 292 * Create a slot id for storing a propagated or inferred type. |
| 299 */ | 293 */ |
| 300 int assignTypeSlot() => ++numSlots; | 294 int assignTypeSlot() => ++numSlots; |
| 301 | 295 |
| 302 /** | 296 /** |
| 303 * Build a [_Scope] object containing the names defined within the body of a | 297 * Build a [_Scope] object containing the names defined within the body of a |
| 304 * class declaration. | 298 * class declaration. |
| 305 */ | 299 */ |
| 306 _Scope buildClassMemberScope( | 300 _Scope buildClassMemberScope( |
| 307 String className, NodeList<ClassMember> members) { | 301 String className, NodeList<ClassMember> members) { |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 735 for (VariableDeclaration variable in variables.variables) { | 729 for (VariableDeclaration variable in variables.variables) { |
| 736 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); | 730 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); |
| 737 b.isFinal = variables.isFinal; | 731 b.isFinal = variables.isFinal; |
| 738 b.isConst = variables.isConst; | 732 b.isConst = variables.isConst; |
| 739 b.isStatic = isDeclaredStatic; | 733 b.isStatic = isDeclaredStatic; |
| 740 b.name = variable.name.name; | 734 b.name = variable.name.name; |
| 741 b.nameOffset = variable.name.offset; | 735 b.nameOffset = variable.name.offset; |
| 742 b.type = serializeTypeName(variables.type); | 736 b.type = serializeTypeName(variables.type); |
| 743 b.documentationComment = serializeDocumentation(documentationComment); | 737 b.documentationComment = serializeDocumentation(documentationComment); |
| 744 b.annotations = serializeAnnotations(annotations); | 738 b.annotations = serializeAnnotations(annotations); |
| 745 if (variable.isConst || variable.isFinal && inFieldContext) { | 739 if (variable.isConst || |
| 740 variable.isFinal && isField && !isDeclaredStatic) { |
| 746 Expression initializer = variable.initializer; | 741 Expression initializer = variable.initializer; |
| 747 if (initializer != null) { | 742 if (initializer != null) { |
| 748 b.constExpr = serializeConstExpr(initializer); | 743 b.constExpr = serializeConstExpr(initializer); |
| 749 } | 744 } |
| 750 } | 745 } |
| 751 if (variable.initializer != null && | 746 if (variable.initializer != null && |
| 752 (variables.isFinal || variables.isConst)) { | 747 (variables.isFinal || variables.isConst)) { |
| 753 b.propagatedTypeSlot = assignTypeSlot(); | 748 b.propagatedTypeSlot = assignTypeSlot(); |
| 754 } | 749 } |
| 755 bool isSemanticallyStatic = !isField || isDeclaredStatic; | 750 bool isSemanticallyStatic = !isField || isDeclaredStatic; |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 @override | 877 @override |
| 883 void visitExportDirective(ExportDirective node) { | 878 void visitExportDirective(ExportDirective node) { |
| 884 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder( | 879 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder( |
| 885 uriOffset: node.uri.offset, uriEnd: node.uri.end, offset: node.offset); | 880 uriOffset: node.uri.offset, uriEnd: node.uri.end, offset: node.offset); |
| 886 b.annotations = serializeAnnotations(node.metadata); | 881 b.annotations = serializeAnnotations(node.metadata); |
| 887 exports.add(b); | 882 exports.add(b); |
| 888 } | 883 } |
| 889 | 884 |
| 890 @override | 885 @override |
| 891 void visitFieldDeclaration(FieldDeclaration node) { | 886 void visitFieldDeclaration(FieldDeclaration node) { |
| 892 try { | 887 serializeVariables(node.fields, node.staticKeyword != null, |
| 893 inFieldContext = true; | 888 node.documentationComment, node.metadata, true); |
| 894 serializeVariables(node.fields, node.staticKeyword != null, | |
| 895 node.documentationComment, node.metadata, true); | |
| 896 } finally { | |
| 897 inFieldContext = false; | |
| 898 } | |
| 899 } | 889 } |
| 900 | 890 |
| 901 @override | 891 @override |
| 902 UnlinkedParamBuilder visitFieldFormalParameter(FieldFormalParameter node) { | 892 UnlinkedParamBuilder visitFieldFormalParameter(FieldFormalParameter node) { |
| 903 UnlinkedParamBuilder b = serializeParameter(node); | 893 UnlinkedParamBuilder b = serializeParameter(node); |
| 904 b.isInitializingFormal = true; | 894 b.isInitializingFormal = true; |
| 905 if (node.type != null || node.parameters != null) { | 895 if (node.type != null || node.parameters != null) { |
| 906 b.isFunctionTyped = node.parameters != null; | 896 b.isFunctionTyped = node.parameters != null; |
| 907 if (node.parameters != null) { | 897 if (node.parameters != null) { |
| 908 serializeFunctionTypedParameterDetails(b, node.type, node.parameters); | 898 serializeFunctionTypedParameterDetails(b, node.type, node.parameters); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 /** | 1054 /** |
| 1065 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. | 1055 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. |
| 1066 */ | 1056 */ |
| 1067 class _TypeParameterScope extends _Scope { | 1057 class _TypeParameterScope extends _Scope { |
| 1068 /** | 1058 /** |
| 1069 * Get the number of [_ScopedTypeParameter]s defined in this | 1059 * Get the number of [_ScopedTypeParameter]s defined in this |
| 1070 * [_TypeParameterScope]. | 1060 * [_TypeParameterScope]. |
| 1071 */ | 1061 */ |
| 1072 int get length => _definedNames.length; | 1062 int get length => _definedNames.length; |
| 1073 } | 1063 } |
| OLD | NEW |