| 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/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/src/generated/utilities_dart.dart'; | 10 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 * The number of slot ids which have been assigned to this compilation unit. | 289 * The number of slot ids which have been assigned to this compilation unit. |
| 290 */ | 290 */ |
| 291 int numSlots = 0; | 291 int numSlots = 0; |
| 292 | 292 |
| 293 /** | 293 /** |
| 294 * The [Block] that is being visited now, or `null` for non-local contexts. | 294 * The [Block] that is being visited now, or `null` for non-local contexts. |
| 295 */ | 295 */ |
| 296 Block enclosingBlock = null; | 296 Block enclosingBlock = null; |
| 297 | 297 |
| 298 /** | 298 /** |
| 299 * Create a slot id for storing a propagated or inferred type. | 299 * Create a slot id for storing a propagated or inferred type or const cycle |
| 300 * info. |
| 300 */ | 301 */ |
| 301 int assignTypeSlot() => ++numSlots; | 302 int assignSlot() => ++numSlots; |
| 302 | 303 |
| 303 /** | 304 /** |
| 304 * Build a [_Scope] object containing the names defined within the body of a | 305 * Build a [_Scope] object containing the names defined within the body of a |
| 305 * class declaration. | 306 * class declaration. |
| 306 */ | 307 */ |
| 307 _Scope buildClassMemberScope( | 308 _Scope buildClassMemberScope( |
| 308 String className, NodeList<ClassMember> members) { | 309 String className, NodeList<ClassMember> members) { |
| 309 _Scope scope = new _Scope(); | 310 _Scope scope = new _Scope(); |
| 310 for (ClassMember member in members) { | 311 for (ClassMember member in members) { |
| 311 if (member is MethodDeclaration) { | 312 if (member is MethodDeclaration) { |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 b.isExternal = isExternal; | 523 b.isExternal = isExternal; |
| 523 bool isSemanticallyStatic = isTopLevel || isDeclaredStatic; | 524 bool isSemanticallyStatic = isTopLevel || isDeclaredStatic; |
| 524 if (formalParameters != null) { | 525 if (formalParameters != null) { |
| 525 b.parameters = formalParameters.parameters | 526 b.parameters = formalParameters.parameters |
| 526 .map((FormalParameter p) => p.accept(this)) | 527 .map((FormalParameter p) => p.accept(this)) |
| 527 .toList(); | 528 .toList(); |
| 528 if (!isSemanticallyStatic) { | 529 if (!isSemanticallyStatic) { |
| 529 for (int i = 0; i < formalParameters.parameters.length; i++) { | 530 for (int i = 0; i < formalParameters.parameters.length; i++) { |
| 530 if (!b.parameters[i].isFunctionTyped && | 531 if (!b.parameters[i].isFunctionTyped && |
| 531 b.parameters[i].type == null) { | 532 b.parameters[i].type == null) { |
| 532 b.parameters[i].inferredTypeSlot = assignTypeSlot(); | 533 b.parameters[i].inferredTypeSlot = assignSlot(); |
| 533 } | 534 } |
| 534 } | 535 } |
| 535 } | 536 } |
| 536 } | 537 } |
| 537 b.documentationComment = serializeDocumentation(documentationComment); | 538 b.documentationComment = serializeDocumentation(documentationComment); |
| 538 b.annotations = serializeAnnotations(annotations); | 539 b.annotations = serializeAnnotations(annotations); |
| 539 if (returnType == null && !isSemanticallyStatic) { | 540 if (returnType == null && !isSemanticallyStatic) { |
| 540 b.inferredReturnTypeSlot = assignTypeSlot(); | 541 b.inferredReturnTypeSlot = assignSlot(); |
| 541 } | 542 } |
| 542 b.visibleOffset = enclosingBlock?.offset; | 543 b.visibleOffset = enclosingBlock?.offset; |
| 543 b.visibleLength = enclosingBlock?.length; | 544 b.visibleLength = enclosingBlock?.length; |
| 544 serializeFunctionBody(b, body); | 545 serializeFunctionBody(b, body); |
| 545 scopes.removeLast(); | 546 scopes.removeLast(); |
| 546 assert(scopes.length == oldScopesLength); | 547 assert(scopes.length == oldScopesLength); |
| 547 return b; | 548 return b; |
| 548 } | 549 } |
| 549 | 550 |
| 550 /** | 551 /** |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 * [UnlinkedExecutableBuilder], otherwise return `null`. | 595 * [UnlinkedExecutableBuilder], otherwise return `null`. |
| 595 */ | 596 */ |
| 596 UnlinkedExecutableBuilder serializeInitializerFunction( | 597 UnlinkedExecutableBuilder serializeInitializerFunction( |
| 597 Expression expression) { | 598 Expression expression) { |
| 598 if (expression == null) { | 599 if (expression == null) { |
| 599 return null; | 600 return null; |
| 600 } | 601 } |
| 601 UnlinkedExecutableBuilder initializer = | 602 UnlinkedExecutableBuilder initializer = |
| 602 new UnlinkedExecutableBuilder(nameOffset: expression.offset); | 603 new UnlinkedExecutableBuilder(nameOffset: expression.offset); |
| 603 serializeFunctionBody(initializer, expression); | 604 serializeFunctionBody(initializer, expression); |
| 604 initializer.inferredReturnTypeSlot = assignTypeSlot(); | 605 initializer.inferredReturnTypeSlot = assignSlot(); |
| 605 return initializer; | 606 return initializer; |
| 606 } | 607 } |
| 607 | 608 |
| 608 /** | 609 /** |
| 609 * Serialize a [FieldFormalParameter], [FunctionTypedFormalParameter], or | 610 * Serialize a [FieldFormalParameter], [FunctionTypedFormalParameter], or |
| 610 * [SimpleFormalParameter] into an [UnlinkedParam]. | 611 * [SimpleFormalParameter] into an [UnlinkedParam]. |
| 611 */ | 612 */ |
| 612 UnlinkedParamBuilder serializeParameter(NormalFormalParameter node) { | 613 UnlinkedParamBuilder serializeParameter(NormalFormalParameter node) { |
| 613 UnlinkedParamBuilder b = new UnlinkedParamBuilder(); | 614 UnlinkedParamBuilder b = new UnlinkedParamBuilder(); |
| 614 b.name = node.identifier.name; | 615 b.name = node.identifier.name; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 b.annotations = serializeAnnotations(annotations); | 774 b.annotations = serializeAnnotations(annotations); |
| 774 if (variable.isConst || | 775 if (variable.isConst || |
| 775 variable.isFinal && isField && !isDeclaredStatic) { | 776 variable.isFinal && isField && !isDeclaredStatic) { |
| 776 Expression initializer = variable.initializer; | 777 Expression initializer = variable.initializer; |
| 777 if (initializer != null) { | 778 if (initializer != null) { |
| 778 b.constExpr = serializeConstExpr(initializer); | 779 b.constExpr = serializeConstExpr(initializer); |
| 779 } | 780 } |
| 780 } | 781 } |
| 781 if (variable.initializer != null && | 782 if (variable.initializer != null && |
| 782 (variables.isFinal || variables.isConst)) { | 783 (variables.isFinal || variables.isConst)) { |
| 783 b.propagatedTypeSlot = assignTypeSlot(); | 784 b.propagatedTypeSlot = assignSlot(); |
| 784 } | 785 } |
| 785 bool isSemanticallyStatic = !isField || isDeclaredStatic; | 786 bool isSemanticallyStatic = !isField || isDeclaredStatic; |
| 786 if (variables.type == null && | 787 if (variables.type == null && |
| 787 (variable.initializer != null || !isSemanticallyStatic)) { | 788 (variable.initializer != null || !isSemanticallyStatic)) { |
| 788 b.inferredTypeSlot = assignTypeSlot(); | 789 b.inferredTypeSlot = assignSlot(); |
| 789 } | 790 } |
| 790 b.visibleOffset = enclosingBlock?.offset; | 791 b.visibleOffset = enclosingBlock?.offset; |
| 791 b.visibleLength = enclosingBlock?.length; | 792 b.visibleLength = enclosingBlock?.length; |
| 792 b.initializer = serializeInitializerFunction(variable.initializer); | 793 b.initializer = serializeInitializerFunction(variable.initializer); |
| 793 this.variables.add(b); | 794 this.variables.add(b); |
| 794 } | 795 } |
| 795 } | 796 } |
| 796 | 797 |
| 797 @override | 798 @override |
| 798 void visitBlock(Block node) { | 799 void visitBlock(Block node) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 node.redirectedConstructor.name); | 861 node.redirectedConstructor.name); |
| 861 } | 862 } |
| 862 } else { | 863 } else { |
| 863 for (ConstructorInitializer initializer in node.initializers) { | 864 for (ConstructorInitializer initializer in node.initializers) { |
| 864 if (initializer is RedirectingConstructorInvocation) { | 865 if (initializer is RedirectingConstructorInvocation) { |
| 865 b.isRedirectedConstructor = true; | 866 b.isRedirectedConstructor = true; |
| 866 b.redirectedConstructorName = initializer.constructorName?.name; | 867 b.redirectedConstructorName = initializer.constructorName?.name; |
| 867 } | 868 } |
| 868 } | 869 } |
| 869 } | 870 } |
| 870 b.isConst = node.constKeyword != null; | 871 if (node.constKeyword != null) { |
| 872 b.isConst = true; |
| 873 b.constCycleSlot = assignSlot(); |
| 874 } |
| 871 b.isExternal = node.externalKeyword != null; | 875 b.isExternal = node.externalKeyword != null; |
| 872 b.documentationComment = serializeDocumentation(node.documentationComment); | 876 b.documentationComment = serializeDocumentation(node.documentationComment); |
| 873 b.annotations = serializeAnnotations(node.metadata); | 877 b.annotations = serializeAnnotations(node.metadata); |
| 874 if (node.constKeyword != null) { | 878 if (node.constKeyword != null) { |
| 875 Set<String> constructorParameterNames = | 879 Set<String> constructorParameterNames = |
| 876 node.parameters.parameters.map((p) => p.identifier.name).toSet(); | 880 node.parameters.parameters.map((p) => p.identifier.name).toSet(); |
| 877 b.constantInitializers = node.initializers | 881 b.constantInitializers = node.initializers |
| 878 .map((ConstructorInitializer initializer) => | 882 .map((ConstructorInitializer initializer) => |
| 879 serializeConstructorInitializer(initializer, (Expression expr) { | 883 serializeConstructorInitializer(initializer, (Expression expr) { |
| 880 return serializeConstExpr(expr, constructorParameterNames); | 884 return serializeConstExpr(expr, constructorParameterNames); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 /** | 1131 /** |
| 1128 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. | 1132 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. |
| 1129 */ | 1133 */ |
| 1130 class _TypeParameterScope extends _Scope { | 1134 class _TypeParameterScope extends _Scope { |
| 1131 /** | 1135 /** |
| 1132 * Get the number of [_ScopedTypeParameter]s defined in this | 1136 * Get the number of [_ScopedTypeParameter]s defined in this |
| 1133 * [_TypeParameterScope]. | 1137 * [_TypeParameterScope]. |
| 1134 */ | 1138 */ |
| 1135 int get length => _definedNames.length; | 1139 int get length => _definedNames.length; |
| 1136 } | 1140 } |
| OLD | NEW |