| 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 | 14 |
| 14 /** | 15 /** |
| 15 * Serialize all the declarations in [compilationUnit] to an unlinked summary. | 16 * Serialize all the declarations in [compilationUnit] to an unlinked summary. |
| 16 */ | 17 */ |
| 17 UnlinkedUnitBuilder serializeAstUnlinked(CompilationUnit compilationUnit) { | 18 UnlinkedUnitBuilder serializeAstUnlinked(CompilationUnit compilationUnit) { |
| 18 return new _SummarizeAstVisitor().serializeCompilationUnit(compilationUnit); | 19 return new _SummarizeAstVisitor().serializeCompilationUnit(compilationUnit); |
| 19 } | 20 } |
| 20 | 21 |
| 21 /** | 22 /** |
| 23 * Instances of this class keep track of intermediate state during |
| 24 * serialization of a single constant [Expression]. |
| 25 */ |
| 26 class _ConstExprSerializer extends AbstractConstExprSerializer { |
| 27 UnlinkedTypeRefBuilder serializeIdentifier(Identifier identifier) { |
| 28 throw new UnimplementedError('serializeIdentifier'); |
| 29 } |
| 30 |
| 31 @override |
| 32 UnlinkedTypeRefBuilder serializeType(TypeName typeName) { |
| 33 throw new UnimplementedError('serializeType'); |
| 34 } |
| 35 } |
| 36 |
| 37 /** |
| 22 * An [_OtherScopedEntity] is a [_ScopedEntity] that does not refer to a type | 38 * An [_OtherScopedEntity] is a [_ScopedEntity] that does not refer to a type |
| 23 * parameter. Since we don't need to track any special information about these | 39 * parameter. Since we don't need to track any special information about these |
| 24 * types of scoped entities, it is a singleton class. | 40 * types of scoped entities, it is a singleton class. |
| 25 */ | 41 */ |
| 26 class _OtherScopedEntity extends _ScopedEntity { | 42 class _OtherScopedEntity extends _ScopedEntity { |
| 27 static final _OtherScopedEntity _instance = new _OtherScopedEntity._(); | 43 static final _OtherScopedEntity _instance = new _OtherScopedEntity._(); |
| 28 | 44 |
| 29 factory _OtherScopedEntity() => _instance; | 45 factory _OtherScopedEntity() => _instance; |
| 30 | 46 |
| 31 _OtherScopedEntity._(); | 47 _OtherScopedEntity._(); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 b.imports = unlinkedImports; | 350 b.imports = unlinkedImports; |
| 335 b.parts = parts; | 351 b.parts = parts; |
| 336 b.references = unlinkedReferences; | 352 b.references = unlinkedReferences; |
| 337 b.typedefs = typedefs; | 353 b.typedefs = typedefs; |
| 338 b.variables = variables; | 354 b.variables = variables; |
| 339 b.publicNamespace = computePublicNamespace(compilationUnit); | 355 b.publicNamespace = computePublicNamespace(compilationUnit); |
| 340 return b; | 356 return b; |
| 341 } | 357 } |
| 342 | 358 |
| 343 /** | 359 /** |
| 360 * Serialize the given [expression], creating an [UnlinkedConstBuilder]. |
| 361 */ |
| 362 UnlinkedConstBuilder serializeConstExpr(Expression expression) { |
| 363 _ConstExprSerializer serializer = new _ConstExprSerializer(); |
| 364 serializer.serialize(expression); |
| 365 return serializer.toBuilder(); |
| 366 } |
| 367 |
| 368 /** |
| 344 * Serialize a [Comment] node into an [UnlinkedDocumentationComment] object. | 369 * Serialize a [Comment] node into an [UnlinkedDocumentationComment] object. |
| 345 */ | 370 */ |
| 346 UnlinkedDocumentationCommentBuilder serializeDocumentation( | 371 UnlinkedDocumentationCommentBuilder serializeDocumentation( |
| 347 Comment documentationComment) { | 372 Comment documentationComment) { |
| 348 if (documentationComment == null) { | 373 if (documentationComment == null) { |
| 349 return null; | 374 return null; |
| 350 } | 375 } |
| 351 String text = documentationComment.tokens | 376 String text = documentationComment.tokens |
| 352 .map((Token t) => t.toString()) | 377 .map((Token t) => t.toString()) |
| 353 .join() | 378 .join() |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 for (VariableDeclaration variable in variables.variables) { | 573 for (VariableDeclaration variable in variables.variables) { |
| 549 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); | 574 UnlinkedVariableBuilder b = new UnlinkedVariableBuilder(); |
| 550 b.isFinal = variables.isFinal; | 575 b.isFinal = variables.isFinal; |
| 551 b.isConst = variables.isConst; | 576 b.isConst = variables.isConst; |
| 552 b.isStatic = isStatic; | 577 b.isStatic = isStatic; |
| 553 b.name = variable.name.name; | 578 b.name = variable.name.name; |
| 554 b.nameOffset = variable.name.offset; | 579 b.nameOffset = variable.name.offset; |
| 555 b.type = serializeTypeName(variables.type); | 580 b.type = serializeTypeName(variables.type); |
| 556 b.hasImplicitType = variables.type == null; | 581 b.hasImplicitType = variables.type == null; |
| 557 b.documentationComment = serializeDocumentation(documentationComment); | 582 b.documentationComment = serializeDocumentation(documentationComment); |
| 583 if (variable.isConst) { |
| 584 Expression initializer = variable.initializer; |
| 585 if (initializer != null) { |
| 586 b.constExpr = serializeConstExpr(initializer); |
| 587 } |
| 588 } |
| 558 this.variables.add(b); | 589 this.variables.add(b); |
| 559 } | 590 } |
| 560 } | 591 } |
| 561 | 592 |
| 562 @override | 593 @override |
| 563 void visitClassDeclaration(ClassDeclaration node) { | 594 void visitClassDeclaration(ClassDeclaration node) { |
| 564 currentClassDeclaration = node; | 595 currentClassDeclaration = node; |
| 565 TypeName superclass = | 596 TypeName superclass = |
| 566 node.extendsClause == null ? null : node.extendsClause.superclass; | 597 node.extendsClause == null ? null : node.extendsClause.superclass; |
| 567 serializeClass( | 598 serializeClass( |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 /** | 836 /** |
| 806 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. | 837 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. |
| 807 */ | 838 */ |
| 808 class _TypeParameterScope extends _Scope { | 839 class _TypeParameterScope extends _Scope { |
| 809 /** | 840 /** |
| 810 * Get the number of [_ScopedTypeParameter]s defined in this | 841 * Get the number of [_ScopedTypeParameter]s defined in this |
| 811 * [_TypeParameterScope]. | 842 * [_TypeParameterScope]. |
| 812 */ | 843 */ |
| 813 int get length => _definedNames.length; | 844 int get length => _definedNames.length; |
| 814 } | 845 } |
| OLD | NEW |