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

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

Issue 11230007: Resolve redirecting factories. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Update test status Created 8 years, 1 month 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
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/typechecker.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after
1868 visit(link.head); 1868 visit(link.head);
1869 } 1869 }
1870 } 1870 }
1871 1871
1872 visitOperator(Operator node) { 1872 visitOperator(Operator node) {
1873 unimplemented(node, 'operator'); 1873 unimplemented(node, 'operator');
1874 } 1874 }
1875 1875
1876 visitReturn(Return node) { 1876 visitReturn(Return node) {
1877 if (node.isRedirectingFactoryBody) { 1877 if (node.isRedirectingFactoryBody) {
1878 unimplemented(node, 'redirecting constructors'); 1878 useElement(node.expression, resolveRedirectingFactory(node));
1879 } else {
1880 visit(node.expression);
1879 } 1881 }
1880 visit(node.expression);
1881 } 1882 }
1882 1883
1883 visitThrow(Throw node) { 1884 visitThrow(Throw node) {
1884 if (!inCatchBlock && node.expression == null) { 1885 if (!inCatchBlock && node.expression == null) {
1885 error(node, MessageKind.THROW_WITHOUT_EXPRESSION); 1886 error(node, MessageKind.THROW_WITHOUT_EXPRESSION);
1886 } 1887 }
1887 visit(node.expression); 1888 visit(node.expression);
1888 } 1889 }
1889 1890
1890 visitVariableDefinitions(VariableDefinitions node) { 1891 visitVariableDefinitions(VariableDefinitions node) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 1945
1945 /** 1946 /**
1946 * Try to resolve the constructor that is referred to by [node]. 1947 * Try to resolve the constructor that is referred to by [node].
1947 * Note: this function may return an ErroneousFunctionElement instead of 1948 * Note: this function may return an ErroneousFunctionElement instead of
1948 * [null], if there is no corresponding constructor, class or library. 1949 * [null], if there is no corresponding constructor, class or library.
1949 */ 1950 */
1950 FunctionElement resolveConstructor(NewExpression node) { 1951 FunctionElement resolveConstructor(NewExpression node) {
1951 return node.accept(new ConstructorResolver(compiler, this)); 1952 return node.accept(new ConstructorResolver(compiler, this));
1952 } 1953 }
1953 1954
1955 FunctionElement resolveRedirectingFactory(Return node) {
1956 return node.accept(new ConstructorResolver(compiler, this));
1957 }
1958
1954 DartType resolveTypeRequired(TypeAnnotation node) { 1959 DartType resolveTypeRequired(TypeAnnotation node) {
1955 bool old = typeRequired; 1960 bool old = typeRequired;
1956 typeRequired = true; 1961 typeRequired = true;
1957 DartType result = resolveTypeAnnotation(node); 1962 DartType result = resolveTypeAnnotation(node);
1958 typeRequired = old; 1963 typeRequired = old;
1959 return result; 1964 return result;
1960 } 1965 }
1961 1966
1962 void analyzeTypeArgument(DartType annotation, DartType argument) { 1967 void analyzeTypeArgument(DartType annotation, DartType argument) {
1963 if (argument == null) return; 1968 if (argument == null) return;
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2938 } else if (inConstContext && !result.modifiers.isConst()) { 2943 } else if (inConstContext && !result.modifiers.isConst()) {
2939 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); 2944 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST);
2940 } 2945 }
2941 return result; 2946 return result;
2942 } 2947 }
2943 2948
2944 visitNewExpression(NewExpression node) { 2949 visitNewExpression(NewExpression node) {
2945 inConstContext = node.isConst(); 2950 inConstContext = node.isConst();
2946 Node selector = node.send.selector; 2951 Node selector = node.send.selector;
2947 Element e = visit(selector); 2952 Element e = visit(selector);
2948 if (!Elements.isUnresolved(e) && identical(e.kind, ElementKind.CLASS)) { 2953 return finishConstructorReference(e, node.send.selector, node);
2954 }
2955
2956 /// Finishes resolution of a constructor reference and records the
2957 /// type of the constructed instance on [expression].
2958 FunctionElement finishConstructorReference(Element e,
2959 Node diagnosticNode,
2960 Expression expression) {
2961 // Find the unnamed constructor if the reference resolved to a
2962 // class.
2963 if (!Elements.isUnresolved(e) && e.isClass()) {
2949 ClassElement cls = e; 2964 ClassElement cls = e;
2950 cls.ensureResolved(compiler); 2965 cls.ensureResolved(compiler);
2951 if (cls.isInterface() && (cls.defaultClass == null)) { 2966 if (cls.isInterface() && (cls.defaultClass == null)) {
2952 error(selector, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]); 2967 // TODO(ahe): Remove this check and error message when we
2968 // don't have interfaces anymore.
2969 error(diagnosticNode,
2970 MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]);
2953 } 2971 }
2954 e = lookupConstructor(cls, selector, const SourceString('')); 2972 // The unnamed constructor may not exist, so [e] may become unresolved.
2973 e = lookupConstructor(cls, diagnosticNode, const SourceString(''));
2955 } 2974 }
2956 if (type == null) { 2975 if (type == null) {
2957 if (Elements.isUnresolved(e)) { 2976 if (Elements.isUnresolved(e)) {
2958 type = compiler.dynamicClass.computeType(compiler); 2977 type = compiler.dynamicClass.computeType(compiler);
2959 } else { 2978 } else {
2960 type = e.getEnclosingClass().computeType(compiler).asRaw(); 2979 type = e.getEnclosingClass().computeType(compiler).asRaw();
2961 } 2980 }
2962 } 2981 }
2963 resolver.mapping.setType(node, type); 2982 resolver.mapping.setType(expression, type);
2964 return e; 2983 return e;
2965 } 2984 }
2966 2985
2967 visitTypeAnnotation(TypeAnnotation node) { 2986 visitTypeAnnotation(TypeAnnotation node) {
2968 assert(invariant(node, type == null)); 2987 assert(invariant(node, type == null));
2969 type = resolver.resolveTypeRequired(node); 2988 type = resolver.resolveTypeRequired(node);
2970 return resolver.mapping[node]; 2989 return resolver.mapping[node];
2971 } 2990 }
2972 2991
2973 visitSend(Send node) { 2992 visitSend(Send node) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3011 } else if (identical(e.kind, ElementKind.TYPEDEF)) { 3030 } else if (identical(e.kind, ElementKind.TYPEDEF)) {
3012 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); 3031 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]);
3013 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { 3032 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) {
3014 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); 3033 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]);
3015 } else if (!identical(e.kind, ElementKind.CLASS) 3034 } else if (!identical(e.kind, ElementKind.CLASS)
3016 && !identical(e.kind, ElementKind.PREFIX)) { 3035 && !identical(e.kind, ElementKind.PREFIX)) {
3017 error(node, MessageKind.NOT_A_TYPE, [name]); 3036 error(node, MessageKind.NOT_A_TYPE, [name]);
3018 } 3037 }
3019 return e; 3038 return e;
3020 } 3039 }
3040
3041 /// Assumed to be called by [resolveRedirectingFactory].
3042 Element visitReturn(Return node) {
3043 Expression expression = node.expression;
3044 return finishConstructorReference(visit(expression),
3045 expression, expression);
3046 }
3021 } 3047 }
OLDNEW
« no previous file with comments | « no previous file | dart/sdk/lib/_internal/compiler/implementation/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698