| 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'; |
| 11 import 'package:analyzer/src/summary/format.dart'; | 11 import 'package:analyzer/src/summary/format.dart'; |
| 12 import 'package:analyzer/src/summary/public_namespace_computer.dart'; | 12 import 'package:analyzer/src/summary/public_namespace_computer.dart'; |
| 13 import 'package:analyzer/src/summary/summarize_const_expr.dart'; | 13 import 'package:analyzer/src/summary/summarize_const_expr.dart'; |
| 14 | 14 |
| 15 /** | 15 /** |
| 16 * Serialize all the declarations in [compilationUnit] to an unlinked summary. | 16 * Serialize all the declarations in [compilationUnit] to an unlinked summary. |
| 17 */ | 17 */ |
| 18 UnlinkedUnitBuilder serializeAstUnlinked(CompilationUnit compilationUnit) { | 18 UnlinkedUnitBuilder serializeAstUnlinked(CompilationUnit compilationUnit) { |
| 19 return new _SummarizeAstVisitor().serializeCompilationUnit(compilationUnit); | 19 return new _SummarizeAstVisitor().serializeCompilationUnit(compilationUnit); |
| 20 } | 20 } |
| 21 | 21 |
| 22 /** | 22 /** |
| 23 * Instances of this class keep track of intermediate state during | 23 * Instances of this class keep track of intermediate state during |
| 24 * serialization of a single constant [Expression]. | 24 * serialization of a single constant [Expression]. |
| 25 */ | 25 */ |
| 26 class _ConstExprSerializer extends AbstractConstExprSerializer { | 26 class _ConstExprSerializer extends AbstractConstExprSerializer { |
| 27 final _SummarizeAstVisitor visitor; |
| 28 |
| 29 _ConstExprSerializer(this.visitor); |
| 30 |
| 27 UnlinkedTypeRefBuilder serializeIdentifier(Identifier identifier) { | 31 UnlinkedTypeRefBuilder serializeIdentifier(Identifier identifier) { |
| 28 throw new UnimplementedError('serializeIdentifier'); | 32 UnlinkedTypeRefBuilder b = new UnlinkedTypeRefBuilder(); |
| 33 if (identifier is SimpleIdentifier) { |
| 34 b.reference = visitor.serializeReference(null, identifier.name); |
| 35 } else if (identifier is PrefixedIdentifier) { |
| 36 int prefix = visitor.serializeReference(null, identifier.prefix.name); |
| 37 b.reference = |
| 38 visitor.serializeReference(prefix, identifier.identifier.name); |
| 39 } else { |
| 40 throw new StateError( |
| 41 'Unexpected identifier type: ${identifier.runtimeType}'); |
| 42 } |
| 43 return b; |
| 29 } | 44 } |
| 30 | 45 |
| 31 @override | 46 @override |
| 32 UnlinkedTypeRefBuilder serializeType(TypeName typeName) { | 47 UnlinkedTypeRefBuilder serializeType(TypeName node) { |
| 33 throw new UnimplementedError('serializeType'); | 48 return visitor.serializeTypeName(node); |
| 34 } | 49 } |
| 35 } | 50 } |
| 36 | 51 |
| 37 /** | 52 /** |
| 38 * An [_OtherScopedEntity] is a [_ScopedEntity] that does not refer to a type | 53 * An [_OtherScopedEntity] is a [_ScopedEntity] that does not refer to a type |
| 39 * parameter. Since we don't need to track any special information about these | 54 * parameter. Since we don't need to track any special information about these |
| 40 * types of scoped entities, it is a singleton class. | 55 * types of scoped entities, it is a singleton class. |
| 41 */ | 56 */ |
| 42 class _OtherScopedEntity extends _ScopedEntity { | 57 class _OtherScopedEntity extends _ScopedEntity { |
| 43 static final _OtherScopedEntity _instance = new _OtherScopedEntity._(); | 58 static final _OtherScopedEntity _instance = new _OtherScopedEntity._(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 int libraryNameOffset; | 209 int libraryNameOffset; |
| 195 | 210 |
| 196 /** | 211 /** |
| 197 * If the library has a library directive, the length of the library name, as | 212 * If the library has a library directive, the length of the library name, as |
| 198 * it appears in the source file. Otherwise `null`. | 213 * it appears in the source file. Otherwise `null`. |
| 199 */ | 214 */ |
| 200 int libraryNameLength; | 215 int libraryNameLength; |
| 201 | 216 |
| 202 /** | 217 /** |
| 203 * If the library has a library directive, the documentation comment for it | 218 * If the library has a library directive, the documentation comment for it |
| 204 * (if any). Othrwise `null`. | 219 * (if any). Otherwise `null`. |
| 205 */ | 220 */ |
| 206 UnlinkedDocumentationCommentBuilder libraryDocumentationComment; | 221 UnlinkedDocumentationCommentBuilder libraryDocumentationComment; |
| 207 | 222 |
| 208 /** | 223 /** |
| 209 * Build a [_Scope] object containing the names defined within the body of a | 224 * Build a [_Scope] object containing the names defined within the body of a |
| 210 * class declaration. | 225 * class declaration. |
| 211 */ | 226 */ |
| 212 _Scope buildClassMemberScope(NodeList<ClassMember> members) { | 227 _Scope buildClassMemberScope(NodeList<ClassMember> members) { |
| 213 _Scope scope = new _Scope(); | 228 _Scope scope = new _Scope(); |
| 214 for (ClassMember member in members) { | 229 for (ClassMember member in members) { |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 b.typedefs = typedefs; | 368 b.typedefs = typedefs; |
| 354 b.variables = variables; | 369 b.variables = variables; |
| 355 b.publicNamespace = computePublicNamespace(compilationUnit); | 370 b.publicNamespace = computePublicNamespace(compilationUnit); |
| 356 return b; | 371 return b; |
| 357 } | 372 } |
| 358 | 373 |
| 359 /** | 374 /** |
| 360 * Serialize the given [expression], creating an [UnlinkedConstBuilder]. | 375 * Serialize the given [expression], creating an [UnlinkedConstBuilder]. |
| 361 */ | 376 */ |
| 362 UnlinkedConstBuilder serializeConstExpr(Expression expression) { | 377 UnlinkedConstBuilder serializeConstExpr(Expression expression) { |
| 363 _ConstExprSerializer serializer = new _ConstExprSerializer(); | 378 _ConstExprSerializer serializer = new _ConstExprSerializer(this); |
| 364 serializer.serialize(expression); | 379 serializer.serialize(expression); |
| 365 return serializer.toBuilder(); | 380 return serializer.toBuilder(); |
| 366 } | 381 } |
| 367 | 382 |
| 368 /** | 383 /** |
| 369 * Serialize a [Comment] node into an [UnlinkedDocumentationComment] object. | 384 * Serialize a [Comment] node into an [UnlinkedDocumentationComment] object. |
| 370 */ | 385 */ |
| 371 UnlinkedDocumentationCommentBuilder serializeDocumentation( | 386 UnlinkedDocumentationCommentBuilder serializeDocumentation( |
| 372 Comment documentationComment) { | 387 Comment documentationComment) { |
| 373 if (documentationComment == null) { | 388 if (documentationComment == null) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 b.reference = | 549 b.reference = |
| 535 serializeReference(prefixIndex, identifier.identifier.name); | 550 serializeReference(prefixIndex, identifier.identifier.name); |
| 536 } else { | 551 } else { |
| 537 throw new StateError( | 552 throw new StateError( |
| 538 'Unexpected identifier type: ${identifier.runtimeType}'); | 553 'Unexpected identifier type: ${identifier.runtimeType}'); |
| 539 } | 554 } |
| 540 if (node.typeArguments != null) { | 555 if (node.typeArguments != null) { |
| 541 // Trailing type arguments of type 'dynamic' should be omitted. | 556 // Trailing type arguments of type 'dynamic' should be omitted. |
| 542 NodeList<TypeName> args = node.typeArguments.arguments; | 557 NodeList<TypeName> args = node.typeArguments.arguments; |
| 543 int numArgsToSerialize = args.length; | 558 int numArgsToSerialize = args.length; |
| 544 while (numArgsToSerialize > 0 && isDynamic(args[numArgsToSerialize - 1])
) { | 559 while ( |
| 560 numArgsToSerialize > 0 && isDynamic(args[numArgsToSerialize - 1])) { |
| 545 --numArgsToSerialize; | 561 --numArgsToSerialize; |
| 546 } | 562 } |
| 547 if (numArgsToSerialize > 0) { | 563 if (numArgsToSerialize > 0) { |
| 548 List<UnlinkedTypeRefBuilder> serializedArguments = <UnlinkedTypeRefBui
lder>[]; | 564 List<UnlinkedTypeRefBuilder> serializedArguments = |
| 565 <UnlinkedTypeRefBuilder>[]; |
| 549 for (int i = 0; i < numArgsToSerialize; i++) { | 566 for (int i = 0; i < numArgsToSerialize; i++) { |
| 550 serializedArguments.add(serializeTypeName(args[i])); | 567 serializedArguments.add(serializeTypeName(args[i])); |
| 551 } | 568 } |
| 552 b.typeArguments = serializedArguments; | 569 b.typeArguments = serializedArguments; |
| 553 } | 570 } |
| 554 } | 571 } |
| 555 } | 572 } |
| 556 return b; | 573 return b; |
| 557 } | 574 } |
| 558 | 575 |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 /** | 863 /** |
| 847 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. | 864 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. |
| 848 */ | 865 */ |
| 849 class _TypeParameterScope extends _Scope { | 866 class _TypeParameterScope extends _Scope { |
| 850 /** | 867 /** |
| 851 * Get the number of [_ScopedTypeParameter]s defined in this | 868 * Get the number of [_ScopedTypeParameter]s defined in this |
| 852 * [_TypeParameterScope]. | 869 * [_TypeParameterScope]. |
| 853 */ | 870 */ |
| 854 int get length => _definedNames.length; | 871 int get length => _definedNames.length; |
| 855 } | 872 } |
| OLD | NEW |