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

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

Issue 1610003002: Rename UnlinkedTypeRef to TypeRef. (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 UnlinkedTypeRefBuilder serializeIdentifier(Identifier identifier) { 31 TypeRefBuilder serializeIdentifier(Identifier identifier) {
32 UnlinkedTypeRefBuilder b = new UnlinkedTypeRefBuilder(); 32 TypeRefBuilder b = new TypeRefBuilder();
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 UnlinkedTypeRefBuilder serializeType(TypeName node) { 47 TypeRefBuilder 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 assert(scopes.length == oldScopesLength); 448 assert(scopes.length == oldScopesLength);
449 return b; 449 return b;
450 } 450 }
451 451
452 /** 452 /**
453 * Serialize the return type and parameters of a function-typed formal 453 * Serialize the return type and parameters of a function-typed formal
454 * parameter and store them in [b]. 454 * parameter and store them in [b].
455 */ 455 */
456 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b, 456 void serializeFunctionTypedParameterDetails(UnlinkedParamBuilder b,
457 TypeName returnType, FormalParameterList parameters) { 457 TypeName returnType, FormalParameterList parameters) {
458 UnlinkedTypeRefBuilder serializedReturnType = 458 TypeRefBuilder serializedReturnType =
459 serializeTypeName(returnType, allowVoid: true); 459 serializeTypeName(returnType, allowVoid: true);
460 if (serializedReturnType != null) { 460 if (serializedReturnType != null) {
461 b.type = serializedReturnType; 461 b.type = serializedReturnType;
462 } 462 }
463 b.parameters = parameters.parameters 463 b.parameters = parameters.parameters
464 .map((FormalParameter p) => p.accept(this)) 464 .map((FormalParameter p) => p.accept(this))
465 .toList(); 465 .toList();
466 } 466 }
467 467
468 /** 468 /**
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 assert(name != 'dynamic'); 501 assert(name != 'dynamic');
502 int index = unlinkedReferences.length; 502 int index = unlinkedReferences.length;
503 unlinkedReferences.add(new UnlinkedReferenceBuilder( 503 unlinkedReferences.add(new UnlinkedReferenceBuilder(
504 prefixReference: prefixIndex, name: name)); 504 prefixReference: prefixIndex, name: name));
505 return index; 505 return index;
506 }); 506 });
507 507
508 /** 508 /**
509 * Serialize a type name (which might be defined in a nested scope, at top 509 * Serialize a type name (which might be defined in a nested scope, at top
510 * level within this library, or at top level within an imported library) to 510 * level within this library, or at top level within an imported library) to
511 * an [UnlinkedTypeRef]. Note that this method does the right thing if the 511 * a [TypeRef]. Note that this method does the right thing if the
512 * name doesn't refer to an entity other than a type (e.g. a class member). 512 * name doesn't refer to an entity other than a type (e.g. a class member).
513 */ 513 */
514 UnlinkedTypeRefBuilder serializeTypeName(TypeName node, 514 TypeRefBuilder serializeTypeName(TypeName node, {bool allowVoid: false}) {
515 {bool allowVoid: false}) { 515 TypeRefBuilder b = new TypeRefBuilder();
516 UnlinkedTypeRefBuilder b = new UnlinkedTypeRefBuilder();
517 if (node != null) { 516 if (node != null) {
518 Identifier identifier = node.name; 517 Identifier identifier = node.name;
519 if (identifier is SimpleIdentifier) { 518 if (identifier is SimpleIdentifier) {
520 String name = identifier.name; 519 String name = identifier.name;
521 int indexOffset = 0; 520 int indexOffset = 0;
522 for (int i = scopes.length - 1; i >= 0; i--) { 521 for (int i = scopes.length - 1; i >= 0; i--) {
523 _Scope scope = scopes[i]; 522 _Scope scope = scopes[i];
524 _ScopedEntity entity = scope[name]; 523 _ScopedEntity entity = scope[name];
525 if (entity != null) { 524 if (entity != null) {
526 if (entity is _ScopedTypeParameter) { 525 if (entity is _ScopedTypeParameter) {
(...skipping 27 matching lines...) Expand all
554 } 553 }
555 if (node.typeArguments != null) { 554 if (node.typeArguments != null) {
556 // Trailing type arguments of type 'dynamic' should be omitted. 555 // Trailing type arguments of type 'dynamic' should be omitted.
557 NodeList<TypeName> args = node.typeArguments.arguments; 556 NodeList<TypeName> args = node.typeArguments.arguments;
558 int numArgsToSerialize = args.length; 557 int numArgsToSerialize = args.length;
559 while ( 558 while (
560 numArgsToSerialize > 0 && isDynamic(args[numArgsToSerialize - 1])) { 559 numArgsToSerialize > 0 && isDynamic(args[numArgsToSerialize - 1])) {
561 --numArgsToSerialize; 560 --numArgsToSerialize;
562 } 561 }
563 if (numArgsToSerialize > 0) { 562 if (numArgsToSerialize > 0) {
564 List<UnlinkedTypeRefBuilder> serializedArguments = 563 List<TypeRefBuilder> serializedArguments = <TypeRefBuilder>[];
565 <UnlinkedTypeRefBuilder>[];
566 for (int i = 0; i < numArgsToSerialize; i++) { 564 for (int i = 0; i < numArgsToSerialize; i++) {
567 serializedArguments.add(serializeTypeName(args[i])); 565 serializedArguments.add(serializeTypeName(args[i]));
568 } 566 }
569 b.typeArguments = serializedArguments; 567 b.typeArguments = serializedArguments;
570 } 568 }
571 } 569 }
572 } 570 }
573 return b; 571 return b;
574 } 572 }
575 573
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 @override 741 @override
744 void visitFunctionTypeAlias(FunctionTypeAlias node) { 742 void visitFunctionTypeAlias(FunctionTypeAlias node) {
745 int oldScopesLength = scopes.length; 743 int oldScopesLength = scopes.length;
746 _TypeParameterScope typeParameterScope = new _TypeParameterScope(); 744 _TypeParameterScope typeParameterScope = new _TypeParameterScope();
747 scopes.add(typeParameterScope); 745 scopes.add(typeParameterScope);
748 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder(); 746 UnlinkedTypedefBuilder b = new UnlinkedTypedefBuilder();
749 b.name = node.name.name; 747 b.name = node.name.name;
750 b.nameOffset = node.name.offset; 748 b.nameOffset = node.name.offset;
751 b.typeParameters = 749 b.typeParameters =
752 serializeTypeParameters(node.typeParameters, typeParameterScope); 750 serializeTypeParameters(node.typeParameters, typeParameterScope);
753 UnlinkedTypeRefBuilder serializedReturnType = 751 TypeRefBuilder serializedReturnType =
754 serializeTypeName(node.returnType, allowVoid: true); 752 serializeTypeName(node.returnType, allowVoid: true);
755 if (serializedReturnType != null) { 753 if (serializedReturnType != null) {
756 b.returnType = serializedReturnType; 754 b.returnType = serializedReturnType;
757 } 755 }
758 b.parameters = node.parameters.parameters 756 b.parameters = node.parameters.parameters
759 .map((FormalParameter p) => p.accept(this)) 757 .map((FormalParameter p) => p.accept(this))
760 .toList(); 758 .toList();
761 b.documentationComment = serializeDocumentation(node.documentationComment); 759 b.documentationComment = serializeDocumentation(node.documentationComment);
762 typedefs.add(b); 760 typedefs.add(b);
763 scopes.removeLast(); 761 scopes.removeLast();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 /** 861 /**
864 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s. 862 * A [_TypeParameterScope] is a [_Scope] which defines [_ScopedTypeParameter]s.
865 */ 863 */
866 class _TypeParameterScope extends _Scope { 864 class _TypeParameterScope extends _Scope {
867 /** 865 /**
868 * Get the number of [_ScopedTypeParameter]s defined in this 866 * Get the number of [_ScopedTypeParameter]s defined in this
869 * [_TypeParameterScope]. 867 * [_TypeParameterScope].
870 */ 868 */
871 int get length => _definedNames.length; 869 int get length => _definedNames.length;
872 } 870 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/lib/src/summary/summarize_const_expr.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698