| 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/dart/element/type.dart' show DartType; | 10 import 'package:analyzer/dart/element/type.dart' show DartType; |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 /** | 560 /** |
| 561 * Serialize the given [declaredIdentifier] into [UnlinkedVariable], and | 561 * Serialize the given [declaredIdentifier] into [UnlinkedVariable], and |
| 562 * store it in [variables]. | 562 * store it in [variables]. |
| 563 */ | 563 */ |
| 564 void serializeDeclaredIdentifier( | 564 void serializeDeclaredIdentifier( |
| 565 AstNode scopeNode, | 565 AstNode scopeNode, |
| 566 Comment documentationComment, | 566 Comment documentationComment, |
| 567 NodeList<Annotation> annotations, | 567 NodeList<Annotation> annotations, |
| 568 bool isFinal, | 568 bool isFinal, |
| 569 bool isConst, | 569 bool isConst, |
| 570 TypeAnnotation type, | 570 TypeName type, |
| 571 bool assignPropagatedTypeSlot, | 571 bool assignPropagatedTypeSlot, |
| 572 SimpleIdentifier declaredIdentifier) { | 572 SimpleIdentifier declaredIdentifier) { |
| 573 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); | 573 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); |
| 574 b.isFinal = isFinal; | 574 b.isFinal = isFinal; |
| 575 b.isConst = isConst; | 575 b.isConst = isConst; |
| 576 b.name = declaredIdentifier.name; | 576 b.name = declaredIdentifier.name; |
| 577 b.nameOffset = declaredIdentifier.offset; | 577 b.nameOffset = declaredIdentifier.offset; |
| 578 b.type = serializeTypeName(type); | 578 b.type = serializeTypeName(type); |
| 579 b.documentationComment = serializeDocumentation(documentationComment); | 579 b.documentationComment = serializeDocumentation(documentationComment); |
| 580 b.annotations = serializeAnnotations(annotations); | 580 b.annotations = serializeAnnotations(annotations); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 608 * | 608 * |
| 609 * If [serializeBodyExpr] is `true`, then the function definition is stored | 609 * If [serializeBodyExpr] is `true`, then the function definition is stored |
| 610 * in [UnlinkedExecutableBuilder.bodyExpr]. | 610 * in [UnlinkedExecutableBuilder.bodyExpr]. |
| 611 */ | 611 */ |
| 612 UnlinkedExecutableBuilder serializeExecutable( | 612 UnlinkedExecutableBuilder serializeExecutable( |
| 613 AstNode node, | 613 AstNode node, |
| 614 String name, | 614 String name, |
| 615 int nameOffset, | 615 int nameOffset, |
| 616 bool isGetter, | 616 bool isGetter, |
| 617 bool isSetter, | 617 bool isSetter, |
| 618 TypeAnnotation returnType, | 618 TypeName returnType, |
| 619 FormalParameterList formalParameters, | 619 FormalParameterList formalParameters, |
| 620 FunctionBody body, | 620 FunctionBody body, |
| 621 bool isTopLevel, | 621 bool isTopLevel, |
| 622 bool isDeclaredStatic, | 622 bool isDeclaredStatic, |
| 623 Comment documentationComment, | 623 Comment documentationComment, |
| 624 NodeList<Annotation> annotations, | 624 NodeList<Annotation> annotations, |
| 625 TypeParameterList typeParameters, | 625 TypeParameterList typeParameters, |
| 626 bool isExternal, | 626 bool isExternal, |
| 627 bool serializeBodyExpr, | 627 bool serializeBodyExpr, |
| 628 bool serializeBody) { | 628 bool serializeBody) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 _localClosureIndexMap = oldLocalClosureIndexMap; | 757 _localClosureIndexMap = oldLocalClosureIndexMap; |
| 758 _serializeClosureBodyExprs = oldSerializeClosureBodyExprs; | 758 _serializeClosureBodyExprs = oldSerializeClosureBodyExprs; |
| 759 return localClosureIndexMap; | 759 return localClosureIndexMap; |
| 760 } | 760 } |
| 761 | 761 |
| 762 /** | 762 /** |
| 763 * Serialize the return type and parameters of a function-typed formal | 763 * Serialize the return type and parameters of a function-typed formal |
| 764 * parameter and store them in [b]. | 764 * parameter and store them in [b]. |
| 765 */ | 765 */ |
| 766 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b, | 766 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b, |
| 767 TypeAnnotation returnType, FormalParameterList parameters) { | 767 TypeName returnType, FormalParameterList parameters) { |
| 768 EntityRefBuilder serializedReturnType = serializeTypeName(returnType); | 768 EntityRefBuilder serializedReturnType = serializeTypeName(returnType); |
| 769 if (serializedReturnType != null) { | 769 if (serializedReturnType != null) { |
| 770 b.type = serializedReturnType; | 770 b.type = serializedReturnType; |
| 771 } | 771 } |
| 772 bool oldMayInheritCovariance = _parametersMayInheritCovariance; | 772 bool oldMayInheritCovariance = _parametersMayInheritCovariance; |
| 773 _parametersMayInheritCovariance = false; | 773 _parametersMayInheritCovariance = false; |
| 774 b.parameters = parameters.parameters | 774 b.parameters = parameters.parameters |
| 775 .map((FormalParameter p) => p.accept(this) as UnlinkedParamBuilder) | 775 .map((FormalParameter p) => p.accept(this) as UnlinkedParamBuilder) |
| 776 .toList(); | 776 .toList(); |
| 777 _parametersMayInheritCovariance = oldMayInheritCovariance; | 777 _parametersMayInheritCovariance = oldMayInheritCovariance; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 926 return b; | 926 return b; |
| 927 } | 927 } |
| 928 } | 928 } |
| 929 | 929 |
| 930 /** | 930 /** |
| 931 * Serialize a type name (which might be defined in a nested scope, at top | 931 * Serialize a type name (which might be defined in a nested scope, at top |
| 932 * level within this library, or at top level within an imported library) to | 932 * level within this library, or at top level within an imported library) to |
| 933 * a [EntityRef]. Note that this method does the right thing if the | 933 * a [EntityRef]. Note that this method does the right thing if the |
| 934 * name doesn't refer to an entity other than a type (e.g. a class member). | 934 * name doesn't refer to an entity other than a type (e.g. a class member). |
| 935 */ | 935 */ |
| 936 EntityRefBuilder serializeTypeName(TypeAnnotation node) { | 936 EntityRefBuilder serializeTypeName(TypeName node) { |
| 937 if (node is TypeName) { | 937 return serializeType(node?.name, node?.typeArguments); |
| 938 return serializeType(node?.name, node?.typeArguments); | |
| 939 } else if (node != null) { | |
| 940 throw new ArgumentError('Cannot serialize a ${node.runtimeType}'); | |
| 941 } | |
| 942 return null; | |
| 943 } | 938 } |
| 944 | 939 |
| 945 /** | 940 /** |
| 946 * Serialize the given [typeParameters] into a list of [UnlinkedTypeParam]s, | 941 * Serialize the given [typeParameters] into a list of [UnlinkedTypeParam]s, |
| 947 * and also store them in [typeParameterScope]. | 942 * and also store them in [typeParameterScope]. |
| 948 */ | 943 */ |
| 949 List<UnlinkedTypeParamBuilder> serializeTypeParameters( | 944 List<UnlinkedTypeParamBuilder> serializeTypeParameters( |
| 950 TypeParameterList typeParameters, | 945 TypeParameterList typeParameters, |
| 951 _TypeParameterScope typeParameterScope) { | 946 _TypeParameterScope typeParameterScope) { |
| 952 if (typeParameters != null) { | 947 if (typeParameters != null) { |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 return b; | 1390 return b; |
| 1396 } | 1391 } |
| 1397 | 1392 |
| 1398 @override | 1393 @override |
| 1399 void visitVariableDeclarationStatement(VariableDeclarationStatement node) { | 1394 void visitVariableDeclarationStatement(VariableDeclarationStatement node) { |
| 1400 serializeVariables( | 1395 serializeVariables( |
| 1401 enclosingBlock, node.variables, false, null, null, false); | 1396 enclosingBlock, node.variables, false, null, null, false); |
| 1402 } | 1397 } |
| 1403 | 1398 |
| 1404 /** | 1399 /** |
| 1400 * Helper method to determine if a given [typeName] refers to `dynamic`. |
| 1401 */ |
| 1402 static bool isDynamic(TypeName typeName) { |
| 1403 Identifier name = typeName.name; |
| 1404 return name is SimpleIdentifier && name.name == 'dynamic'; |
| 1405 } |
| 1406 |
| 1407 /** |
| 1405 * Compute the API signature of the unit and record it. | 1408 * Compute the API signature of the unit and record it. |
| 1406 */ | 1409 */ |
| 1407 static void _computeApiSignature(UnlinkedUnitBuilder b) { | 1410 static void _computeApiSignature(UnlinkedUnitBuilder b) { |
| 1408 ApiSignature apiSignature = new ApiSignature(); | 1411 ApiSignature apiSignature = new ApiSignature(); |
| 1409 b.collectApiSignature(apiSignature); | 1412 b.collectApiSignature(apiSignature); |
| 1410 b.apiSignature = apiSignature.toByteList(); | 1413 b.apiSignature = apiSignature.toByteList(); |
| 1411 } | 1414 } |
| 1412 } | 1415 } |
| 1413 | 1416 |
| 1414 /** | 1417 /** |
| 1415 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. | 1418 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. |
| 1416 */ | 1419 */ |
| 1417 class _TypeParameterScope extends _Scope { | 1420 class _TypeParameterScope extends _Scope { |
| 1418 /** | 1421 /** |
| 1419 * Get the number of [_ScopedTypeParameter]s defined in this | 1422 * Get the number of [_ScopedTypeParameter]s defined in this |
| 1420 * [_TypeParameterScope]. | 1423 * [_TypeParameterScope]. |
| 1421 */ | 1424 */ |
| 1422 int get length => _definedNames.length; | 1425 int get length => _definedNames.length; |
| 1423 } | 1426 } |
| OLD | NEW |