| 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 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 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2848 if (objectElement == null) { | 2848 if (objectElement == null) { |
| 2849 compiler.internalError("Internal error: cannot resolve Object", | 2849 compiler.internalError("Internal error: cannot resolve Object", |
| 2850 node: node); | 2850 node: node); |
| 2851 } else { | 2851 } else { |
| 2852 objectElement.ensureResolved(compiler); | 2852 objectElement.ensureResolved(compiler); |
| 2853 } | 2853 } |
| 2854 element.supertype = objectElement.computeType(compiler); | 2854 element.supertype = objectElement.computeType(compiler); |
| 2855 } | 2855 } |
| 2856 | 2856 |
| 2857 assert(element.interfaces == null); | 2857 assert(element.interfaces == null); |
| 2858 Link<DartType> interfaces = const Link<DartType>(); | 2858 element.interfaces = resolveInterfaces(node.interfaces, node.superclass); |
| 2859 for (Link<Node> link = node.interfaces.nodes; | |
| 2860 !link.isEmpty; | |
| 2861 link = link.tail) { | |
| 2862 DartType interfaceType = typeResolver.resolveTypeAnnotation( | |
| 2863 link.head, scope, element, onFailure: error); | |
| 2864 if (interfaceType != null) { | |
| 2865 if (identical(interfaceType.kind, TypeKind.MALFORMED_TYPE)) { | |
| 2866 // Error has already been reported. | |
| 2867 } else if (!identical(interfaceType.kind, TypeKind.INTERFACE)) { | |
| 2868 // TODO(johnniwinther): Handle dynamic. | |
| 2869 TypeAnnotation typeAnnotation = link.head; | |
| 2870 error(typeAnnotation.typeName, MessageKind.CLASS_NAME_EXPECTED, []); | |
| 2871 } else { | |
| 2872 if (interfaceType == element.supertype) { | |
| 2873 compiler.reportMessage( | |
| 2874 compiler.spanFromSpannable(node.superclass), | |
| 2875 MessageKind.DUPLICATE_EXTENDS_IMPLEMENTS.error([interfaceType]), | |
| 2876 Diagnostic.ERROR); | |
| 2877 compiler.reportMessage( | |
| 2878 compiler.spanFromSpannable(link.head), | |
| 2879 MessageKind.DUPLICATE_EXTENDS_IMPLEMENTS.error([interfaceType]), | |
| 2880 Diagnostic.ERROR); | |
| 2881 } | |
| 2882 if (interfaces.contains(interfaceType)) { | |
| 2883 compiler.reportMessage( | |
| 2884 compiler.spanFromSpannable(link.head), | |
| 2885 MessageKind.DUPLICATE_IMPLEMENTS.error([interfaceType]), | |
| 2886 Diagnostic.ERROR); | |
| 2887 } | |
| 2888 interfaces = interfaces.prepend(interfaceType); | |
| 2889 if (isBlackListed(interfaceType)) { | |
| 2890 error(link.head, MessageKind.CANNOT_IMPLEMENT, [interfaceType]); | |
| 2891 } | |
| 2892 } | |
| 2893 } | |
| 2894 } | |
| 2895 element.interfaces = interfaces; | |
| 2896 calculateAllSupertypes(element); | 2859 calculateAllSupertypes(element); |
| 2897 | 2860 |
| 2898 if (node.defaultClause != null) { | 2861 if (node.defaultClause != null) { |
| 2899 element.defaultClass = visit(node.defaultClause); | 2862 element.defaultClass = visit(node.defaultClause); |
| 2900 } | 2863 } |
| 2901 element.addDefaultConstructorIfNeeded(compiler); | 2864 element.addDefaultConstructorIfNeeded(compiler); |
| 2902 return element.computeType(compiler); | 2865 return element.computeType(compiler); |
| 2903 } | 2866 } |
| 2904 | 2867 |
| 2905 DartType visitMixinApplication(MixinApplication node) { | 2868 DartType visitMixinApplication(MixinApplication node) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2932 mixinApplication.supertypeLoadState = STATE_DONE; | 2895 mixinApplication.supertypeLoadState = STATE_DONE; |
| 2933 return mixinApplication.computeType(compiler); | 2896 return mixinApplication.computeType(compiler); |
| 2934 } | 2897 } |
| 2935 | 2898 |
| 2936 void doApplyMixinTo(MixinApplicationElement mixinApplication, | 2899 void doApplyMixinTo(MixinApplicationElement mixinApplication, |
| 2937 DartType supertype, | 2900 DartType supertype, |
| 2938 DartType mixinType) { | 2901 DartType mixinType) { |
| 2939 assert(mixinApplication.supertype == null); | 2902 assert(mixinApplication.supertype == null); |
| 2940 mixinApplication.supertype = supertype; | 2903 mixinApplication.supertype = supertype; |
| 2941 | 2904 |
| 2905 // Named mixin application may have an 'implements' clause. |
| 2906 NamedMixinApplication namedMixinApplication = |
| 2907 mixinApplication.parseNode(compiler).asNamedMixinApplication(); |
| 2908 Link<DartType> interfaces = (namedMixinApplication != null) |
| 2909 ? resolveInterfaces(namedMixinApplication.interfaces, |
| 2910 namedMixinApplication.superclass) |
| 2911 : const Link<DartType>(); |
| 2912 |
| 2942 // The class that is the result of a mixin application implements | 2913 // The class that is the result of a mixin application implements |
| 2943 // the interface of the class that was mixed in. | 2914 // the interface of the class that was mixed in so always prepend |
| 2944 Link<DartType> interfaces = const Link<DartType>(); | 2915 // that to the interface list. |
| 2945 interfaces = interfaces.prepend(mixinType); | 2916 interfaces = interfaces.prepend(mixinType); |
| 2946 assert(mixinApplication.interfaces == null); | 2917 assert(mixinApplication.interfaces == null); |
| 2947 mixinApplication.interfaces = interfaces; | 2918 mixinApplication.interfaces = interfaces; |
| 2948 | 2919 |
| 2949 assert(mixinApplication.mixin == null); | 2920 assert(mixinApplication.mixin == null); |
| 2950 mixinApplication.mixin = resolveMixinFor(mixinApplication, mixinType); | 2921 mixinApplication.mixin = resolveMixinFor(mixinApplication, mixinType); |
| 2951 mixinApplication.addDefaultConstructorIfNeeded(compiler); | 2922 mixinApplication.addDefaultConstructorIfNeeded(compiler); |
| 2952 calculateAllSupertypes(mixinApplication); | 2923 calculateAllSupertypes(mixinApplication); |
| 2953 } | 2924 } |
| 2954 | 2925 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3041 error(superclass.typeName, MessageKind.CLASS_NAME_EXPECTED, []); | 3012 error(superclass.typeName, MessageKind.CLASS_NAME_EXPECTED, []); |
| 3042 return null; | 3013 return null; |
| 3043 } else if (isBlackListed(supertype)) { | 3014 } else if (isBlackListed(supertype)) { |
| 3044 error(superclass, MessageKind.CANNOT_EXTEND, [supertype]); | 3015 error(superclass, MessageKind.CANNOT_EXTEND, [supertype]); |
| 3045 return null; | 3016 return null; |
| 3046 } | 3017 } |
| 3047 } | 3018 } |
| 3048 return supertype; | 3019 return supertype; |
| 3049 } | 3020 } |
| 3050 | 3021 |
| 3022 Link<DartType> resolveInterfaces(NodeList interfaces, Node superclass) { |
| 3023 Link<DartType> result = const Link<DartType>(); |
| 3024 if (interfaces == null) return result; |
| 3025 for (Link<Node> link = interfaces.nodes; !link.isEmpty; link = link.tail) { |
| 3026 DartType interfaceType = typeResolver.resolveTypeAnnotation( |
| 3027 link.head, scope, element, onFailure: error); |
| 3028 if (interfaceType != null) { |
| 3029 if (identical(interfaceType.kind, TypeKind.MALFORMED_TYPE)) { |
| 3030 // Error has already been reported. |
| 3031 } else if (!identical(interfaceType.kind, TypeKind.INTERFACE)) { |
| 3032 // TODO(johnniwinther): Handle dynamic. |
| 3033 TypeAnnotation typeAnnotation = link.head; |
| 3034 error(typeAnnotation.typeName, MessageKind.CLASS_NAME_EXPECTED, []); |
| 3035 } else { |
| 3036 if (interfaceType == element.supertype) { |
| 3037 compiler.reportMessage( |
| 3038 compiler.spanFromSpannable(superclass), |
| 3039 MessageKind.DUPLICATE_EXTENDS_IMPLEMENTS.error([interfaceType]), |
| 3040 Diagnostic.ERROR); |
| 3041 compiler.reportMessage( |
| 3042 compiler.spanFromSpannable(link.head), |
| 3043 MessageKind.DUPLICATE_EXTENDS_IMPLEMENTS.error([interfaceType]), |
| 3044 Diagnostic.ERROR); |
| 3045 } |
| 3046 if (result.contains(interfaceType)) { |
| 3047 compiler.reportMessage( |
| 3048 compiler.spanFromSpannable(link.head), |
| 3049 MessageKind.DUPLICATE_IMPLEMENTS.error([interfaceType]), |
| 3050 Diagnostic.ERROR); |
| 3051 } |
| 3052 result = result.prepend(interfaceType); |
| 3053 if (isBlackListed(interfaceType)) { |
| 3054 error(link.head, MessageKind.CANNOT_IMPLEMENT, [interfaceType]); |
| 3055 } |
| 3056 } |
| 3057 } |
| 3058 } |
| 3059 return result; |
| 3060 } |
| 3061 |
| 3051 void calculateAllSupertypes(ClassElement cls) { | 3062 void calculateAllSupertypes(ClassElement cls) { |
| 3052 // TODO(karlklose): Check if type arguments match, if a class | 3063 // TODO(karlklose): Check if type arguments match, if a class |
| 3053 // element occurs more than once in the supertypes. | 3064 // element occurs more than once in the supertypes. |
| 3054 if (cls.allSupertypes != null) return; | 3065 if (cls.allSupertypes != null) return; |
| 3055 final DartType supertype = cls.supertype; | 3066 final DartType supertype = cls.supertype; |
| 3056 if (supertype != null) { | 3067 if (supertype != null) { |
| 3057 var allSupertypes = new LinkBuilder<DartType>(); | 3068 var allSupertypes = new LinkBuilder<DartType>(); |
| 3058 addAllSupertypes(allSupertypes, supertype); | 3069 addAllSupertypes(allSupertypes, supertype); |
| 3059 for (Link<DartType> interfaces = cls.interfaces; | 3070 for (Link<DartType> interfaces = cls.interfaces; |
| 3060 !interfaces.isEmpty; | 3071 !interfaces.isEmpty; |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3584 return e; | 3595 return e; |
| 3585 } | 3596 } |
| 3586 | 3597 |
| 3587 /// Assumed to be called by [resolveRedirectingFactory]. | 3598 /// Assumed to be called by [resolveRedirectingFactory]. |
| 3588 Element visitReturn(Return node) { | 3599 Element visitReturn(Return node) { |
| 3589 Node expression = node.expression; | 3600 Node expression = node.expression; |
| 3590 return finishConstructorReference(visit(expression), | 3601 return finishConstructorReference(visit(expression), |
| 3591 expression, expression); | 3602 expression, expression); |
| 3592 } | 3603 } |
| 3593 } | 3604 } |
| OLD | NEW |