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 abstract class TreeElements { | 5 abstract class TreeElements { |
| 6 Element operator[](Node node); | 6 Element operator[](Node node); |
| 7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
| 8 DartType getType(Node node); | 8 DartType getType(Node node); |
| 9 bool isParameterChecked(Element element); | 9 bool isParameterChecked(Element element); |
| 10 } | 10 } |
| (...skipping 1814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1825 visit(link.head); | 1825 visit(link.head); |
| 1826 } | 1826 } |
| 1827 } | 1827 } |
| 1828 | 1828 |
| 1829 visitOperator(Operator node) { | 1829 visitOperator(Operator node) { |
| 1830 unimplemented(node, 'operator'); | 1830 unimplemented(node, 'operator'); |
| 1831 } | 1831 } |
| 1832 | 1832 |
| 1833 visitReturn(Return node) { | 1833 visitReturn(Return node) { |
| 1834 if (node.isRedirectingFactoryBody) { | 1834 if (node.isRedirectingFactoryBody) { |
| 1835 unimplemented(node, 'redirecting constructors'); | 1835 return resolveRedirectingFactory(node); |
| 1836 } | 1836 } |
| 1837 visit(node.expression); | 1837 visit(node.expression); |
| 1838 } | 1838 } |
| 1839 | 1839 |
| 1840 visitThrow(Throw node) { | 1840 visitThrow(Throw node) { |
| 1841 if (!inCatchBlock && node.expression == null) { | 1841 if (!inCatchBlock && node.expression == null) { |
| 1842 error(node, MessageKind.THROW_WITHOUT_EXPRESSION); | 1842 error(node, MessageKind.THROW_WITHOUT_EXPRESSION); |
| 1843 } | 1843 } |
| 1844 visit(node.expression); | 1844 visit(node.expression); |
| 1845 } | 1845 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1901 | 1901 |
| 1902 /** | 1902 /** |
| 1903 * Try to resolve the constructor that is referred to by [node]. | 1903 * Try to resolve the constructor that is referred to by [node]. |
| 1904 * Note: this function may return an ErroneousFunctionElement instead of | 1904 * Note: this function may return an ErroneousFunctionElement instead of |
| 1905 * [null], if there is no corresponding constructor, class or library. | 1905 * [null], if there is no corresponding constructor, class or library. |
| 1906 */ | 1906 */ |
| 1907 FunctionElement resolveConstructor(NewExpression node) { | 1907 FunctionElement resolveConstructor(NewExpression node) { |
| 1908 return node.accept(new ConstructorResolver(compiler, this)); | 1908 return node.accept(new ConstructorResolver(compiler, this)); |
| 1909 } | 1909 } |
| 1910 | 1910 |
| 1911 FunctionElement resolveRedirectingFactory(Return node) { | |
| 1912 return node.accept(new ConstructorResolver(compiler, this)); | |
| 1913 } | |
| 1914 | |
| 1911 DartType resolveTypeRequired(TypeAnnotation node) { | 1915 DartType resolveTypeRequired(TypeAnnotation node) { |
| 1912 bool old = typeRequired; | 1916 bool old = typeRequired; |
| 1913 typeRequired = true; | 1917 typeRequired = true; |
| 1914 DartType result = resolveTypeAnnotation(node); | 1918 DartType result = resolveTypeAnnotation(node); |
| 1915 typeRequired = old; | 1919 typeRequired = old; |
| 1916 return result; | 1920 return result; |
| 1917 } | 1921 } |
| 1918 | 1922 |
| 1919 void analyzeTypeArgument(DartType annotation, DartType argument) { | 1923 void analyzeTypeArgument(DartType annotation, DartType argument) { |
| 1920 if (argument == null) return; | 1924 if (argument == null) return; |
| (...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2868 } else if (inConstContext && !result.modifiers.isConst()) { | 2872 } else if (inConstContext && !result.modifiers.isConst()) { |
| 2869 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); | 2873 error(diagnosticNode, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
| 2870 } | 2874 } |
| 2871 return result; | 2875 return result; |
| 2872 } | 2876 } |
| 2873 | 2877 |
| 2874 visitNewExpression(NewExpression node) { | 2878 visitNewExpression(NewExpression node) { |
| 2875 inConstContext = node.isConst(); | 2879 inConstContext = node.isConst(); |
| 2876 Node selector = node.send.selector; | 2880 Node selector = node.send.selector; |
| 2877 Element e = visit(selector); | 2881 Element e = visit(selector); |
| 2882 e = finishConstructorReference(e, node.send.selector); | |
| 2883 resolver.mapping.setType(node, type); | |
|
Johnni Winther
2012/10/22 09:47:34
I don't like the implicit handling of [type]. Coul
| |
| 2884 return e; | |
| 2885 } | |
| 2886 | |
| 2887 FunctionElement finishConstructorReference(Element e, Node node) { | |
| 2878 if (!Elements.isUnresolved(e) && identical(e.kind, ElementKind.CLASS)) { | 2888 if (!Elements.isUnresolved(e) && identical(e.kind, ElementKind.CLASS)) { |
| 2879 ClassElement cls = e; | 2889 ClassElement cls = e; |
| 2880 cls.ensureResolved(compiler); | 2890 cls.ensureResolved(compiler); |
| 2881 if (cls.isInterface() && (cls.defaultClass == null)) { | 2891 if (cls.isInterface() && (cls.defaultClass == null)) { |
| 2882 error(selector, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]); | 2892 error(node, MessageKind.CANNOT_INSTANTIATE_INTERFACE, [cls.name]); |
| 2883 } | 2893 } |
| 2884 e = lookupConstructor(cls, selector, const SourceString('')); | 2894 e = lookupConstructor(cls, node, const SourceString('')); |
| 2885 } | 2895 } |
| 2886 if (type == null) { | 2896 if (type == null) { |
| 2887 type = e.getEnclosingClass().computeType(compiler); | 2897 if (Elements.isUnresolved(e)) { |
| 2898 type = compiler.dynamicClass.computeType(compiler); | |
| 2899 } else { | |
| 2900 type = e.getEnclosingClass().computeType(compiler).asRaw(); | |
|
Johnni Winther
2012/10/22 09:47:34
This is the right type!
| |
| 2901 } | |
| 2888 } | 2902 } |
| 2889 resolver.mapping.setType(node, type); | |
| 2890 return e; | 2903 return e; |
| 2891 } | 2904 } |
| 2892 | 2905 |
| 2893 visitTypeAnnotation(TypeAnnotation node) { | 2906 visitTypeAnnotation(TypeAnnotation node) { |
| 2894 assert(invariant(node, type == null)); | 2907 assert(invariant(node, type == null)); |
| 2895 type = resolver.resolveTypeRequired(node); | 2908 type = resolver.resolveTypeRequired(node); |
| 2896 return resolver.mapping[node]; | 2909 return resolver.mapping[node]; |
| 2897 } | 2910 } |
| 2898 | 2911 |
| 2899 visitSend(Send node) { | 2912 visitSend(Send node) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2937 } else if (identical(e.kind, ElementKind.TYPEDEF)) { | 2950 } else if (identical(e.kind, ElementKind.TYPEDEF)) { |
| 2938 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); | 2951 error(node, MessageKind.CANNOT_INSTANTIATE_TYPEDEF, [name]); |
| 2939 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { | 2952 } else if (identical(e.kind, ElementKind.TYPE_VARIABLE)) { |
| 2940 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); | 2953 error(node, MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE, [name]); |
| 2941 } else if (!identical(e.kind, ElementKind.CLASS) | 2954 } else if (!identical(e.kind, ElementKind.CLASS) |
| 2942 && !identical(e.kind, ElementKind.PREFIX)) { | 2955 && !identical(e.kind, ElementKind.PREFIX)) { |
| 2943 error(node, MessageKind.NOT_A_TYPE, [name]); | 2956 error(node, MessageKind.NOT_A_TYPE, [name]); |
| 2944 } | 2957 } |
| 2945 return e; | 2958 return e; |
| 2946 } | 2959 } |
| 2960 | |
| 2961 /// Assumed to be called by [resolveRedirectingFactory]. | |
| 2962 Element visitReturn(Return node) { | |
| 2963 Element e = visit(node.expression); | |
| 2964 e = finishConstructorReference(e, node.expression); | |
| 2965 resolver.mapping.setType(node, type); | |
| 2966 // TODO(ahe): Remove this debug warning when this is fully implemented. | |
| 2967 warning(node.expression, MessageKind.GENERIC, ['e = $e; type = $type']); | |
| 2968 return e; | |
| 2969 } | |
| 2947 } | 2970 } |
| 2948 | 2971 |
| 2949 abstract class Scope { | 2972 abstract class Scope { |
| 2950 final Element element; | 2973 final Element element; |
| 2951 final Scope parent; | 2974 final Scope parent; |
| 2952 | 2975 |
| 2953 Scope(this.parent, this.element); | 2976 Scope(this.parent, this.element); |
| 2954 abstract Element add(Element element); | 2977 abstract Element add(Element element); |
| 2955 | 2978 |
| 2956 Element lookup(SourceString name) { | 2979 Element lookup(SourceString name) { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3170 return result; | 3193 return result; |
| 3171 } | 3194 } |
| 3172 Element lookup(SourceString name) => localLookup(name); | 3195 Element lookup(SourceString name) => localLookup(name); |
| 3173 Element lexicalLookup(SourceString name) => localLookup(name); | 3196 Element lexicalLookup(SourceString name) => localLookup(name); |
| 3174 | 3197 |
| 3175 Element add(Element newElement) { | 3198 Element add(Element newElement) { |
| 3176 throw "Cannot add an element in a patch library scope"; | 3199 throw "Cannot add an element in a patch library scope"; |
| 3177 } | 3200 } |
| 3178 String toString() => 'PatchLibraryScope($origin,$patch)'; | 3201 String toString() => 'PatchLibraryScope($origin,$patch)'; |
| 3179 } | 3202 } |
| OLD | NEW |