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

Side by Side Diff: pkg/compiler/lib/src/elements/modelx.dart

Issue 1881013002: Expand ResolvedAst to handle synthetic constructors. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: dartfmt Created 4 years, 8 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 | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/id_generator.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 elements.modelx; 5 library elements.modelx;
6 6
7 import '../common.dart'; 7 import '../common.dart';
8 import '../common/resolution.dart' show Resolution, Parsing; 8 import '../common/resolution.dart' show Resolution, Parsing;
9 import '../compiler.dart' show Compiler; 9 import '../compiler.dart' show Compiler;
10 import '../constants/constant_constructors.dart'; 10 import '../constants/constant_constructors.dart';
(...skipping 2337 matching lines...) Expand 10 before | Expand all | Expand 10 after
2348 FunctionExpression parseNode(Parsing parsing) => null; 2348 FunctionExpression parseNode(Parsing parsing) => null;
2349 2349
2350 bool get hasNode => false; 2350 bool get hasNode => false;
2351 2351
2352 FunctionExpression get node => null; 2352 FunctionExpression get node => null;
2353 2353
2354 Token get position => enclosingElement.position; 2354 Token get position => enclosingElement.position;
2355 2355
2356 bool get isSynthesized => true; 2356 bool get isSynthesized => true;
2357 2357
2358 bool get hasResolvedAst => true;
2359
2360 ResolvedAst get resolvedAst {
2361 return new SynthesizedResolvedAst(
2362 this,
2363 isDefaultConstructor
2364 ? ResolvedAstKind.DEFAULT_CONSTRUCTOR
2365 : ResolvedAstKind.FORWARDING_CONSTRUCTOR);
2366 }
2367
2358 DartType get type { 2368 DartType get type {
2359 if (isDefaultConstructor) { 2369 if (isDefaultConstructor) {
2360 return super.type; 2370 return super.type;
2361 } else { 2371 } else {
2362 // TODO(johnniwinther): Ensure that the function type substitutes type 2372 // TODO(johnniwinther): Ensure that the function type substitutes type
2363 // variables correctly. 2373 // variables correctly.
2364 return definingConstructor.type; 2374 return definingConstructor.type;
2365 } 2375 }
2366 } 2376 }
2367 2377
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
2687 if (origin != null) { 2697 if (origin != null) {
2688 return 'patch ${super.toString()}'; 2698 return 'patch ${super.toString()}';
2689 } else if (patch != null) { 2699 } else if (patch != null) {
2690 return 'origin ${super.toString()}'; 2700 return 'origin ${super.toString()}';
2691 } else { 2701 } else {
2692 return super.toString(); 2702 return super.toString();
2693 } 2703 }
2694 } 2704 }
2695 } 2705 }
2696 2706
2707 /// This element is used to encode an enum class.
Johnni Winther 2016/04/12 13:59:19 Comments add per request in previous CL.
2708 ///
2709 /// For instance
2710 ///
2711 /// enum A { b, c, }
2712 ///
2713 /// is modelled as
2714 ///
2715 /// class A {
2716 /// final int index;
2717 ///
2718 /// const A(this.index);
2719 ///
2720 /// String toString() {
2721 /// return const <int, A>{0: 'A.b', 1: 'A.c'}[index];
2722 /// }
2723 ///
2724 /// static const A b = const A(0);
2725 /// static const A c = const A(1);
2726 ///
2727 /// static const List<A> values = const <A>[b, c];
2728 /// }
2729 ///
2730 /// where the `A` class is encoded using this element.
2731 ///
2697 class EnumClassElementX extends ClassElementX 2732 class EnumClassElementX extends ClassElementX
2698 implements EnumClassElement, DeclarationSite { 2733 implements EnumClassElement, DeclarationSite {
2699 final Enum node; 2734 final Enum node;
2700 List<FieldElement> _enumValues; 2735 List<FieldElement> _enumValues;
2701 2736
2702 EnumClassElementX(String name, Element enclosing, int id, this.node) 2737 EnumClassElementX(String name, Element enclosing, int id, this.node)
2703 : super(name, enclosing, id, STATE_NOT_STARTED); 2738 : super(name, enclosing, id, STATE_NOT_STARTED);
2704 2739
2705 @override 2740 @override
2706 bool get hasNode => true; 2741 bool get hasNode => true;
(...skipping 23 matching lines...) Expand all
2730 void set enumValues(List<FieldElement> values) { 2765 void set enumValues(List<FieldElement> values) {
2731 assert(invariant(this, _enumValues == null, 2766 assert(invariant(this, _enumValues == null,
2732 message: "enumValues has already been computed for $this.")); 2767 message: "enumValues has already been computed for $this."));
2733 _enumValues = values; 2768 _enumValues = values;
2734 } 2769 }
2735 2770
2736 @override 2771 @override
2737 DeclarationSite get declarationSite => this; 2772 DeclarationSite get declarationSite => this;
2738 } 2773 }
2739 2774
2775 /// This element is used to encode the implicit constructor in an enum class.
2776 ///
2777 /// For instance
2778 ///
2779 /// enum A { b, c, }
2780 ///
2781 /// is modelled as
2782 ///
2783 /// class A {
2784 /// final int index;
2785 ///
2786 /// const A(this.index);
2787 ///
2788 /// String toString() {
2789 /// return const <int, A>{0: 'A.b', 1: 'A.c'}[index];
2790 /// }
2791 ///
2792 /// static const A b = const A(0);
2793 /// static const A c = const A(1);
2794 ///
2795 /// static const List<A> values = const <A>[b, c];
2796 /// }
2797 ///
2798 /// where the `const A(...)` constructor is encoded using this element.
2799 ///
2740 class EnumConstructorElementX extends ConstructorElementX { 2800 class EnumConstructorElementX extends ConstructorElementX {
2741 final FunctionExpression node; 2801 final FunctionExpression node;
2742 2802
2743 EnumConstructorElementX( 2803 EnumConstructorElementX(
2744 EnumClassElementX enumClass, Modifiers modifiers, this.node) 2804 EnumClassElementX enumClass, Modifiers modifiers, this.node)
2745 : super( 2805 : super(
2746 '', // Name. 2806 '', // Name.
2747 ElementKind.GENERATIVE_CONSTRUCTOR, 2807 ElementKind.GENERATIVE_CONSTRUCTOR,
2748 modifiers, 2808 modifiers,
2749 enumClass); 2809 enumClass);
2750 2810
2751 @override 2811 @override
2752 bool get hasNode => true; 2812 bool get hasNode => true;
2753 2813
2754 @override 2814 @override
2755 FunctionExpression parseNode(Parsing parsing) => node; 2815 FunctionExpression parseNode(Parsing parsing) => node;
2756 2816
2757 @override 2817 @override
2758 SourceSpan get sourcePosition => enclosingClass.sourcePosition; 2818 SourceSpan get sourcePosition => enclosingClass.sourcePosition;
2759 } 2819 }
2760 2820
2821 /// This element is used to encode the implicit methods in an enum class.
2822 ///
2823 /// For instance
2824 ///
2825 /// enum A { b, c, }
2826 ///
2827 /// is modelled as
2828 ///
2829 /// class A {
2830 /// final int index;
2831 ///
2832 /// const A(this.index);
2833 ///
2834 /// String toString() {
2835 /// return const <int, A>{0: 'A.b', 1: 'A.c'}[index];
2836 /// }
2837 ///
2838 /// static const A b = const A(0);
2839 /// static const A c = const A(1);
2840 ///
2841 /// static const List<A> values = const <A>[b, c];
2842 /// }
2843 ///
2844 /// where the `toString` method is encoded using this element.
2845 ///
2761 class EnumMethodElementX extends MethodElementX { 2846 class EnumMethodElementX extends MethodElementX {
2762 final FunctionExpression node; 2847 final FunctionExpression node;
2763 2848
2764 EnumMethodElementX( 2849 EnumMethodElementX(
2765 String name, EnumClassElementX enumClass, Modifiers modifiers, this.node) 2850 String name, EnumClassElementX enumClass, Modifiers modifiers, this.node)
2766 : super(name, ElementKind.FUNCTION, modifiers, enumClass, true); 2851 : super(name, ElementKind.FUNCTION, modifiers, enumClass, true);
2767 2852
2768 @override 2853 @override
2769 bool get hasNode => true; 2854 bool get hasNode => true;
2770 2855
2771 @override 2856 @override
2772 FunctionExpression parseNode(Parsing parsing) => node; 2857 FunctionExpression parseNode(Parsing parsing) => node;
2773 2858
2774 @override 2859 @override
2775 SourceSpan get sourcePosition => enclosingClass.sourcePosition; 2860 SourceSpan get sourcePosition => enclosingClass.sourcePosition;
2776 } 2861 }
2777 2862
2863 /// This element is used to encode the initializing formal of the implicit
2864 /// constructor in an enum class.
2865 ///
2866 /// For instance
2867 ///
2868 /// enum A { b, c, }
2869 ///
2870 /// is modelled as
2871 ///
2872 /// class A {
2873 /// final int index;
2874 ///
2875 /// const A(this.index);
2876 ///
2877 /// String toString() {
2878 /// return const <int, A>{0: 'A.b', 1: 'A.c'}[index];
2879 /// }
2880 ///
2881 /// static const A b = const A(0);
2882 /// static const A c = const A(1);
2883 ///
2884 /// static const List<A> values = const <A>[b, c];
2885 /// }
2886 ///
2887 /// where the `this.index` formal is encoded using this element.
2888 ///
2778 class EnumFormalElementX extends InitializingFormalElementX { 2889 class EnumFormalElementX extends InitializingFormalElementX {
2779 EnumFormalElementX( 2890 EnumFormalElementX(
2780 ConstructorElement constructor, 2891 ConstructorElement constructor,
2781 VariableDefinitions variables, 2892 VariableDefinitions variables,
2782 Identifier identifier, 2893 Identifier identifier,
2783 EnumFieldElementX fieldElement) 2894 EnumFieldElementX fieldElement)
2784 : super(constructor, variables, identifier, null, fieldElement) { 2895 : super(constructor, variables, identifier, null, fieldElement) {
2785 typeCache = fieldElement.type; 2896 typeCache = fieldElement.type;
2786 } 2897 }
2787 2898
2788 @override 2899 @override
2789 SourceSpan get sourcePosition => enclosingClass.sourcePosition; 2900 SourceSpan get sourcePosition => enclosingClass.sourcePosition;
2790 } 2901 }
2791 2902
2903 /// This element is used to encode the implicitly fields in an enum class.
2904 ///
2905 /// For instance
2906 ///
2907 /// enum A { b, c, }
2908 ///
2909 /// is modelled as
2910 ///
2911 /// class A {
2912 /// final int index;
2913 ///
2914 /// const A(this.index);
2915 ///
2916 /// String toString() {
2917 /// return const <int, A>{0: 'A.b', 1: 'A.c'}[index];
2918 /// }
2919 ///
2920 /// static const A b = const A(0);
2921 /// static const A c = const A(1);
2922 ///
2923 /// static const List<A> values = const <A>[b, c];
2924 /// }
2925 ///
2926 /// where the `index` and `values` fields are encoded using this element.
2927 ///
2792 class EnumFieldElementX extends FieldElementX { 2928 class EnumFieldElementX extends FieldElementX {
2793 EnumFieldElementX(Identifier name, EnumClassElementX enumClass, 2929 EnumFieldElementX(Identifier name, EnumClassElementX enumClass,
2794 VariableList variableList, Node definition, 2930 VariableList variableList, Node definition,
2795 [Expression initializer]) 2931 [Expression initializer])
2796 : super(name, enumClass, variableList) { 2932 : super(name, enumClass, variableList) {
2797 definitionsCache = new VariableDefinitions( 2933 definitionsCache = new VariableDefinitions(
2798 null, variableList.modifiers, new NodeList.singleton(definition)); 2934 null, variableList.modifiers, new NodeList.singleton(definition));
2799 initializerCache = initializer; 2935 initializerCache = initializer;
2800 } 2936 }
2801 2937
2802 @override 2938 @override
2803 SourceSpan get sourcePosition => enclosingClass.sourcePosition; 2939 SourceSpan get sourcePosition => enclosingClass.sourcePosition;
2804 } 2940 }
2805 2941
2942 /// This element is used to encode the constant value in an enum class.
2943 ///
2944 /// For instance
2945 ///
2946 /// enum A { b, c, }
2947 ///
2948 /// is modelled as
2949 ///
2950 /// class A {
2951 /// final int index;
2952 ///
2953 /// const A(this.index);
2954 ///
2955 /// String toString() {
2956 /// return const <int, A>{0: 'A.b', 1: 'A.c'}[index];
2957 /// }
2958 ///
2959 /// static const A b = const A(0);
2960 /// static const A c = const A(1);
2961 ///
2962 /// static const List<A> values = const <A>[b, c];
2963 /// }
2964 ///
2965 /// where the `b` and `c` fields are encoded using this element.
2966 ///
2806 class EnumConstantElementX extends EnumFieldElementX 2967 class EnumConstantElementX extends EnumFieldElementX
2807 implements EnumConstantElement { 2968 implements EnumConstantElement {
2808 final int index; 2969 final int index;
2809 2970
2810 EnumConstantElementX( 2971 EnumConstantElementX(
2811 Identifier name, 2972 Identifier name,
2812 EnumClassElementX enumClass, 2973 EnumClassElementX enumClass,
2813 VariableList variableList, 2974 VariableList variableList,
2814 Node definition, 2975 Node definition,
2815 Expression initializer, 2976 Expression initializer,
2816 this.index) 2977 this.index)
2817 : super(name, enumClass, variableList, definition, initializer); 2978 : super(name, enumClass, variableList, definition, initializer);
2818 2979
2819 @override 2980 @override
2820 SourceSpan get sourcePosition { 2981 SourceSpan get sourcePosition {
2821 return new SourceSpan( 2982 return new SourceSpan(enclosingClass.sourcePosition.uri,
2822 enclosingClass.sourcePosition.uri,
2823 position.charOffset, position.charEnd); 2983 position.charOffset, position.charEnd);
2824 } 2984 }
2825 } 2985 }
2826 2986
2827 abstract class MixinApplicationElementX extends BaseClassElementX 2987 abstract class MixinApplicationElementX extends BaseClassElementX
2828 with MixinApplicationElementCommon 2988 with MixinApplicationElementCommon
2829 implements MixinApplicationElement { 2989 implements MixinApplicationElement {
2830 Link<ConstructorElement> constructors = new Link<ConstructorElement>(); 2990 Link<ConstructorElement> constructors = new Link<ConstructorElement>();
2831 2991
2832 InterfaceType mixinType; 2992 InterfaceType mixinType;
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
3119 /// found through [declaration] since its node define the inheritance relation 3279 /// found through [declaration] since its node define the inheritance relation
3120 /// for the class. For unpatched elements the defining element is the element 3280 /// for the class. For unpatched elements the defining element is the element
3121 /// itself. 3281 /// itself.
3122 AstElement get definingElement; 3282 AstElement get definingElement;
3123 3283
3124 bool get hasResolvedAst { 3284 bool get hasResolvedAst {
3125 return definingElement.hasNode && definingElement.hasTreeElements; 3285 return definingElement.hasNode && definingElement.hasTreeElements;
3126 } 3286 }
3127 3287
3128 ResolvedAst get resolvedAst { 3288 ResolvedAst get resolvedAst {
3129 return new ResolvedAst( 3289 return new ParsedResolvedAst(
3130 declaration, definingElement.node, definingElement.treeElements); 3290 declaration, definingElement.node, definingElement.treeElements);
3131 } 3291 }
3132 } 3292 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/elements/elements.dart ('k') | pkg/compiler/lib/src/id_generator.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698