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

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

Issue 1957973002: Fix AST-based type inference of enum types. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 /** 5 /**
6 * This library is capable of producing linked summaries from unlinked 6 * This library is capable of producing linked summaries from unlinked
7 * ones (or prelinked ones). It functions by building a miniature 7 * ones (or prelinked ones). It functions by building a miniature
8 * element model to represent the contents of the summaries, and then 8 * element model to represent the contents of the summaries, and then
9 * scanning the element model to gather linked information and adding 9 * scanning the element model to gather linked information and adding
10 * it to the summary data structures. 10 * it to the summary data structures.
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 List<MethodElementForLink> _methods; 425 List<MethodElementForLink> _methods;
426 List<InterfaceType> _mixins; 426 List<InterfaceType> _mixins;
427 List<InterfaceType> _interfaces; 427 List<InterfaceType> _interfaces;
428 List<PropertyAccessorElementForLink> _accessors; 428 List<PropertyAccessorElementForLink> _accessors;
429 429
430 ClassElementForLink_Class( 430 ClassElementForLink_Class(
431 CompilationUnitElementForLink enclosingElement, this._unlinkedClass) 431 CompilationUnitElementForLink enclosingElement, this._unlinkedClass)
432 : super(enclosingElement); 432 : super(enclosingElement);
433 433
434 @override 434 @override
435 List<PropertyAccessorElement> get accessors { 435 List<PropertyAccessorElementForLink> get accessors {
436 if (_accessors == null) { 436 if (_accessors == null) {
437 _accessors = <PropertyAccessorElementForLink>[]; 437 _accessors = <PropertyAccessorElementForLink>[];
438 Map<String, SyntheticVariableElementForLink> syntheticVariables = 438 Map<String, SyntheticVariableElementForLink> syntheticVariables =
439 <String, SyntheticVariableElementForLink>{}; 439 <String, SyntheticVariableElementForLink>{};
440 for (UnlinkedExecutable unlinkedExecutable 440 for (UnlinkedExecutable unlinkedExecutable
441 in _unlinkedClass.executables) { 441 in _unlinkedClass.executables) {
442 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter || 442 if (unlinkedExecutable.kind == UnlinkedExecutableKind.getter ||
443 unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { 443 unlinkedExecutable.kind == UnlinkedExecutableKind.setter) {
444 String name = unlinkedExecutable.name; 444 String name = unlinkedExecutable.name;
445 if (unlinkedExecutable.kind == UnlinkedExecutableKind.setter) { 445 if (unlinkedExecutable.kind == UnlinkedExecutableKind.setter) {
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 * linking. 657 * linking.
658 */ 658 */
659 class ClassElementForLink_Enum extends ClassElementForLink { 659 class ClassElementForLink_Enum extends ClassElementForLink {
660 /** 660 /**
661 * The unlinked representation of the enum in the summary. 661 * The unlinked representation of the enum in the summary.
662 */ 662 */
663 final UnlinkedEnum _unlinkedEnum; 663 final UnlinkedEnum _unlinkedEnum;
664 664
665 InterfaceType _type; 665 InterfaceType _type;
666 List<FieldElementForLink_EnumField> _fields; 666 List<FieldElementForLink_EnumField> _fields;
667 List<PropertyAccessorElementForLink> _accessors;
668 DartType _valuesType;
667 669
668 ClassElementForLink_Enum( 670 ClassElementForLink_Enum(
669 CompilationUnitElementForLink enclosingElement, this._unlinkedEnum) 671 CompilationUnitElementForLink enclosingElement, this._unlinkedEnum)
670 : super(enclosingElement); 672 : super(enclosingElement);
671 673
672 @override 674 @override
673 List<PropertyAccessorElement> get accessors { 675 List<PropertyAccessorElementForLink> get accessors {
674 // TODO(paulberry): do we need to include synthetic accessors? 676 if (_accessors == null) {
675 return const []; 677 _accessors = <PropertyAccessorElementForLink>[];
678 for (FieldElementForLink_EnumField field in fields) {
679 _accessors.add(field.getter);
680 }
681 }
682 return _accessors;
676 } 683 }
677 684
678 @override 685 @override
679 List<ConstructorElementForLink> get constructors => const []; 686 List<ConstructorElementForLink> get constructors => const [];
680 687
681 @override 688 @override
682 String get displayName => _unlinkedEnum.name; 689 String get displayName => _unlinkedEnum.name;
683 690
684 @override 691 @override
685 List<FieldElementForLink_EnumField> get fields { 692 List<FieldElementForLink_EnumField> get fields {
(...skipping 27 matching lines...) Expand all
713 720
714 @override 721 @override
715 DartType get type => _type ??= new InterfaceTypeImpl(this); 722 DartType get type => _type ??= new InterfaceTypeImpl(this);
716 723
717 @override 724 @override
718 List<TypeParameterElement> get typeParameters => const []; 725 List<TypeParameterElement> get typeParameters => const [];
719 726
720 @override 727 @override
721 ConstructorElementForLink get unnamedConstructor => null; 728 ConstructorElementForLink get unnamedConstructor => null;
722 729
730 /**
731 * Get the type of the enum's static member `values`.
732 */
733 DartType get valuesType =>
734 _valuesType ??= library._linker.typeProvider.listType.instantiate([type]);
735
723 @override 736 @override
724 DartType buildType(DartType getTypeArgument(int i), 737 DartType buildType(DartType getTypeArgument(int i),
725 List<int> implicitFunctionTypeIndices) => 738 List<int> implicitFunctionTypeIndices) =>
726 type; 739 type;
727 740
728 @override 741 @override
729 void link(CompilationUnitElementInBuildUnit compilationUnit) {} 742 void link(CompilationUnitElementInBuildUnit compilationUnit) {}
730 743
731 @override 744 @override
732 String toString() => '$enclosingElement.$name'; 745 String toString() => '$enclosingElement.$name';
(...skipping 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after
2565 * Specialization of [FieldElementForLink] for enum fields. 2578 * Specialization of [FieldElementForLink] for enum fields.
2566 */ 2579 */
2567 class FieldElementForLink_EnumField extends FieldElementForLink 2580 class FieldElementForLink_EnumField extends FieldElementForLink
2568 implements FieldElement { 2581 implements FieldElement {
2569 /** 2582 /**
2570 * The unlinked representation of the field in the summary, or `null` if this 2583 * The unlinked representation of the field in the summary, or `null` if this
2571 * is an enum's `values` field. 2584 * is an enum's `values` field.
2572 */ 2585 */
2573 final UnlinkedEnumValue unlinkedEnumValue; 2586 final UnlinkedEnumValue unlinkedEnumValue;
2574 2587
2588 PropertyAccessorElementForLink_EnumField _getter;
2589
2575 @override 2590 @override
2576 final ClassElementForLink_Enum enclosingElement; 2591 final ClassElementForLink_Enum enclosingElement;
2577 2592
2578 FieldElementForLink_EnumField(this.unlinkedEnumValue, this.enclosingElement); 2593 FieldElementForLink_EnumField(this.unlinkedEnumValue, this.enclosingElement);
2579 2594
2580 @override 2595 @override
2596 PropertyAccessorElementForLink_EnumField get getter =>
2597 _getter ??= new PropertyAccessorElementForLink_EnumField(this);
2598
2599 @override
2581 bool get isStatic => true; 2600 bool get isStatic => true;
2582 2601
2583 @override 2602 @override
2584 bool get isSynthetic => false; 2603 bool get isSynthetic => false;
2585 2604
2586 @override 2605 @override
2587 String get name => 2606 String get name =>
2588 unlinkedEnumValue == null ? 'values' : unlinkedEnumValue.name; 2607 unlinkedEnumValue == null ? 'values' : unlinkedEnumValue.name;
2589 2608
2590 @override 2609 @override
2610 DartType get type => unlinkedEnumValue == null
2611 ? enclosingElement.valuesType
2612 : enclosingElement.type;
2613
2614 @override
2591 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 2615 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
2592 2616
2593 @override 2617 @override
2594 String toString() => '$enclosingElement.$name'; 2618 String toString() => '$enclosingElement.$name';
2595 } 2619 }
2596 2620
2597 /** 2621 /**
2598 * Element representing a function-typed parameter resynthesied from a summary 2622 * Element representing a function-typed parameter resynthesied from a summary
2599 * during linking. 2623 * during linking.
2600 */ 2624 */
(...skipping 1067 matching lines...) Expand 10 before | Expand all | Expand 10 after
3668 /** 3692 /**
3669 * Element representing a getter or setter resynthesized from a summary during 3693 * Element representing a getter or setter resynthesized from a summary during
3670 * linking. 3694 * linking.
3671 */ 3695 */
3672 abstract class PropertyAccessorElementForLink 3696 abstract class PropertyAccessorElementForLink
3673 implements PropertyAccessorElementImpl, ReferenceableElementForLink { 3697 implements PropertyAccessorElementImpl, ReferenceableElementForLink {
3674 void link(CompilationUnitElementInBuildUnit compilationUnit); 3698 void link(CompilationUnitElementInBuildUnit compilationUnit);
3675 } 3699 }
3676 3700
3677 /** 3701 /**
3702 * Specialization of [PropertyAccessorElementForLink] for synthetic accessors
3703 * implied by the synthetic fields of an enum declaration.
3704 */
3705 class PropertyAccessorElementForLink_EnumField
3706 implements PropertyAccessorElementForLink {
3707 @override
3708 final FieldElementForLink_EnumField variable;
3709
3710 FunctionTypeImpl _type;
3711
3712 PropertyAccessorElementForLink_EnumField(this.variable);
3713
3714 @override
3715 ConstructorElementForLink get asConstructor => null;
3716
3717 @override
3718 ConstVariableNode get asConstVariable => null;
3719
3720 @override
3721 DartType get asStaticType => returnType;
3722
3723 @override
3724 TypeInferenceNode get asTypeInferenceNode => null;
3725
3726 @override
3727 Element get enclosingElement => variable.enclosingElement;
3728
3729 @override
3730 bool get isGetter => true;
3731
3732 @override
3733 bool get isSetter => false;
3734
3735 @override
3736 bool get isStatic => variable.isStatic;
3737
3738 @override
3739 bool get isSynthetic => true;
3740
3741 @override
3742 ElementKind get kind => ElementKind.GETTER;
3743
3744 @override
3745 LibraryElementForLink get library =>
3746 variable.enclosingElement.enclosingElement.enclosingElement;
3747
3748 @override
3749 String get name => variable.name;
3750
3751 @override
3752 List<ParameterElement> get parameters => const [];
3753
3754 @override
3755 DartType get returnType => variable.type;
3756
3757 @override
3758 FunctionTypeImpl get type => _type ??= new FunctionTypeImpl(this);
3759
3760 @override
3761 List<TypeParameterElement> get typeParameters => const [];
3762
3763 @override
3764 DartType buildType(DartType getTypeArgument(int i),
3765 List<int> implicitFunctionTypeIndices) =>
3766 DynamicTypeImpl.instance;
3767
3768 @override
3769 ReferenceableElementForLink getContainedName(String name) {
3770 return new NonstaticMemberElementForLink(library, this, name);
3771 }
3772
3773 @override
3774 bool isAccessibleIn(LibraryElement library) =>
3775 !Identifier.isPrivateName(name) || identical(this.library, library);
3776
3777 @override
3778 void link(CompilationUnitElementInBuildUnit compilationUnit) {}
3779
3780 @override
3781 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
3782
3783 @override
3784 String toString() => '$enclosingElement.$name';
3785 }
3786
3787 /**
3678 * Specialization of [PropertyAccessorElementForLink] for non-synthetic 3788 * Specialization of [PropertyAccessorElementForLink] for non-synthetic
3679 * accessors explicitly declared in the source code. 3789 * accessors explicitly declared in the source code.
3680 */ 3790 */
3681 class PropertyAccessorElementForLink_Executable extends ExecutableElementForLink 3791 class PropertyAccessorElementForLink_Executable extends ExecutableElementForLink
3682 implements PropertyAccessorElementForLink { 3792 implements PropertyAccessorElementForLink {
3683 @override 3793 @override
3684 SyntheticVariableElementForLink variable; 3794 SyntheticVariableElementForLink variable;
3685 3795
3686 PropertyAccessorElementForLink_Executable( 3796 PropertyAccessorElementForLink_Executable(
3687 CompilationUnitElementForLink enclosingUnit, 3797 CompilationUnitElementForLink enclosingUnit,
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after
4620 * there are no type parameters in scope. 4730 * there are no type parameters in scope.
4621 */ 4731 */
4622 TypeParameterizedElementForLink get _typeParameterContext; 4732 TypeParameterizedElementForLink get _typeParameterContext;
4623 4733
4624 @override 4734 @override
4625 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); 4735 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
4626 4736
4627 @override 4737 @override
4628 String toString() => '$enclosingElement.$name'; 4738 String toString() => '$enclosingElement.$name';
4629 } 4739 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/src/task/strong/inferred_type_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698