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

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

Issue 12018014: Start allowing mixin application extensions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Extend test cases. Created 7 years, 11 months 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 operator[](Node node); 8 Element operator[](Node node);
9 Selector getSelector(Send send); 9 Selector getSelector(Send send);
10 DartType getType(Node node); 10 DartType getType(Node node);
(...skipping 2719 matching lines...) Expand 10 before | Expand all | Expand 10 after
2730 compiler.ensure(element != null); 2730 compiler.ensure(element != null);
2731 compiler.ensure(element.resolutionState == STATE_STARTED); 2731 compiler.ensure(element.resolutionState == STATE_STARTED);
2732 2732
2733 InterfaceType type = element.computeType(compiler); 2733 InterfaceType type = element.computeType(compiler);
2734 scope = new TypeDeclarationScope(scope, element); 2734 scope = new TypeDeclarationScope(scope, element);
2735 // TODO(ahe): It is not safe to call resolveTypeVariableBounds yet. 2735 // TODO(ahe): It is not safe to call resolveTypeVariableBounds yet.
2736 // As a side-effect, this may get us back here trying to 2736 // As a side-effect, this may get us back here trying to
2737 // resolve this class again. 2737 // resolve this class again.
2738 resolveTypeVariableBounds(node.typeParameters); 2738 resolveTypeVariableBounds(node.typeParameters);
2739 2739
2740 // Resolve super type and deal with the Object class nicely. 2740 // Setup the supertype for the element.
2741 element.supertype = resolveSupertype(element, node.superclass); 2741 assert(element.supertype == null);
2742 if (node.superclass != null) {
2743 MixinApplication superMixin = node.superclass.asMixinApplication();
2744 if (superMixin != null) {
2745 DartType supertype = resolveSupertype(element, superMixin.superclass);
2746 Link<Node> link = superMixin.mixins.nodes;
2747 while (!link.isEmpty) {
2748 supertype = applyMixin(supertype, visit(link.head));
2749 link = link.tail;
2750 }
2751 element.supertype = supertype;
2752 } else {
2753 element.supertype = resolveSupertype(element, node.superclass);
2754 }
2755 }
2756
2757 // If the super type isn't specified, we make it Object.
2742 final objectElement = compiler.objectClass; 2758 final objectElement = compiler.objectClass;
2743 if (!identical(element, objectElement) && element.supertype == null) { 2759 if (!identical(element, objectElement) && element.supertype == null) {
2744 if (objectElement == null) { 2760 if (objectElement == null) {
2745 compiler.internalError("Internal error: cannot resolve Object", 2761 compiler.internalError("Internal error: cannot resolve Object",
2746 node: node); 2762 node: node);
2747 } else { 2763 } else {
2748 objectElement.ensureResolved(compiler); 2764 objectElement.ensureResolved(compiler);
2749 } 2765 }
2750 element.supertype = objectElement.computeType(compiler); 2766 element.supertype = objectElement.computeType(compiler);
2751 } 2767 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
2810 supertype = applyMixin(supertype, visit(link.head)); 2826 supertype = applyMixin(supertype, visit(link.head));
2811 link = link.tail; 2827 link = link.tail;
2812 } 2828 }
2813 doApplyMixinTo(element, supertype, visit(link.head)); 2829 doApplyMixinTo(element, supertype, visit(link.head));
2814 return element.computeType(compiler); 2830 return element.computeType(compiler);
2815 } 2831 }
2816 2832
2817 DartType applyMixin(DartType supertype, DartType mixinType) { 2833 DartType applyMixin(DartType supertype, DartType mixinType) {
2818 String superName = supertype.name.slowToString(); 2834 String superName = supertype.name.slowToString();
2819 String mixinName = mixinType.name.slowToString(); 2835 String mixinName = mixinType.name.slowToString();
2820 // TODO(kasperl): This is a little bit weird. Maybe we should
2821 // restructure the parsed nodes for mixin applications to better
2822 // match the nesting implied by the list of mixins so that each
2823 // mixin application element could get it's own proper node.
2824 MixinApplication fakeTree = element.parseNode(compiler);
2825 ClassElement mixinApplication = new MixinApplicationElementX( 2836 ClassElement mixinApplication = new MixinApplicationElementX(
2826 new SourceString("${superName}_${mixinName}"), 2837 new SourceString("${superName}_${mixinName}"),
2827 element.getCompilationUnit(), 2838 element.getCompilationUnit(),
2828 compiler.getNextFreeClassId(), 2839 compiler.getNextFreeClassId(),
2829 fakeTree); 2840 element.parseNode(compiler));
2830 doApplyMixinTo(mixinApplication, supertype, mixinType); 2841 doApplyMixinTo(mixinApplication, supertype, mixinType);
2831 mixinApplication.resolutionState = STATE_DONE; 2842 mixinApplication.resolutionState = STATE_DONE;
2832 mixinApplication.supertypeLoadState = STATE_DONE; 2843 mixinApplication.supertypeLoadState = STATE_DONE;
2833 return mixinApplication.computeType(compiler); 2844 return mixinApplication.computeType(compiler);
2834 } 2845 }
2835 2846
2836 void doApplyMixinTo(ClassElement mixinApplication, 2847 void doApplyMixinTo(ClassElement mixinApplication,
2837 DartType supertype, 2848 DartType supertype,
2838 DartType mixinType) { 2849 DartType mixinType) {
2839 assert(mixinApplication.supertype == null); 2850 assert(mixinApplication.supertype == null);
2840 mixinApplication.supertype = supertype; 2851 mixinApplication.supertype = supertype;
2841 2852
2842 // The class that is the result of a mixin application implements 2853 // The class that is the result of a mixin application implements
2843 // the interface of the class that was mixed in. 2854 // the interface of the class that was mixed in.
2844 Link<DartType> interfaces = const Link<DartType>(); 2855 Link<DartType> interfaces = const Link<DartType>();
2845 interfaces = interfaces.prepend(mixinType); 2856 interfaces = interfaces.prepend(mixinType);
2846 assert(mixinApplication.interfaces == null); 2857 assert(mixinApplication.interfaces == null);
2847 mixinApplication.interfaces = interfaces; 2858 mixinApplication.interfaces = interfaces;
2848 2859
2849 assert(element.mixin == null); 2860 assert(mixinApplication.mixin == null);
2850 mixinApplication.mixin = mixinType.element; 2861 mixinApplication.mixin = mixinType.element;
2851 mixinApplication.mixin.ensureResolved(compiler); 2862 mixinApplication.mixin.ensureResolved(compiler);
2852 mixinApplication.addDefaultConstructorIfNeeded(compiler); 2863 mixinApplication.addDefaultConstructorIfNeeded(compiler);
2853 calculateAllSupertypes(mixinApplication); 2864 calculateAllSupertypes(mixinApplication);
2854 } 2865 }
2855 2866
2856 2867
2857 // TODO(johnniwinther): Remove when default class is no longer supported. 2868 // TODO(johnniwinther): Remove when default class is no longer supported.
2858 DartType visitTypeAnnotation(TypeAnnotation node) { 2869 DartType visitTypeAnnotation(TypeAnnotation node) {
2859 return visit(node.typeName); 2870 return visit(node.typeName);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2898 Identifier selector = node.selector.asIdentifier(); 2909 Identifier selector = node.selector.asIdentifier();
2899 var e = prefixElement.lookupLocalMember(selector.source); 2910 var e = prefixElement.lookupLocalMember(selector.source);
2900 if (e == null || !e.impliesType()) { 2911 if (e == null || !e.impliesType()) {
2901 error(node.selector, MessageKind.CANNOT_RESOLVE_TYPE, [node.selector]); 2912 error(node.selector, MessageKind.CANNOT_RESOLVE_TYPE, [node.selector]);
2902 return null; 2913 return null;
2903 } 2914 }
2904 return e.computeType(compiler); 2915 return e.computeType(compiler);
2905 } 2916 }
2906 2917
2907 DartType resolveSupertype(ClassElement cls, TypeAnnotation superclass) { 2918 DartType resolveSupertype(ClassElement cls, TypeAnnotation superclass) {
2908 DartType supertype; 2919 DartType supertype = typeResolver.resolveTypeAnnotation(
2909 if (superclass != null) { 2920 superclass, scope, cls, onFailure: error);
2910 supertype = typeResolver.resolveTypeAnnotation(
2911 superclass, scope, cls, onFailure: error);
2912 }
2913 if (supertype != null) { 2921 if (supertype != null) {
2914 if (identical(supertype.kind, TypeKind.MALFORMED_TYPE)) { 2922 if (identical(supertype.kind, TypeKind.MALFORMED_TYPE)) {
2915 // Error has already been reported. 2923 // Error has already been reported.
2916 } else if (!identical(supertype.kind, TypeKind.INTERFACE)) { 2924 } else if (!identical(supertype.kind, TypeKind.INTERFACE)) {
2917 // TODO(johnniwinther): Handle dynamic. 2925 // TODO(johnniwinther): Handle dynamic.
2918 error(superclass.typeName, MessageKind.CLASS_NAME_EXPECTED, []); 2926 error(superclass.typeName, MessageKind.CLASS_NAME_EXPECTED, []);
2919 return null; 2927 return null;
2920 } else if (isBlackListed(supertype)) { 2928 } else if (isBlackListed(supertype)) {
2921 error(superclass, MessageKind.CANNOT_EXTEND, [supertype]); 2929 error(superclass, MessageKind.CANNOT_EXTEND, [supertype]);
2922 return null; 2930 return null;
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after
3461 return e; 3469 return e;
3462 } 3470 }
3463 3471
3464 /// Assumed to be called by [resolveRedirectingFactory]. 3472 /// Assumed to be called by [resolveRedirectingFactory].
3465 Element visitReturn(Return node) { 3473 Element visitReturn(Return node) {
3466 Node expression = node.expression; 3474 Node expression = node.expression;
3467 return finishConstructorReference(visit(expression), 3475 return finishConstructorReference(visit(expression),
3468 expression, expression); 3476 expression, expression);
3469 } 3477 }
3470 } 3478 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698