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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/resolution/members.dart

Issue 88153003: Add synthetic type variables to unnamed mixin applications. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove unneeded handling of unnamed mixin applications. Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 part of resolution; 5 part of resolution;
6 6
7 abstract class TreeElements { 7 abstract class TreeElements {
8 Element get currentElement; 8 Element get currentElement;
9 Setlet<Node> get superUses; 9 Setlet<Node> get superUses;
10 10
(...skipping 3806 matching lines...) Expand 10 before | Expand all | Expand 10 after
3817 resolveTypeVariableBounds(node.typeParameters); 3817 resolveTypeVariableBounds(node.typeParameters);
3818 3818
3819 // Setup the supertype for the element (if there is a cycle in the 3819 // Setup the supertype for the element (if there is a cycle in the
3820 // class hierarchy, it has already been set to Object). 3820 // class hierarchy, it has already been set to Object).
3821 if (element.supertype == null && node.superclass != null) { 3821 if (element.supertype == null && node.superclass != null) {
3822 MixinApplication superMixin = node.superclass.asMixinApplication(); 3822 MixinApplication superMixin = node.superclass.asMixinApplication();
3823 if (superMixin != null) { 3823 if (superMixin != null) {
3824 DartType supertype = resolveSupertype(element, superMixin.superclass); 3824 DartType supertype = resolveSupertype(element, superMixin.superclass);
3825 Link<Node> link = superMixin.mixins.nodes; 3825 Link<Node> link = superMixin.mixins.nodes;
3826 while (!link.isEmpty) { 3826 while (!link.isEmpty) {
3827 supertype = applyMixin( 3827 supertype = applyMixin(supertype, checkMixinType(link.head), link.head );
karlklose 2013/11/28 15:04:16 Long line.
Johnni Winther 2013/12/03 15:57:38 Done.
3828 supertype, checkMixinType(link.head), link.head);
3829 link = link.tail; 3828 link = link.tail;
3830 } 3829 }
3831 element.supertype = supertype; 3830 element.supertype = supertype;
3832 } else { 3831 } else {
3833 element.supertype = resolveSupertype(element, node.superclass); 3832 element.supertype = resolveSupertype(element, node.superclass);
3834 } 3833 }
3835 } 3834 }
3836 // If the super type isn't specified, we provide a default. The language 3835 // If the super type isn't specified, we provide a default. The language
3837 // specifies [Object] but the backend can pick a specific 'implementation' 3836 // specifies [Object] but the backend can pick a specific 'implementation'
3838 // of Object - the JavaScript backend chooses between Object and 3837 // of Object - the JavaScript backend chooses between Object and
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
3914 supertype = applyMixin(supertype, checkMixinType(link.head), link.head); 3913 supertype = applyMixin(supertype, checkMixinType(link.head), link.head);
3915 link = link.tail; 3914 link = link.tail;
3916 } 3915 }
3917 doApplyMixinTo(element, supertype, checkMixinType(link.head)); 3916 doApplyMixinTo(element, supertype, checkMixinType(link.head));
3918 return element.computeType(compiler); 3917 return element.computeType(compiler);
3919 } 3918 }
3920 3919
3921 DartType applyMixin(DartType supertype, DartType mixinType, Node node) { 3920 DartType applyMixin(DartType supertype, DartType mixinType, Node node) {
3922 String superName = supertype.name; 3921 String superName = supertype.name;
3923 String mixinName = mixinType.name; 3922 String mixinName = mixinType.name;
3924 ClassElement mixinApplication = new MixinApplicationElementX( 3923 MixinApplicationElementX mixinApplication = new MixinApplicationElementX(
karlklose 2013/11/28 15:04:16 Do you need the implementation (X) class here?
Johnni Winther 2013/12/03 15:57:38 Needed to call computeThisAndRawType.
3925 "${superName}+${mixinName}", 3924 "${superName}+${mixinName}",
3926 element.getCompilationUnit(), 3925 element.getCompilationUnit(),
3927 compiler.getNextFreeClassId(), 3926 compiler.getNextFreeClassId(),
3928 node, 3927 node,
3929 Modifiers.EMPTY); // TODO(kasperl): Should this be abstract? 3928 Modifiers.EMPTY); // TODO(kasperl): Should this be abstract?
3929 // Create synthetic type variables for the mixin application.
3930 LinkBuilder<DartType> typeVariablesBuilder = new LinkBuilder<DartType>();
3931 element.typeVariables.forEach((TypeVariableType type) {
3932 TypeVariableElementX typeVariableElement = new TypeVariableElementX(
3933 type.name, mixinApplication, type.element.parseNode(compiler));
3934 TypeVariableType typeVariable = new TypeVariableType(typeVariableElement);
3935 typeVariablesBuilder.addLast(typeVariable);
3936 });
3937 Link<DartType> typeVariables = typeVariablesBuilder.toLink();
3938 // Setup bounds on the synthetic type variables.
3939 Link<DartType> link = typeVariables;
3940 element.typeVariables.forEach((TypeVariableType type) {
3941 TypeVariableType typeVariable = link.head;
3942 TypeVariableElement typeVariableElement = typeVariable.element;
3943 typeVariableElement.type = typeVariable;
3944 typeVariableElement.bound =
3945 type.element.bound.subst(typeVariables, element.typeVariables);
3946 link = link.tail;
3947 });
3948 // Setup this and raw type for the mixin application.
3949 mixinApplication.computeThisAndRawType(compiler, typeVariables);
3950 // Substitute in synthetic type variables in super and mixin types.
3951 supertype = supertype.subst(typeVariables, element.typeVariables);
3952 mixinType = mixinType.subst(typeVariables, element.typeVariables);
3953
3930 doApplyMixinTo(mixinApplication, supertype, mixinType); 3954 doApplyMixinTo(mixinApplication, supertype, mixinType);
3931 mixinApplication.resolutionState = STATE_DONE; 3955 mixinApplication.resolutionState = STATE_DONE;
3932 mixinApplication.supertypeLoadState = STATE_DONE; 3956 mixinApplication.supertypeLoadState = STATE_DONE;
3933 return mixinApplication.computeType(compiler); 3957 // Replace the synthetic type variables by the original type variables in
3958 // the returning type (which should be the type actually extended).
karlklose 2013/11/28 15:04:16 'returning type' -> 'returned type'?
Johnni Winther 2013/12/03 15:57:38 Done.
3959 InterfaceType mixinThisType = mixinApplication.computeType(compiler);
3960 return mixinThisType.subst(element.typeVariables,
3961 mixinThisType.typeArguments);
3934 } 3962 }
3935 3963
3936 bool isDefaultConstructor(FunctionElement constructor) { 3964 bool isDefaultConstructor(FunctionElement constructor) {
3937 return constructor.name == '' && 3965 return constructor.name == '' &&
3938 constructor.computeSignature(compiler).parameterCount == 0; 3966 constructor.computeSignature(compiler).parameterCount == 0;
3939 } 3967 }
3940 3968
3941 FunctionElement createForwardingConstructor(FunctionElement target, 3969 FunctionElement createForwardingConstructor(FunctionElement target,
3942 ClassElement enclosing) { 3970 ClassElement enclosing) {
3943 return new SynthesizedConstructorElementX( 3971 return new SynthesizedConstructorElementX(
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
4120 interfaces = interfaces.tail) { 4148 interfaces = interfaces.tail) {
4121 addAllSupertypes(allSupertypes, interfaces.head); 4149 addAllSupertypes(allSupertypes, interfaces.head);
4122 } 4150 }
4123 allSupertypes.add(compiler, cls.computeType(compiler)); 4151 allSupertypes.add(compiler, cls.computeType(compiler));
4124 cls.allSupertypesAndSelf = allSupertypes.toTypeSet(); 4152 cls.allSupertypesAndSelf = allSupertypes.toTypeSet();
4125 } else { 4153 } else {
4126 assert(identical(cls, compiler.objectClass)); 4154 assert(identical(cls, compiler.objectClass));
4127 cls.allSupertypesAndSelf = 4155 cls.allSupertypesAndSelf =
4128 new OrderedTypeSet.singleton(cls.computeType(compiler)); 4156 new OrderedTypeSet.singleton(cls.computeType(compiler));
4129 } 4157 }
4130 } 4158 }
4131 4159
4132 /** 4160 /**
4133 * Adds [type] and all supertypes of [type] to [allSupertypes] while 4161 * Adds [type] and all supertypes of [type] to [allSupertypes] while
4134 * substituting type variables. 4162 * substituting type variables.
4135 */ 4163 */
4136 void addAllSupertypes(OrderedTypeSetBuilder allSupertypes, 4164 void addAllSupertypes(OrderedTypeSetBuilder allSupertypes,
4137 InterfaceType type) { 4165 InterfaceType type) {
4138 Link<DartType> typeArguments = type.typeArguments; 4166 Link<DartType> typeArguments = type.typeArguments;
4139 ClassElement classElement = type.element; 4167 ClassElement classElement = type.element;
4140 Link<DartType> typeVariables = classElement.typeVariables; 4168 Link<DartType> typeVariables = classElement.typeVariables;
(...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after
4740 return finishConstructorReference(visit(expression), 4768 return finishConstructorReference(visit(expression),
4741 expression, expression); 4769 expression, expression);
4742 } 4770 }
4743 } 4771 }
4744 4772
4745 /// Looks up [name] in [scope] and unwraps the result. 4773 /// Looks up [name] in [scope] and unwraps the result.
4746 Element lookupInScope(Compiler compiler, Node node, 4774 Element lookupInScope(Compiler compiler, Node node,
4747 Scope scope, String name) { 4775 Scope scope, String name) {
4748 return Elements.unwrap(scope.lookup(name), compiler, node); 4776 return Elements.unwrap(scope.lookup(name), compiler, node);
4749 } 4777 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698