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

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

Issue 1621763002: Use the explicit string 'dynamic' to refer to dynamic in summaries. (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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 501
502 /** 502 /**
503 * Serialize a reference to a top level name declared elsewhere, by adding an 503 * Serialize a reference to a top level name declared elsewhere, by adding an
504 * entry to the references table if necessary. If [prefixIndex] is not null, 504 * entry to the references table if necessary. If [prefixIndex] is not null,
505 * the reference is associated with the prefix having the given index in the 505 * the reference is associated with the prefix having the given index in the
506 * references table. 506 * references table.
507 */ 507 */
508 int serializeReference(int prefixIndex, String name) => nameToReference 508 int serializeReference(int prefixIndex, String name) => nameToReference
509 .putIfAbsent(prefixIndex, () => <String, int>{}) 509 .putIfAbsent(prefixIndex, () => <String, int>{})
510 .putIfAbsent(name, () { 510 .putIfAbsent(name, () {
511 assert(name != 'dynamic');
512 int index = unlinkedReferences.length; 511 int index = unlinkedReferences.length;
513 unlinkedReferences.add(new UnlinkedReferenceBuilder( 512 unlinkedReferences.add(new UnlinkedReferenceBuilder(
514 prefixReference: prefixIndex, name: name)); 513 prefixReference: prefixIndex, name: name));
515 return index; 514 return index;
516 }); 515 });
517 516
518 /** 517 /**
519 * Serialize a type name (which might be defined in a nested scope, at top 518 * 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 519 * level within this library, or at top level within an imported library) to
521 * a [EntityRef]. Note that this method does the right thing if the 520 * 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). 521 * name doesn't refer to an entity other than a type (e.g. a class member).
523 */ 522 */
524 EntityRefBuilder serializeTypeName(TypeName node, {bool allowVoid: false}) { 523 EntityRefBuilder serializeTypeName(TypeName node, {bool allowVoid: false}) {
525 EntityRefBuilder b = new EntityRefBuilder(); 524 EntityRefBuilder b = new EntityRefBuilder();
526 if (node != null) { 525 if (node == null) {
526 b.reference = serializeReference(null, 'dynamic');
527 } else {
527 Identifier identifier = node.name; 528 Identifier identifier = node.name;
528 if (identifier is SimpleIdentifier) { 529 if (identifier is SimpleIdentifier) {
529 String name = identifier.name; 530 String name = identifier.name;
530 int indexOffset = 0; 531 int indexOffset = 0;
531 for (int i = scopes.length - 1; i >= 0; i--) { 532 for (int i = scopes.length - 1; i >= 0; i--) {
532 _Scope scope = scopes[i]; 533 _Scope scope = scopes[i];
533 _ScopedEntity entity = scope[name]; 534 _ScopedEntity entity = scope[name];
534 if (entity != null) { 535 if (entity != null) {
535 if (entity is _ScopedTypeParameter) { 536 if (entity is _ScopedTypeParameter) {
536 b.paramReference = indexOffset + entity.index; 537 b.paramReference = indexOffset + entity.index;
537 return b; 538 return b;
538 } else { 539 } else {
539 // None of the other things that can be declared in local scopes 540 // None of the other things that can be declared in local scopes
540 // are types, so this is an error and should be treated as a 541 // are types, so this is an error and should be treated as a
541 // reference to `dynamic`. 542 // reference to `dynamic`.
543 b.reference = serializeReference(null, 'dynamic');
542 return b; 544 return b;
543 } 545 }
544 } 546 }
545 if (scope is _TypeParameterScope) { 547 if (scope is _TypeParameterScope) {
546 indexOffset += scope.length; 548 indexOffset += scope.length;
547 } 549 }
548 } 550 }
549 if (allowVoid && name == 'void') { 551 if (allowVoid && name == 'void') {
550 return null; 552 return null;
551 } 553 }
552 if (name != 'dynamic') { 554 b.reference = serializeReference(null, name);
553 b.reference = serializeReference(null, name);
554 }
555 } else if (identifier is PrefixedIdentifier) { 555 } else if (identifier is PrefixedIdentifier) {
556 int prefixIndex = prefixIndices.putIfAbsent(identifier.prefix.name, 556 int prefixIndex = prefixIndices.putIfAbsent(identifier.prefix.name,
557 () => serializeReference(null, identifier.prefix.name)); 557 () => serializeReference(null, identifier.prefix.name));
558 b.reference = 558 b.reference =
559 serializeReference(prefixIndex, identifier.identifier.name); 559 serializeReference(prefixIndex, identifier.identifier.name);
560 } else { 560 } else {
561 throw new StateError( 561 throw new StateError(
562 'Unexpected identifier type: ${identifier.runtimeType}'); 562 'Unexpected identifier type: ${identifier.runtimeType}');
563 } 563 }
564 if (node.typeArguments != null) { 564 if (node.typeArguments != null) {
(...skipping 310 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
« no previous file with comments | « pkg/analyzer/lib/src/summary/resynthesize.dart ('k') | pkg/analyzer/lib/src/summary/summarize_elements.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698