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 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1863 visit(link.head); | 1863 visit(link.head); |
1864 } | 1864 } |
1865 } | 1865 } |
1866 | 1866 |
1867 visitOperator(Operator node) { | 1867 visitOperator(Operator node) { |
1868 unimplemented(node, 'operator'); | 1868 unimplemented(node, 'operator'); |
1869 } | 1869 } |
1870 | 1870 |
1871 visitReturn(Return node) { | 1871 visitReturn(Return node) { |
1872 if (node.isRedirectingFactoryBody) { | 1872 if (node.isRedirectingFactoryBody) { |
1873 useElement(node.expression, resolveRedirectingFactory(node)); | 1873 handleRedirectingFactoryBody(node); |
1874 } else { | 1874 } else { |
1875 visit(node.expression); | 1875 visit(node.expression); |
1876 } | 1876 } |
1877 } | 1877 } |
1878 | 1878 |
| 1879 void handleRedirectingFactoryBody(Return node) { |
| 1880 Element redirectionTarget = resolveRedirectingFactory(node); |
| 1881 var type = mapping.getType(node.expression); |
| 1882 if (type is InterfaceType && !type.arguments.isEmpty) { |
| 1883 unimplemented(node.expression, 'type arguments on redirecting factory'); |
| 1884 } |
| 1885 useElement(node.expression, redirectionTarget); |
| 1886 assert(invariant(node, enclosingElement.isFactoryConstructor())); |
| 1887 FunctionElement constructor = enclosingElement; |
| 1888 if (constructor.modifiers.isConst() && |
| 1889 !redirectionTarget.modifiers.isConst()) { |
| 1890 error(node, MessageKind.CONSTRUCTOR_IS_NOT_CONST); |
| 1891 } |
| 1892 // TODO(ahe): Check that this doesn't lead to a cycle. For now, |
| 1893 // just make sure that the redirection target isn't itself a |
| 1894 // redirecting factory. |
| 1895 { // This entire block is temporary code per the above TODO. |
| 1896 FunctionElement targetImplementation = redirectionTarget.implementation; |
| 1897 FunctionExpression function = targetImplementation.parseNode(compiler); |
| 1898 if (function.body != null && function.body.asReturn() != null |
| 1899 && function.body.asReturn().isRedirectingFactoryBody) { |
| 1900 unimplemented(node.expression, 'redirecing to redirecting factory'); |
| 1901 } |
| 1902 } |
| 1903 constructor.defaultImplementation = redirectionTarget; |
| 1904 world.registerStaticUse(redirectionTarget); |
| 1905 } |
| 1906 |
1879 visitThrow(Throw node) { | 1907 visitThrow(Throw node) { |
1880 if (!inCatchBlock && node.expression == null) { | 1908 if (!inCatchBlock && node.expression == null) { |
1881 error(node, MessageKind.THROW_WITHOUT_EXPRESSION); | 1909 error(node, MessageKind.THROW_WITHOUT_EXPRESSION); |
1882 } | 1910 } |
1883 visit(node.expression); | 1911 visit(node.expression); |
1884 } | 1912 } |
1885 | 1913 |
1886 visitVariableDefinitions(VariableDefinitions node) { | 1914 visitVariableDefinitions(VariableDefinitions node) { |
1887 visit(node.type); | 1915 visit(node.type); |
1888 VariableDefinitionsVisitor visitor = | 1916 VariableDefinitionsVisitor visitor = |
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3033 return e; | 3061 return e; |
3034 } | 3062 } |
3035 | 3063 |
3036 /// Assumed to be called by [resolveRedirectingFactory]. | 3064 /// Assumed to be called by [resolveRedirectingFactory]. |
3037 Element visitReturn(Return node) { | 3065 Element visitReturn(Return node) { |
3038 Node expression = node.expression; | 3066 Node expression = node.expression; |
3039 return finishConstructorReference(visit(expression), | 3067 return finishConstructorReference(visit(expression), |
3040 expression, expression); | 3068 expression, expression); |
3041 } | 3069 } |
3042 } | 3070 } |
OLD | NEW |