| OLD | NEW |
| 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 3814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3825 resolveTypeVariableBounds(node.typeParameters); | 3825 resolveTypeVariableBounds(node.typeParameters); |
| 3826 | 3826 |
| 3827 // Setup the supertype for the element (if there is a cycle in the | 3827 // Setup the supertype for the element (if there is a cycle in the |
| 3828 // class hierarchy, it has already been set to Object). | 3828 // class hierarchy, it has already been set to Object). |
| 3829 if (element.supertype == null && node.superclass != null) { | 3829 if (element.supertype == null && node.superclass != null) { |
| 3830 MixinApplication superMixin = node.superclass.asMixinApplication(); | 3830 MixinApplication superMixin = node.superclass.asMixinApplication(); |
| 3831 if (superMixin != null) { | 3831 if (superMixin != null) { |
| 3832 DartType supertype = resolveSupertype(element, superMixin.superclass); | 3832 DartType supertype = resolveSupertype(element, superMixin.superclass); |
| 3833 Link<Node> link = superMixin.mixins.nodes; | 3833 Link<Node> link = superMixin.mixins.nodes; |
| 3834 while (!link.isEmpty) { | 3834 while (!link.isEmpty) { |
| 3835 supertype = applyMixin( | 3835 supertype = applyMixin(supertype, |
| 3836 supertype, checkMixinType(link.head), link.head); | 3836 checkMixinType(link.head), link.head); |
| 3837 link = link.tail; | 3837 link = link.tail; |
| 3838 } | 3838 } |
| 3839 element.supertype = supertype; | 3839 element.supertype = supertype; |
| 3840 } else { | 3840 } else { |
| 3841 element.supertype = resolveSupertype(element, node.superclass); | 3841 element.supertype = resolveSupertype(element, node.superclass); |
| 3842 } | 3842 } |
| 3843 } | 3843 } |
| 3844 // If the super type isn't specified, we provide a default. The language | 3844 // If the super type isn't specified, we provide a default. The language |
| 3845 // specifies [Object] but the backend can pick a specific 'implementation' | 3845 // specifies [Object] but the backend can pick a specific 'implementation' |
| 3846 // of Object - the JavaScript backend chooses between Object and | 3846 // of Object - the JavaScript backend chooses between Object and |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3922 supertype = applyMixin(supertype, checkMixinType(link.head), link.head); | 3922 supertype = applyMixin(supertype, checkMixinType(link.head), link.head); |
| 3923 link = link.tail; | 3923 link = link.tail; |
| 3924 } | 3924 } |
| 3925 doApplyMixinTo(element, supertype, checkMixinType(link.head)); | 3925 doApplyMixinTo(element, supertype, checkMixinType(link.head)); |
| 3926 return element.computeType(compiler); | 3926 return element.computeType(compiler); |
| 3927 } | 3927 } |
| 3928 | 3928 |
| 3929 DartType applyMixin(DartType supertype, DartType mixinType, Node node) { | 3929 DartType applyMixin(DartType supertype, DartType mixinType, Node node) { |
| 3930 String superName = supertype.name; | 3930 String superName = supertype.name; |
| 3931 String mixinName = mixinType.name; | 3931 String mixinName = mixinType.name; |
| 3932 ClassElement mixinApplication = new MixinApplicationElementX( | 3932 MixinApplicationElementX mixinApplication = new MixinApplicationElementX( |
| 3933 "${superName}+${mixinName}", | 3933 "${superName}+${mixinName}", |
| 3934 element.getCompilationUnit(), | 3934 element.getCompilationUnit(), |
| 3935 compiler.getNextFreeClassId(), | 3935 compiler.getNextFreeClassId(), |
| 3936 node, | 3936 node, |
| 3937 Modifiers.EMPTY); // TODO(kasperl): Should this be abstract? | 3937 Modifiers.EMPTY); // TODO(kasperl): Should this be abstract? |
| 3938 // Create synthetic type variables for the mixin application. |
| 3939 LinkBuilder<DartType> typeVariablesBuilder = new LinkBuilder<DartType>(); |
| 3940 element.typeVariables.forEach((TypeVariableType type) { |
| 3941 TypeVariableElementX typeVariableElement = new TypeVariableElementX( |
| 3942 type.name, mixinApplication, type.element.parseNode(compiler)); |
| 3943 TypeVariableType typeVariable = new TypeVariableType(typeVariableElement); |
| 3944 typeVariablesBuilder.addLast(typeVariable); |
| 3945 }); |
| 3946 Link<DartType> typeVariables = typeVariablesBuilder.toLink(); |
| 3947 // Setup bounds on the synthetic type variables. |
| 3948 Link<DartType> link = typeVariables; |
| 3949 element.typeVariables.forEach((TypeVariableType type) { |
| 3950 TypeVariableType typeVariable = link.head; |
| 3951 TypeVariableElement typeVariableElement = typeVariable.element; |
| 3952 typeVariableElement.type = typeVariable; |
| 3953 typeVariableElement.bound = |
| 3954 type.element.bound.subst(typeVariables, element.typeVariables); |
| 3955 link = link.tail; |
| 3956 }); |
| 3957 // Setup this and raw type for the mixin application. |
| 3958 mixinApplication.computeThisAndRawType(compiler, typeVariables); |
| 3959 // Substitute in synthetic type variables in super and mixin types. |
| 3960 supertype = supertype.subst(typeVariables, element.typeVariables); |
| 3961 mixinType = mixinType.subst(typeVariables, element.typeVariables); |
| 3962 |
| 3938 doApplyMixinTo(mixinApplication, supertype, mixinType); | 3963 doApplyMixinTo(mixinApplication, supertype, mixinType); |
| 3939 mixinApplication.resolutionState = STATE_DONE; | 3964 mixinApplication.resolutionState = STATE_DONE; |
| 3940 mixinApplication.supertypeLoadState = STATE_DONE; | 3965 mixinApplication.supertypeLoadState = STATE_DONE; |
| 3941 return mixinApplication.computeType(compiler); | 3966 // Replace the synthetic type variables by the original type variables in |
| 3967 // the returned type (which should be the type actually extended). |
| 3968 InterfaceType mixinThisType = mixinApplication.computeType(compiler); |
| 3969 return mixinThisType.subst(element.typeVariables, |
| 3970 mixinThisType.typeArguments); |
| 3942 } | 3971 } |
| 3943 | 3972 |
| 3944 bool isDefaultConstructor(FunctionElement constructor) { | 3973 bool isDefaultConstructor(FunctionElement constructor) { |
| 3945 return constructor.name == '' && | 3974 return constructor.name == '' && |
| 3946 constructor.computeSignature(compiler).parameterCount == 0; | 3975 constructor.computeSignature(compiler).parameterCount == 0; |
| 3947 } | 3976 } |
| 3948 | 3977 |
| 3949 FunctionElement createForwardingConstructor(FunctionElement target, | 3978 FunctionElement createForwardingConstructor(FunctionElement target, |
| 3950 ClassElement enclosing) { | 3979 ClassElement enclosing) { |
| 3951 return new SynthesizedConstructorElementX( | 3980 return new SynthesizedConstructorElementX( |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4128 interfaces = interfaces.tail) { | 4157 interfaces = interfaces.tail) { |
| 4129 addAllSupertypes(allSupertypes, interfaces.head); | 4158 addAllSupertypes(allSupertypes, interfaces.head); |
| 4130 } | 4159 } |
| 4131 allSupertypes.add(compiler, cls.computeType(compiler)); | 4160 allSupertypes.add(compiler, cls.computeType(compiler)); |
| 4132 cls.allSupertypesAndSelf = allSupertypes.toTypeSet(); | 4161 cls.allSupertypesAndSelf = allSupertypes.toTypeSet(); |
| 4133 } else { | 4162 } else { |
| 4134 assert(identical(cls, compiler.objectClass)); | 4163 assert(identical(cls, compiler.objectClass)); |
| 4135 cls.allSupertypesAndSelf = | 4164 cls.allSupertypesAndSelf = |
| 4136 new OrderedTypeSet.singleton(cls.computeType(compiler)); | 4165 new OrderedTypeSet.singleton(cls.computeType(compiler)); |
| 4137 } | 4166 } |
| 4138 } | 4167 } |
| 4139 | 4168 |
| 4140 /** | 4169 /** |
| 4141 * Adds [type] and all supertypes of [type] to [allSupertypes] while | 4170 * Adds [type] and all supertypes of [type] to [allSupertypes] while |
| 4142 * substituting type variables. | 4171 * substituting type variables. |
| 4143 */ | 4172 */ |
| 4144 void addAllSupertypes(OrderedTypeSetBuilder allSupertypes, | 4173 void addAllSupertypes(OrderedTypeSetBuilder allSupertypes, |
| 4145 InterfaceType type) { | 4174 InterfaceType type) { |
| 4146 Link<DartType> typeArguments = type.typeArguments; | 4175 Link<DartType> typeArguments = type.typeArguments; |
| 4147 ClassElement classElement = type.element; | 4176 ClassElement classElement = type.element; |
| 4148 Link<DartType> typeVariables = classElement.typeVariables; | 4177 Link<DartType> typeVariables = classElement.typeVariables; |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4748 return finishConstructorReference(visit(expression), | 4777 return finishConstructorReference(visit(expression), |
| 4749 expression, expression); | 4778 expression, expression); |
| 4750 } | 4779 } |
| 4751 } | 4780 } |
| 4752 | 4781 |
| 4753 /// Looks up [name] in [scope] and unwraps the result. | 4782 /// Looks up [name] in [scope] and unwraps the result. |
| 4754 Element lookupInScope(Compiler compiler, Node node, | 4783 Element lookupInScope(Compiler compiler, Node node, |
| 4755 Scope scope, String name) { | 4784 Scope scope, String name) { |
| 4756 return Elements.unwrap(scope.lookup(name), compiler, node); | 4785 return Elements.unwrap(scope.lookup(name), compiler, node); |
| 4757 } | 4786 } |
| OLD | NEW |