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 TypeAnnotation mixinNode = link.head; |
karlklose
2013/10/03 07:50:01
How about: 'resolveType' -> 'checkMixinType'?
Johnni Winther
2013/10/03 08:00:26
Done.
| |
3610 DartType mixinType = checkMixinType(mixinNode); | |
3611 supertype = applyMixin(supertype, mixinType, mixinNode); | |
3610 link = link.tail; | 3612 link = link.tail; |
3611 } | 3613 } |
3612 element.supertype = supertype; | 3614 element.supertype = supertype; |
3613 } else { | 3615 } else { |
3614 element.supertype = resolveSupertype(element, node.superclass); | 3616 element.supertype = resolveSupertype(element, node.superclass); |
3615 } | 3617 } |
3616 } | 3618 } |
3617 // If the super type isn't specified, we provide a default. The language | 3619 // If the super type isn't specified, we provide a default. The language |
3618 // specifies [Object] but the backend can pick a specific 'implementation' | 3620 // specifies [Object] but the backend can pick a specific 'implementation' |
3619 // of Object - the JavaScript backend chooses between Object and | 3621 // of Object - the JavaScript backend chooses between Object and |
(...skipping 30 matching lines...) Expand all Loading... | |
3650 kind.error, arguments, const SourceString(''), element); | 3652 kind.error, arguments, const SourceString(''), element); |
3651 compiler.backend.registerThrowNoSuchMethod(mapping); | 3653 compiler.backend.registerThrowNoSuchMethod(mapping); |
3652 } | 3654 } |
3653 FunctionElement constructor = | 3655 FunctionElement constructor = |
3654 new SynthesizedConstructorElementX.forDefault(superMember, element); | 3656 new SynthesizedConstructorElementX.forDefault(superMember, element); |
3655 element.setDefaultConstructor(constructor, compiler); | 3657 element.setDefaultConstructor(constructor, compiler); |
3656 } | 3658 } |
3657 return element.computeType(compiler); | 3659 return element.computeType(compiler); |
3658 } | 3660 } |
3659 | 3661 |
3662 /// Resolves the mixed type for [mixinNode] and checks that the the mixin type | |
3663 /// is not black-listed. The mixin type is returned. | |
3664 DartType checkMixinType(TypeAnnotation mixinNode) { | |
3665 DartType mixinType = resolveType(mixinNode); | |
3666 if (isBlackListed(mixinType)) { | |
3667 compiler.reportError(mixinNode, | |
3668 MessageKind.CANNOT_MIXIN, {'type': mixinType}); | |
3669 } | |
3670 return mixinType; | |
3671 } | |
3672 | |
3660 DartType visitNamedMixinApplication(NamedMixinApplication node) { | 3673 DartType visitNamedMixinApplication(NamedMixinApplication node) { |
3661 compiler.ensure(element != null); | 3674 compiler.ensure(element != null); |
3662 compiler.ensure(element.resolutionState == STATE_STARTED); | 3675 compiler.ensure(element.resolutionState == STATE_STARTED); |
3663 | 3676 |
3664 InterfaceType type = element.computeType(compiler); | 3677 InterfaceType type = element.computeType(compiler); |
3665 scope = new TypeDeclarationScope(scope, element); | 3678 scope = new TypeDeclarationScope(scope, element); |
3666 resolveTypeVariableBounds(node.typeParameters); | 3679 resolveTypeVariableBounds(node.typeParameters); |
3667 | 3680 |
3668 // Generate anonymous mixin application elements for the | 3681 // Generate anonymous mixin application elements for the |
3669 // intermediate mixin applications (excluding the last). | 3682 // intermediate mixin applications (excluding the last). |
3670 DartType supertype = resolveSupertype(element, node.superclass); | 3683 DartType supertype = resolveSupertype(element, node.superclass); |
3671 Link<Node> link = node.mixins.nodes; | 3684 Link<Node> link = node.mixins.nodes; |
3672 while (!link.tail.isEmpty) { | 3685 while (!link.tail.isEmpty) { |
3673 supertype = applyMixin(supertype, resolveType(link.head), link.head); | 3686 TypeAnnotation mixinNode = link.head; |
karlklose
2013/10/03 07:50:01
Ditto.
Johnni Winther
2013/10/03 08:00:26
Done.
| |
3687 DartType mixinType = checkMixinType(mixinNode); | |
3688 supertype = applyMixin(supertype, mixinType, mixinNode); | |
3674 link = link.tail; | 3689 link = link.tail; |
3675 } | 3690 } |
3676 doApplyMixinTo(element, supertype, resolveType(link.head)); | 3691 doApplyMixinTo(element, supertype, checkMixinType(link.head)); |
3677 return element.computeType(compiler); | 3692 return element.computeType(compiler); |
3678 } | 3693 } |
3679 | 3694 |
3680 DartType applyMixin(DartType supertype, DartType mixinType, Node node) { | 3695 DartType applyMixin(DartType supertype, DartType mixinType, Node node) { |
3681 String superName = supertype.name.slowToString(); | 3696 String superName = supertype.name.slowToString(); |
3682 String mixinName = mixinType.name.slowToString(); | 3697 String mixinName = mixinType.name.slowToString(); |
3683 ClassElement mixinApplication = new MixinApplicationElementX( | 3698 ClassElement mixinApplication = new MixinApplicationElementX( |
3684 new SourceString("${superName}+${mixinName}"), | 3699 new SourceString("${superName}+${mixinName}"), |
3685 element.getCompilationUnit(), | 3700 element.getCompilationUnit(), |
3686 compiler.getNextFreeClassId(), | 3701 compiler.getNextFreeClassId(), |
(...skipping 12 matching lines...) Expand all Loading... | |
3699 | 3714 |
3700 FunctionElement createForwardingConstructor(FunctionElement target, | 3715 FunctionElement createForwardingConstructor(FunctionElement target, |
3701 ClassElement enclosing) { | 3716 ClassElement enclosing) { |
3702 return new SynthesizedConstructorElementX( | 3717 return new SynthesizedConstructorElementX( |
3703 target.name, target, enclosing, false); | 3718 target.name, target, enclosing, false); |
3704 } | 3719 } |
3705 | 3720 |
3706 void doApplyMixinTo(MixinApplicationElement mixinApplication, | 3721 void doApplyMixinTo(MixinApplicationElement mixinApplication, |
3707 DartType supertype, | 3722 DartType supertype, |
3708 DartType mixinType) { | 3723 DartType mixinType) { |
3724 | |
karlklose
2013/10/03 07:50:01
Remove extra line.
Johnni Winther
2013/10/03 08:00:26
Done.
| |
3709 Node node = mixinApplication.parseNode(compiler); | 3725 Node node = mixinApplication.parseNode(compiler); |
3710 | 3726 |
3711 if (mixinApplication.supertype != null) { | 3727 if (mixinApplication.supertype != null) { |
3712 // [supertype] is not null if there was a cycle. | 3728 // [supertype] is not null if there was a cycle. |
3713 assert(invariant(node, compiler.compilationFailed)); | 3729 assert(invariant(node, compiler.compilationFailed)); |
3714 supertype = mixinApplication.supertype; | 3730 supertype = mixinApplication.supertype; |
3715 assert(invariant(node, supertype.element == compiler.objectClass)); | 3731 assert(invariant(node, supertype.element == compiler.objectClass)); |
3716 } else { | 3732 } else { |
3717 mixinApplication.supertype = supertype; | 3733 mixinApplication.supertype = supertype; |
3718 } | 3734 } |
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4485 return e; | 4501 return e; |
4486 } | 4502 } |
4487 | 4503 |
4488 /// Assumed to be called by [resolveRedirectingFactory]. | 4504 /// Assumed to be called by [resolveRedirectingFactory]. |
4489 Element visitReturn(Return node) { | 4505 Element visitReturn(Return node) { |
4490 Node expression = node.expression; | 4506 Node expression = node.expression; |
4491 return finishConstructorReference(visit(expression), | 4507 return finishConstructorReference(visit(expression), |
4492 expression, expression); | 4508 expression, expression); |
4493 } | 4509 } |
4494 } | 4510 } |
OLD | NEW |