Chromium Code Reviews| 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 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1846 visit(link.head); | 1846 visit(link.head); |
| 1847 } | 1847 } |
| 1848 } | 1848 } |
| 1849 | 1849 |
| 1850 visitOperator(Operator node) { | 1850 visitOperator(Operator node) { |
| 1851 unimplemented(node, 'operator'); | 1851 unimplemented(node, 'operator'); |
| 1852 } | 1852 } |
| 1853 | 1853 |
| 1854 visitReturn(Return node) { | 1854 visitReturn(Return node) { |
| 1855 if (node.isRedirectingFactoryBody) { | 1855 if (node.isRedirectingFactoryBody) { |
| 1856 unimplemented(node, 'redirecting constructors'); | 1856 return resolveRedirectingFactory(node); |
| 1857 } | 1857 } |
| 1858 visit(node.expression); | 1858 visit(node.expression); |
| 1859 } | 1859 } |
| 1860 | 1860 |
| 1861 visitThrow(Throw node) { | 1861 visitThrow(Throw node) { |
| 1862 if (!inCatchBlock && node.expression == null) { | 1862 if (!inCatchBlock && node.expression == null) { |
| 1863 error(node, MessageKind.THROW_WITHOUT_EXPRESSION); | 1863 error(node, MessageKind.THROW_WITHOUT_EXPRESSION); |
| 1864 } | 1864 } |
| 1865 visit(node.expression); | 1865 visit(node.expression); |
| 1866 } | 1866 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1922 | 1922 |
| 1923 /** | 1923 /** |
| 1924 * Try to resolve the constructor that is referred to by [node]. | 1924 * Try to resolve the constructor that is referred to by [node]. |
| 1925 * Note: this function may return an ErroneousFunctionElement instead of | 1925 * Note: this function may return an ErroneousFunctionElement instead of |
| 1926 * [null], if there is no corresponding constructor, class or library. | 1926 * [null], if there is no corresponding constructor, class or library. |
| 1927 */ | 1927 */ |
| 1928 FunctionElement resolveConstructor(NewExpression node) { | 1928 FunctionElement resolveConstructor(NewExpression node) { |
| 1929 return node.accept(new ConstructorResolver(compiler, this)); | 1929 return node.accept(new ConstructorResolver(compiler, this)); |
| 1930 } | 1930 } |
| 1931 | 1931 |
| 1932 FunctionElement resolveRedirectingFactory(Return node) { | |
| 1933 return node.accept(new ConstructorResolver(compiler, this)); | |
| 1934 } | |
| 1935 | |
| 1932 DartType resolveTypeRequired(TypeAnnotation node) { | 1936 DartType resolveTypeRequired(TypeAnnotation node) { |
| 1933 bool old = typeRequired; | 1937 bool old = typeRequired; |
| 1934 typeRequired = true; | 1938 typeRequired = true; |
| 1935 DartType result = resolveTypeAnnotation(node); | 1939 DartType result = resolveTypeAnnotation(node); |
| 1936 typeRequired = old; | 1940 typeRequired = old; |
| 1937 return result; | 1941 return result; |
| 1938 } | 1942 } |
| 1939 | 1943 |
| 1940 void analyzeTypeArgument(DartType annotation, DartType argument) { | 1944 void analyzeTypeArgument(DartType annotation, DartType argument) { |
| 1941 if (argument == null) return; | 1945 if (argument == null) return; |
| (...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2916 } else if (inConstContext && !result.modifiers.isConst()) { | 2920 } else if (inConstContext && !result.modifiers.isConst()) { |
| 2917 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); | 2921 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
| 2918 } | 2922 } |
| 2919 return result; | 2923 return result; |
| 2920 } | 2924 } |
| 2921 | 2925 |
| 2922 visitNewExpression(NewExpression node) { | 2926 visitNewExpression(NewExpression node) { |
| 2923 inConstContext = node.isConst(); | 2927 inConstContext = node.isConst(); |
| 2924 Node selector = node.send.selector; | 2928 Node selector = node.send.selector; |
| 2925 Element e = visit(selector); | 2929 Element e = visit(selector); |
| 2930 e = finishConstructorReference(e, node.send.selector); | |
| 2931 resolver.mapping.setType(node, type); | |
| 2932 return e; | |
| 2933 } | |
| 2934 | |
| 2935 FunctionElement finishConstructorReference(Element e, Node node) { | |
|
Johnni Winther
2012/11/05 13:49:33
Strange name. Document the method.
| |
| 2926 if (!Elements.isUnresolved(e) && identical(e.kind, ElementKind.CLASS)) { | 2936 if (!Elements.isUnresolved(e) && identical(e.kind, ElementKind.CLASS)) { |
| 2927 ClassElement cls = e; | 2937 ClassElement cls = e; |
| 2928 cls.ensureResolved(compiler); | 2938 cls.ensureResolved(compiler); |
| 2929 if (cls.isInterface() && (cls.defaultClass == null)) { | 2939 if (cls.isInterface() && (cls.defaultClass == null)) { |
| 2930 error(selector, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]); | 2940 error(node, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]); |
| 2931 } | 2941 } |
| 2932 e = lookupConstructor(cls, selector, const SourceString('')); | 2942 e = lookupConstructor(cls, node, const SourceString('')); |
| 2933 } | 2943 } |
| 2934 if (type == null) { | 2944 if (type == null) { |
| 2935 if (Elements.isUnresolved(e)) { | 2945 if (Elements.isUnresolved(e)) { |
| 2936 type = compiler.dynamicClass.computeType(compiler); | 2946 type = compiler.dynamicClass.computeType(compiler); |
| 2937 } else { | 2947 } else { |
| 2938 type = e.getEnclosingClass().computeType(compiler).asRaw(); | 2948 type = e.getEnclosingClass().computeType(compiler).asRaw(); |
| 2939 } | 2949 } |
| 2940 } | 2950 } |
| 2941 resolver.mapping.setType(node, type); | |
| 2942 return e; | 2951 return e; |
| 2943 } | 2952 } |
| 2944 | 2953 |
| 2945 visitTypeAnnotation(TypeAnnotation node) { | 2954 visitTypeAnnotation(TypeAnnotation node) { |
| 2946 assert(invariant(node, type == null)); | 2955 assert(invariant(node, type == null)); |
| 2947 type = resolver.resolveTypeRequired(node); | 2956 type = resolver.resolveTypeRequired(node); |
| 2948 return resolver.mapping[node]; | 2957 return resolver.mapping[node]; |
| 2949 } | 2958 } |
| 2950 | 2959 |
| 2951 visitSend(Send node) { | 2960 visitSend(Send node) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2989 } else if (identical(e.kind, ElementKind.TYPEDEF)) { | 2998 } else if (identical(e.kind, ElementKind.TYPEDEF)) { |
| 2990 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); | 2999 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); |
| 2991 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { | 3000 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { |
| 2992 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); | 3001 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); |
| 2993 } else if (!identical(e.kind, ElementKind.CLASS) | 3002 } else if (!identical(e.kind, ElementKind.CLASS) |
| 2994 && !identical(e.kind, ElementKind.PREFIX)) { | 3003 && !identical(e.kind, ElementKind.PREFIX)) { |
| 2995 error(node, MessageKind.NOT_A_TYPE, [name]); | 3004 error(node, MessageKind.NOT_A_TYPE, [name]); |
| 2996 } | 3005 } |
| 2997 return e; | 3006 return e; |
| 2998 } | 3007 } |
| 3008 | |
| 3009 /// Assumed to be called by [resolveRedirectingFactory]. | |
| 3010 Element visitReturn(Return node) { | |
| 3011 Element e = visit(node.expression); | |
| 3012 e = finishConstructorReference(e, node.expression); | |
| 3013 resolver.mapping.setType(node, type); | |
| 3014 // TODO(ahe): Remove this debug warning when this is fully implemented. | |
| 3015 warning(node.expression, MessageKind.GENERIC, ['e = $e; type = $type']); | |
| 3016 return e; | |
| 3017 } | |
| 2999 } | 3018 } |
| OLD | NEW |