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 3931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3942 // that to the interface list. | 3942 // that to the interface list. |
3943 interfaces = interfaces.prepend(mixinType); | 3943 interfaces = interfaces.prepend(mixinType); |
3944 assert(mixinApplication.interfaces == null); | 3944 assert(mixinApplication.interfaces == null); |
3945 mixinApplication.interfaces = interfaces; | 3945 mixinApplication.interfaces = interfaces; |
3946 | 3946 |
3947 if (mixinType.kind != TypeKind.INTERFACE) { | 3947 if (mixinType.kind != TypeKind.INTERFACE) { |
3948 mixinApplication.allSupertypes = const Link<DartType>(); | 3948 mixinApplication.allSupertypes = const Link<DartType>(); |
3949 return; | 3949 return; |
3950 } | 3950 } |
3951 | 3951 |
3952 assert(mixinApplication.mixin == null); | 3952 assert(mixinApplication.mixinType == null); |
3953 Element mixin = resolveMixinFor(mixinApplication, mixinType); | 3953 mixinApplication.mixinType = resolveMixinFor(mixinApplication, mixinType); |
3954 | |
3955 mixinApplication.mixin = mixin; | |
3956 | 3954 |
3957 // Create forwarding constructors for constructor defined in the superclass | 3955 // Create forwarding constructors for constructor defined in the superclass |
3958 // because they are now hidden by the mixin application. | 3956 // because they are now hidden by the mixin application. |
3959 ClassElement superclass = supertype.element; | 3957 ClassElement superclass = supertype.element; |
3960 superclass.forEachLocalMember((Element member) { | 3958 superclass.forEachLocalMember((Element member) { |
3961 if (!member.isGenerativeConstructor()) return; | 3959 if (!member.isGenerativeConstructor()) return; |
3962 FunctionElement forwarder = | 3960 FunctionElement forwarder = |
3963 createForwardingConstructor(member, mixinApplication); | 3961 createForwardingConstructor(member, mixinApplication); |
3964 mixinApplication.addConstructor(forwarder); | 3962 mixinApplication.addConstructor(forwarder); |
3965 }); | 3963 }); |
3966 calculateAllSupertypes(mixinApplication); | 3964 calculateAllSupertypes(mixinApplication); |
3967 } | 3965 } |
3968 | 3966 |
3969 ClassElement resolveMixinFor(MixinApplicationElement mixinApplication, | 3967 InterfaceType resolveMixinFor(MixinApplicationElement mixinApplication, |
3970 DartType mixinType) { | 3968 DartType mixinType) { |
3971 ClassElement mixin = mixinType.element; | 3969 ClassElement mixin = mixinType.element; |
3972 mixin.ensureResolved(compiler); | 3970 mixin.ensureResolved(compiler); |
3973 | 3971 |
3974 // Check for cycles in the mixin chain. | 3972 // Check for cycles in the mixin chain. |
3975 ClassElement previous = mixinApplication; // For better error messages. | 3973 ClassElement previous = mixinApplication; // For better error messages. |
3976 ClassElement current = mixin; | 3974 ClassElement current = mixin; |
3977 while (current != null && current.isMixinApplication) { | 3975 while (current != null && current.isMixinApplication) { |
3978 MixinApplicationElement currentMixinApplication = current; | 3976 MixinApplicationElement currentMixinApplication = current; |
3979 if (currentMixinApplication == mixinApplication) { | 3977 if (currentMixinApplication == mixinApplication) { |
3980 compiler.reportError( | 3978 compiler.reportError( |
3981 mixinApplication, MessageKind.ILLEGAL_MIXIN_CYCLE, | 3979 mixinApplication, MessageKind.ILLEGAL_MIXIN_CYCLE, |
3982 {'mixinName1': current.name, 'mixinName2': previous.name}); | 3980 {'mixinName1': current.name, 'mixinName2': previous.name}); |
3983 // We have found a cycle in the mixin chain. Return null as | 3981 // We have found a cycle in the mixin chain. Return null as |
3984 // the mixin for this application to avoid getting into | 3982 // the mixin for this application to avoid getting into |
3985 // infinite recursion when traversing members. | 3983 // infinite recursion when traversing members. |
3986 return null; | 3984 return null; |
3987 } | 3985 } |
3988 previous = current; | 3986 previous = current; |
3989 current = currentMixinApplication.mixin; | 3987 current = currentMixinApplication.mixin; |
3990 } | 3988 } |
3991 compiler.world.registerMixinUse(mixinApplication, mixin); | 3989 compiler.world.registerMixinUse(mixinApplication, mixin); |
3992 return mixin; | 3990 return mixinType; |
3993 } | 3991 } |
3994 | 3992 |
3995 DartType resolveType(TypeAnnotation node) { | 3993 DartType resolveType(TypeAnnotation node) { |
3996 return typeResolver.resolveTypeAnnotation(this, node); | 3994 return typeResolver.resolveTypeAnnotation(this, node); |
3997 } | 3995 } |
3998 | 3996 |
3999 DartType resolveSupertype(ClassElement cls, TypeAnnotation superclass) { | 3997 DartType resolveSupertype(ClassElement cls, TypeAnnotation superclass) { |
4000 DartType supertype = resolveType(superclass); | 3998 DartType supertype = resolveType(superclass); |
4001 if (supertype != null) { | 3999 if (supertype != null) { |
4002 if (identical(supertype.kind, TypeKind.MALFORMED_TYPE)) { | 4000 if (identical(supertype.kind, TypeKind.MALFORMED_TYPE)) { |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4728 return finishConstructorReference(visit(expression), | 4726 return finishConstructorReference(visit(expression), |
4729 expression, expression); | 4727 expression, expression); |
4730 } | 4728 } |
4731 } | 4729 } |
4732 | 4730 |
4733 /// Looks up [name] in [scope] and unwraps the result. | 4731 /// Looks up [name] in [scope] and unwraps the result. |
4734 Element lookupInScope(Compiler compiler, Node node, | 4732 Element lookupInScope(Compiler compiler, Node node, |
4735 Scope scope, String name) { | 4733 Scope scope, String name) { |
4736 return Elements.unwrap(scope.lookup(name), compiler, node); | 4734 return Elements.unwrap(scope.lookup(name), compiler, node); |
4737 } | 4735 } |
OLD | NEW |