Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(875)

Side by Side Diff: pkg/analyzer/lib/src/summary/summarize_ast.dart

Issue 1619913005: Rename TypeRef to EntityRef. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
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; 27 final _SummarizeAstVisitor visitor;
28 28
29 _ConstExprSerializer(this.visitor); 29 _ConstExprSerializer(this.visitor);
30 30
31 TypeRefBuilder serializeIdentifier(Identifier identifier) { 31 EntityRefBuilder serializeIdentifier(Identifier identifier) {
32 TypeRefBuilder b = new TypeRefBuilder(); 32 EntityRefBuilder b = new EntityRefBuilder();
33 if (identifier is SimpleIdentifier) { 33 if (identifier is SimpleIdentifier) {
34 b.reference = visitor.serializeReference(null, identifier.name); 34 b.reference = visitor.serializeReference(null, identifier.name);
35 } else if (identifier is PrefixedIdentifier) { 35 } else if (identifier is PrefixedIdentifier) {
36 int prefix = visitor.serializeReference(null, identifier.prefix.name); 36 int prefix = visitor.serializeReference(null, identifier.prefix.name);
37 b.reference = 37 b.reference =
38 visitor.serializeReference(prefix, identifier.identifier.name); 38 visitor.serializeReference(prefix, identifier.identifier.name);
39 } else { 39 } else {
40 throw new StateError( 40 throw new StateError(
41 'Unexpected identifier type: ${identifier.runtimeType}'); 41 'Unexpected identifier type: ${identifier.runtimeType}');
42 } 42 }
43 return b; 43 return b;
44 } 44 }
45 45
46 @override 46 @override
47 TypeRefBuilder serializeType(TypeName node) { 47 EntityRefBuilder serializeType(TypeName node) {
48 return visitor.serializeTypeName(node); 48 return visitor.serializeTypeName(node);
49 } 49 }
50 } 50 }
51 51
52 /** 52 /**
53 * 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
54 * 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
55 * types of scoped entities, it is a singleton class. 55 * types of scoped entities, it is a singleton class.
56 */ 56 */
57 class _OtherScopedEntity extends _ScopedEntity { 57 class _OtherScopedEntity extends _ScopedEntity {
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 assert(scopes.length == oldScopesLength); 458 assert(scopes.length == oldScopesLength);
459 return b; 459 return b;
460 } 460 }
461 461
462 /** 462 /**
463 * Serialize the return type and parameters of a function-typed formal 463 * Serialize the return type and parameters of a function-typed formal
464 * parameter and store them in [b]. 464 * parameter and store them in [b].
465 */ 465 */
466 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b, 466 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b,
467 TypeName returnType, FormalParameterList parameters) { 467 TypeName returnType, FormalParameterList parameters) {
468 TypeRefBuilder serializedReturnType = 468 EntityRefBuilder serializedReturnType =
469 serializeTypeName(returnType, allowVoid: true); 469 serializeTypeName(returnType, allowVoid: true);
470 if (serializedReturnType != null) { 470 if (serializedReturnType != null) {
471 b.type = serializedReturnType; 471 b.type = serializedReturnType;
472 } 472 }
473 b.parameters = parameters.parameters 473 b.parameters = parameters.parameters
474 .map((FormalParameter p) => p.accept(this)) 474 .map((FormalParameter p) => p.accept(this))
475 .toList(); 475 .toList();
476 } 476 }
477 477
478 /** 478 /**
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 assert(name != 'dynamic'); 511 assert(name != 'dynamic');
512 int index = unlinkedReferences.length; 512 int index = unlinkedReferences.length;
513 unlinkedReferences.add(new UnlinkedReferenceBuilder( 513 unlinkedReferences.add(new UnlinkedReferenceBuilder(
514 prefixReference: prefixIndex, name: name)); 514 prefixReference: prefixIndex, name: name));
515 return index; 515 return index;
516 }); 516 });
517 517
518 /** 518 /**
519 * Serialize a type name (which might be defined in a nested scope, at top 519 * Serialize a type name (which might be defined in a nested scope, at top
520 * level within this library, or at top level within an imported library) to 520 * level within this library, or at top level within an imported library) to
521 * a [TypeRef]. Note that this method does the right thing if the 521 * a [EntityRef]. Note that this method does the right thing if the
522 * name doesn't refer to an entity other than a type (e.g. a class member). 522 * name doesn't refer to an entity other than a type (e.g. a class member).
523 */ 523 */
524 TypeRefBuilder serializeTypeName(TypeName node, {bool allowVoid: false}) { 524 EntityRefBuilder serializeTypeName(TypeName node, {bool allowVoid: false}) {
525 TypeRefBuilder b = new TypeRefBuilder(); 525 EntityRefBuilder b = new EntityRefBuilder();
526 if (node != null) { 526 if (node != null) {
527 Identifier identifier = node.name; 527 Identifier identifier = node.name;
528 if (identifier is SimpleIdentifier) { 528 if (identifier is SimpleIdentifier) {
529 String name = identifier.name; 529 String name = identifier.name;
530 int indexOffset = 0; 530 int indexOffset = 0;
531 for (int i = scopes.length - 1; i >= 0; i--) { 531 for (int i = scopes.length - 1; i >= 0; i--) {
532 _Scope scope = scopes[i]; 532 _Scope scope = scopes[i];
533 _ScopedEntity entity = scope[name]; 533 _ScopedEntity entity = scope[name];
534 if (entity != null) { 534 if (entity != null) {
535 if (entity is _ScopedTypeParameter) { 535 if (entity is _ScopedTypeParameter) {
(...skipping 27 matching lines...) Expand all
563 } 563 }
564 if (node.typeArguments != null) { 564 if (node.typeArguments != null) {
565 // Trailing type arguments of type 'dynamic' should be omitted. 565 // Trailing type arguments of type 'dynamic' should be omitted.
566 NodeList<TypeName> args = node.typeArguments.arguments; 566 NodeList<TypeName> args = node.typeArguments.arguments;
567 int numArgsToSerialize = args.length; 567 int numArgsToSerialize = args.length;
568 while ( 568 while (
569 numArgsToSerialize > 0 && isDynamic(args[numArgsToSerialize - 1])) { 569 numArgsToSerialize > 0 && isDynamic(args[numArgsToSerialize - 1])) {
570 --numArgsToSerialize; 570 --numArgsToSerialize;
571 } 571 }
572 if (numArgsToSerialize > 0) { 572 if (numArgsToSerialize > 0) {
573 List<TypeRefBuilder> serializedArguments = <TypeRefBuilder>[]; 573 List<EntityRefBuilder> serializedArguments = <EntityRefBuilder>[];
574 for (int i = 0; i < numArgsToSerialize; i++) { 574 for (int i = 0; i < numArgsToSerialize; i++) {
575 serializedArguments.add(serializeTypeName(args[i])); 575 serializedArguments.add(serializeTypeName(args[i]));
576 } 576 }
577 b.typeArguments = serializedArguments; 577 b.typeArguments = serializedArguments;
578 } 578 }
579 } 579 }
580 } 580 }
581 return b; 581 return b;
582 } 582 }
583 583
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
755 @override 755 @override
756 void visitFunctionTypeAlias(FunctionTypeAlias node) { 756 void visitFunctionTypeAlias(FunctionTypeAlias node) {
757 int oldScopesLength = scopes.length; 757 int oldScopesLength = scopes.length;
758 _TypeParameterScope typeParameterScope = new _TypeParameterScope(); 758 _TypeParameterScope typeParameterScope = new _TypeParameterScope();
759 scopes.add(typeParameterScope); 759 scopes.add(typeParameterScope);
760 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(); 760 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder();
761 b.name = node.name.name; 761 b.name = node.name.name;
762 b.nameOffset = node.name.offset; 762 b.nameOffset = node.name.offset;
763 b.typeParameters = 763 b.typeParameters =
764 serializeTypeParameters(node.typeParameters, typeParameterScope); 764 serializeTypeParameters(node.typeParameters, typeParameterScope);
765 TypeRefBuilder serializedReturnType = 765 EntityRefBuilder serializedReturnType =
766 serializeTypeName(node.returnType, allowVoid: true); 766 serializeTypeName(node.returnType, allowVoid: true);
767 if (serializedReturnType != null) { 767 if (serializedReturnType != null) {
768 b.returnType = serializedReturnType; 768 b.returnType = serializedReturnType;
769 } 769 }
770 b.parameters = node.parameters.parameters 770 b.parameters = node.parameters.parameters
771 .map((FormalParameter p) => p.accept(this)) 771 .map((FormalParameter p) => p.accept(this))
772 .toList(); 772 .toList();
773 b.documentationComment = serializeDocumentation(node.documentationComment); 773 b.documentationComment = serializeDocumentation(node.documentationComment);
774 typedefs.add(b); 774 typedefs.add(b);
775 scopes.removeLast(); 775 scopes.removeLast();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 /** 875 /**
876 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. 876 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s.
877 */ 877 */
878 class _TypeParameterScope extends _Scope { 878 class _TypeParameterScope extends _Scope {
879 /** 879 /**
880 * Get the number of [_ScopedTypeParameter]s defined in this 880 * Get the number of [_ScopedTypeParameter]s defined in this
881 * [_TypeParameterScope]. 881 * [_TypeParameterScope].
882 */ 882 */
883 int get length => _definedNames.length; 883 int get length => _definedNames.length;
884 } 884 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698