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 Set<Node> get superUses; | 9 Set<Node> get superUses; |
10 | 10 |
(...skipping 3588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3599 resolveTypeVariableBounds(node.typeParameters); | 3599 resolveTypeVariableBounds(node.typeParameters); |
3600 | 3600 |
3601 // Setup the supertype for the element (if there is a cycle in the | 3601 // Setup the supertype for the element (if there is a cycle in the |
3602 // class hierarchy, it has already been set to Object). | 3602 // class hierarchy, it has already been set to Object). |
3603 if (element.supertype == null && node.superclass != null) { | 3603 if (element.supertype == null && node.superclass != null) { |
3604 MixinApplication superMixin = node.superclass.asMixinApplication(); | 3604 MixinApplication superMixin = node.superclass.asMixinApplication(); |
3605 if (superMixin != null) { | 3605 if (superMixin != null) { |
3606 DartType supertype = resolveSupertype(element, superMixin.superclass); | 3606 DartType supertype = resolveSupertype(element, superMixin.superclass); |
3607 Link<Node> link = superMixin.mixins.nodes; | 3607 Link<Node> link = superMixin.mixins.nodes; |
3608 while (!link.isEmpty) { | 3608 while (!link.isEmpty) { |
3609 supertype = applyMixin(supertype, resolveType(link.head), node); | 3609 supertype = applyMixin( |
| 3610 supertype, checkMixinType(link.head), link.head); |
3610 link = link.tail; | 3611 link = link.tail; |
3611 } | 3612 } |
3612 element.supertype = supertype; | 3613 element.supertype = supertype; |
3613 } else { | 3614 } else { |
3614 element.supertype = resolveSupertype(element, node.superclass); | 3615 element.supertype = resolveSupertype(element, node.superclass); |
3615 } | 3616 } |
3616 } | 3617 } |
3617 // If the super type isn't specified, we provide a default. The language | 3618 // If the super type isn't specified, we provide a default. The language |
3618 // specifies [Object] but the backend can pick a specific 'implementation' | 3619 // specifies [Object] but the backend can pick a specific 'implementation' |
3619 // of Object - the JavaScript backend chooses between Object and | 3620 // of Object - the JavaScript backend chooses between Object and |
(...skipping 30 matching lines...) Expand all Loading... |
3650 kind.error, arguments, const SourceString(''), element); | 3651 kind.error, arguments, const SourceString(''), element); |
3651 compiler.backend.registerThrowNoSuchMethod(mapping); | 3652 compiler.backend.registerThrowNoSuchMethod(mapping); |
3652 } | 3653 } |
3653 FunctionElement constructor = | 3654 FunctionElement constructor = |
3654 new SynthesizedConstructorElementX.forDefault(superMember, element); | 3655 new SynthesizedConstructorElementX.forDefault(superMember, element); |
3655 element.setDefaultConstructor(constructor, compiler); | 3656 element.setDefaultConstructor(constructor, compiler); |
3656 } | 3657 } |
3657 return element.computeType(compiler); | 3658 return element.computeType(compiler); |
3658 } | 3659 } |
3659 | 3660 |
| 3661 /// Resolves the mixed type for [mixinNode] and checks that the the mixin type |
| 3662 /// is not black-listed. The mixin type is returned. |
| 3663 DartType checkMixinType(TypeAnnotation mixinNode) { |
| 3664 DartType mixinType = resolveType(mixinNode); |
| 3665 if (isBlackListed(mixinType)) { |
| 3666 compiler.reportError(mixinNode, |
| 3667 MessageKind.CANNOT_MIXIN, {'type': mixinType}); |
| 3668 } |
| 3669 return mixinType; |
| 3670 } |
| 3671 |
3660 DartType visitNamedMixinApplication(NamedMixinApplication node) { | 3672 DartType visitNamedMixinApplication(NamedMixinApplication node) { |
3661 compiler.ensure(element != null); | 3673 compiler.ensure(element != null); |
3662 compiler.ensure(element.resolutionState == STATE_STARTED); | 3674 compiler.ensure(element.resolutionState == STATE_STARTED); |
3663 | 3675 |
3664 InterfaceType type = element.computeType(compiler); | 3676 InterfaceType type = element.computeType(compiler); |
3665 scope = new TypeDeclarationScope(scope, element); | 3677 scope = new TypeDeclarationScope(scope, element); |
3666 resolveTypeVariableBounds(node.typeParameters); | 3678 resolveTypeVariableBounds(node.typeParameters); |
3667 | 3679 |
3668 // Generate anonymous mixin application elements for the | 3680 // Generate anonymous mixin application elements for the |
3669 // intermediate mixin applications (excluding the last). | 3681 // intermediate mixin applications (excluding the last). |
3670 DartType supertype = resolveSupertype(element, node.superclass); | 3682 DartType supertype = resolveSupertype(element, node.superclass); |
3671 Link<Node> link = node.mixins.nodes; | 3683 Link<Node> link = node.mixins.nodes; |
3672 while (!link.tail.isEmpty) { | 3684 while (!link.tail.isEmpty) { |
3673 supertype = applyMixin(supertype, resolveType(link.head), link.head); | 3685 supertype = applyMixin(supertype, checkMixinType(link.head), link.head); |
3674 link = link.tail; | 3686 link = link.tail; |
3675 } | 3687 } |
3676 doApplyMixinTo(element, supertype, resolveType(link.head)); | 3688 doApplyMixinTo(element, supertype, checkMixinType(link.head)); |
3677 return element.computeType(compiler); | 3689 return element.computeType(compiler); |
3678 } | 3690 } |
3679 | 3691 |
3680 DartType applyMixin(DartType supertype, DartType mixinType, Node node) { | 3692 DartType applyMixin(DartType supertype, DartType mixinType, Node node) { |
3681 String superName = supertype.name.slowToString(); | 3693 String superName = supertype.name.slowToString(); |
3682 String mixinName = mixinType.name.slowToString(); | 3694 String mixinName = mixinType.name.slowToString(); |
3683 ClassElement mixinApplication = new MixinApplicationElementX( | 3695 ClassElement mixinApplication = new MixinApplicationElementX( |
3684 new SourceString("${superName}+${mixinName}"), | 3696 new SourceString("${superName}+${mixinName}"), |
3685 element.getCompilationUnit(), | 3697 element.getCompilationUnit(), |
3686 compiler.getNextFreeClassId(), | 3698 compiler.getNextFreeClassId(), |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4485 return e; | 4497 return e; |
4486 } | 4498 } |
4487 | 4499 |
4488 /// Assumed to be called by [resolveRedirectingFactory]. | 4500 /// Assumed to be called by [resolveRedirectingFactory]. |
4489 Element visitReturn(Return node) { | 4501 Element visitReturn(Return node) { |
4490 Node expression = node.expression; | 4502 Node expression = node.expression; |
4491 return finishConstructorReference(visit(expression), | 4503 return finishConstructorReference(visit(expression), |
4492 expression, expression); | 4504 expression, expression); |
4493 } | 4505 } |
4494 } | 4506 } |
OLD | NEW |