| 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 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 * [UnlinkedExecutable]. | 386 * [UnlinkedExecutable]. |
| 387 */ | 387 */ |
| 388 UnlinkedExecutableBuilder serializeExecutable( | 388 UnlinkedExecutableBuilder serializeExecutable( |
| 389 SimpleIdentifier name, | 389 SimpleIdentifier name, |
| 390 bool isGetter, | 390 bool isGetter, |
| 391 bool isSetter, | 391 bool isSetter, |
| 392 TypeName returnType, | 392 TypeName returnType, |
| 393 FormalParameterList formalParameters, | 393 FormalParameterList formalParameters, |
| 394 FunctionBody body, | 394 FunctionBody body, |
| 395 bool isTopLevel, | 395 bool isTopLevel, |
| 396 bool isStatic, | 396 bool isDeclaredStatic, |
| 397 Comment documentationComment, | 397 Comment documentationComment, |
| 398 TypeParameterList typeParameters, | 398 TypeParameterList typeParameters, |
| 399 bool isExternal) { | 399 bool isExternal) { |
| 400 int oldScopesLength = scopes.length; | 400 int oldScopesLength = scopes.length; |
| 401 _TypeParameterScope typeParameterScope = new _TypeParameterScope(); | 401 _TypeParameterScope typeParameterScope = new _TypeParameterScope(); |
| 402 scopes.add(typeParameterScope); | 402 scopes.add(typeParameterScope); |
| 403 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(); | 403 UnlinkedExecutableBuilder b = new UnlinkedExecutableBuilder(); |
| 404 String nameString = name.name; | 404 String nameString = name.name; |
| 405 if (isGetter) { | 405 if (isGetter) { |
| 406 b.kind = UnlinkedExecutableKind.getter; | 406 b.kind = UnlinkedExecutableKind.getter; |
| 407 } else if (isSetter) { | 407 } else if (isSetter) { |
| 408 b.kind = UnlinkedExecutableKind.setter; | 408 b.kind = UnlinkedExecutableKind.setter; |
| 409 nameString = '$nameString='; | 409 nameString = '$nameString='; |
| 410 } else { | 410 } else { |
| 411 b.kind = UnlinkedExecutableKind.functionOrMethod; | 411 b.kind = UnlinkedExecutableKind.functionOrMethod; |
| 412 } | 412 } |
| 413 b.isAbstract = body is EmptyFunctionBody; | 413 b.isAbstract = body is EmptyFunctionBody; |
| 414 b.name = nameString; | 414 b.name = nameString; |
| 415 b.nameOffset = name.offset; | 415 b.nameOffset = name.offset; |
| 416 b.typeParameters = | 416 b.typeParameters = |
| 417 serializeTypeParameters(typeParameters, typeParameterScope); | 417 serializeTypeParameters(typeParameters, typeParameterScope); |
| 418 if (!isTopLevel) { | 418 if (!isTopLevel) { |
| 419 b.isStatic = isStatic; | 419 b.isStatic = isDeclaredStatic; |
| 420 } | 420 } |
| 421 b.returnType = serializeTypeName(returnType); | 421 b.returnType = serializeTypeName(returnType); |
| 422 b.isExternal = isExternal; | 422 b.isExternal = isExternal; |
| 423 bool isSemanticallyStatic = isTopLevel || isDeclaredStatic; |
| 423 if (formalParameters != null) { | 424 if (formalParameters != null) { |
| 424 b.parameters = formalParameters.parameters | 425 b.parameters = formalParameters.parameters |
| 425 .map((FormalParameter p) => p.accept(this)) | 426 .map((FormalParameter p) => p.accept(this)) |
| 426 .toList(); | 427 .toList(); |
| 428 if (!isSemanticallyStatic) { |
| 429 for (int i = 0; i < formalParameters.parameters.length; i++) { |
| 430 if (!b.parameters[i].isFunctionTyped && |
| 431 b.parameters[i].type == null) { |
| 432 b.parameters[i].inferredTypeSlot = assignTypeSlot(); |
| 433 } |
| 434 } |
| 435 } |
| 427 } | 436 } |
| 428 b.documentationComment = serializeDocumentation(documentationComment); | 437 b.documentationComment = serializeDocumentation(documentationComment); |
| 438 if (returnType == null && !isSemanticallyStatic) { |
| 439 b.inferredReturnTypeSlot = assignTypeSlot(); |
| 440 } |
| 429 scopes.removeLast(); | 441 scopes.removeLast(); |
| 430 assert(scopes.length == oldScopesLength); | 442 assert(scopes.length == oldScopesLength); |
| 431 return b; | 443 return b; |
| 432 } | 444 } |
| 433 | 445 |
| 434 /** | 446 /** |
| 435 * Serialize the return type and parameters of a function-typed formal | 447 * Serialize the return type and parameters of a function-typed formal |
| 436 * parameter and store them in [b]. | 448 * parameter and store them in [b]. |
| 437 */ | 449 */ |
| 438 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b, | 450 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 } | 576 } |
| 565 return typeParameters.typeParameters.map(visitTypeParameter).toList(); | 577 return typeParameters.typeParameters.map(visitTypeParameter).toList(); |
| 566 } | 578 } |
| 567 return const <UnlinkedTypeParamBuilder>[]; | 579 return const <UnlinkedTypeParamBuilder>[]; |
| 568 } | 580 } |
| 569 | 581 |
| 570 /** | 582 /** |
| 571 * Serialize the given [variables] into [UnlinkedVariable]s, and store them | 583 * Serialize the given [variables] into [UnlinkedVariable]s, and store them |
| 572 * in [this.variables]. | 584 * in [this.variables]. |
| 573 */ | 585 */ |
| 574 void serializeVariables(VariableDeclarationList variables, bool isStatic, | 586 void serializeVariables(VariableDeclarationList variables, |
| 575 Comment documentationComment) { | 587 bool isDeclaredStatic, Comment documentationComment, bool isField) { |
| 576 for (VariableDeclaration variable in variables.variables) { | 588 for (VariableDeclaration variable in variables.variables) { |
| 577 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); | 589 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); |
| 578 b.isFinal = variables.isFinal; | 590 b.isFinal = variables.isFinal; |
| 579 b.isConst = variables.isConst; | 591 b.isConst = variables.isConst; |
| 580 b.isStatic = isStatic; | 592 b.isStatic = isDeclaredStatic; |
| 581 b.name = variable.name.name; | 593 b.name = variable.name.name; |
| 582 b.nameOffset = variable.name.offset; | 594 b.nameOffset = variable.name.offset; |
| 583 b.type = serializeTypeName(variables.type); | 595 b.type = serializeTypeName(variables.type); |
| 584 b.documentationComment = serializeDocumentation(documentationComment); | 596 b.documentationComment = serializeDocumentation(documentationComment); |
| 585 if (variable.isConst) { | 597 if (variable.isConst) { |
| 586 Expression initializer = variable.initializer; | 598 Expression initializer = variable.initializer; |
| 587 if (initializer != null) { | 599 if (initializer != null) { |
| 588 b.constExpr = serializeConstExpr(initializer); | 600 b.constExpr = serializeConstExpr(initializer); |
| 589 } | 601 } |
| 590 } | 602 } |
| 591 if (variable.initializer != null && | 603 if (variable.initializer != null && |
| 592 (variables.isFinal || variables.isConst)) { | 604 (variables.isFinal || variables.isConst)) { |
| 593 b.propagatedTypeSlot = assignTypeSlot(); | 605 b.propagatedTypeSlot = assignTypeSlot(); |
| 594 } | 606 } |
| 607 bool isSemanticallyStatic = !isField || isDeclaredStatic; |
| 608 if (variables.type == null && |
| 609 (variable.initializer != null || !isSemanticallyStatic)) { |
| 610 b.inferredTypeSlot = assignTypeSlot(); |
| 611 } |
| 595 this.variables.add(b); | 612 this.variables.add(b); |
| 596 } | 613 } |
| 597 } | 614 } |
| 598 | 615 |
| 599 @override | 616 @override |
| 600 void visitClassDeclaration(ClassDeclaration node) { | 617 void visitClassDeclaration(ClassDeclaration node) { |
| 601 TypeName superclass = | 618 TypeName superclass = |
| 602 node.extendsClause == null ? null : node.extendsClause.superclass; | 619 node.extendsClause == null ? null : node.extendsClause.superclass; |
| 603 serializeClass( | 620 serializeClass( |
| 604 node.abstractKeyword, | 621 node.abstractKeyword, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 | 686 |
| 670 @override | 687 @override |
| 671 void visitExportDirective(ExportDirective node) { | 688 void visitExportDirective(ExportDirective node) { |
| 672 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder( | 689 UnlinkedExportNonPublicBuilder b = new UnlinkedExportNonPublicBuilder( |
| 673 uriOffset: node.uri.offset, uriEnd: node.uri.end, offset: node.offset); | 690 uriOffset: node.uri.offset, uriEnd: node.uri.end, offset: node.offset); |
| 674 exports.add(b); | 691 exports.add(b); |
| 675 } | 692 } |
| 676 | 693 |
| 677 @override | 694 @override |
| 678 void visitFieldDeclaration(FieldDeclaration node) { | 695 void visitFieldDeclaration(FieldDeclaration node) { |
| 679 serializeVariables( | 696 serializeVariables(node.fields, node.staticKeyword != null, |
| 680 node.fields, node.staticKeyword != null, node.documentationComment); | 697 node.documentationComment, true); |
| 681 } | 698 } |
| 682 | 699 |
| 683 @override | 700 @override |
| 684 UnlinkedParamBuilder visitFieldFormalParameter(FieldFormalParameter node) { | 701 UnlinkedParamBuilder visitFieldFormalParameter(FieldFormalParameter node) { |
| 685 UnlinkedParamBuilder b = serializeParameter(node); | 702 UnlinkedParamBuilder b = serializeParameter(node); |
| 686 b.isInitializingFormal = true; | 703 b.isInitializingFormal = true; |
| 687 if (node.type != null || node.parameters != null) { | 704 if (node.type != null || node.parameters != null) { |
| 688 b.isFunctionTyped = node.parameters != null; | 705 b.isFunctionTyped = node.parameters != null; |
| 689 if (node.parameters != null) { | 706 if (node.parameters != null) { |
| 690 serializeFunctionTypedParameterDetails(b, node.type, node.parameters); | 707 serializeFunctionTypedParameterDetails(b, node.type, node.parameters); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 | 816 |
| 800 @override | 817 @override |
| 801 UnlinkedParamBuilder visitSimpleFormalParameter(SimpleFormalParameter node) { | 818 UnlinkedParamBuilder visitSimpleFormalParameter(SimpleFormalParameter node) { |
| 802 UnlinkedParamBuilder b = serializeParameter(node); | 819 UnlinkedParamBuilder b = serializeParameter(node); |
| 803 b.type = serializeTypeName(node.type); | 820 b.type = serializeTypeName(node.type); |
| 804 return b; | 821 return b; |
| 805 } | 822 } |
| 806 | 823 |
| 807 @override | 824 @override |
| 808 void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 825 void visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 809 serializeVariables(node.variables, false, node.documentationComment); | 826 serializeVariables(node.variables, false, node.documentationComment, false); |
| 810 } | 827 } |
| 811 | 828 |
| 812 @override | 829 @override |
| 813 UnlinkedTypeParamBuilder visitTypeParameter(TypeParameter node) { | 830 UnlinkedTypeParamBuilder visitTypeParameter(TypeParameter node) { |
| 814 UnlinkedTypeParamBuilder b = new UnlinkedTypeParamBuilder(); | 831 UnlinkedTypeParamBuilder b = new UnlinkedTypeParamBuilder(); |
| 815 b.name = node.name.name; | 832 b.name = node.name.name; |
| 816 b.nameOffset = node.name.offset; | 833 b.nameOffset = node.name.offset; |
| 817 if (node.bound != null) { | 834 if (node.bound != null) { |
| 818 b.bound = serializeTypeName(node.bound); | 835 b.bound = serializeTypeName(node.bound); |
| 819 } | 836 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 832 /** | 849 /** |
| 833 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. | 850 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. |
| 834 */ | 851 */ |
| 835 class _TypeParameterScope extends _Scope { | 852 class _TypeParameterScope extends _Scope { |
| 836 /** | 853 /** |
| 837 * Get the number of [_ScopedTypeParameter]s defined in this | 854 * Get the number of [_ScopedTypeParameter]s defined in this |
| 838 * [_TypeParameterScope]. | 855 * [_TypeParameterScope]. |
| 839 */ | 856 */ |
| 840 int get length => _definedNames.length; | 857 int get length => _definedNames.length; |
| 841 } | 858 } |
| OLD | NEW |