| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library dart2js.send_structure; | 5 library dart2js.send_structure; |
| 6 | 6 |
| 7 import 'access_semantics.dart'; | 7 import 'access_semantics.dart'; |
| 8 import 'operators.dart'; | 8 import 'operators.dart'; |
| 9 import 'semantic_visitor.dart'; | 9 import 'semantic_visitor.dart'; |
| 10 import '../dart_types.dart'; | 10 import '../dart_types.dart'; |
| (...skipping 1856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1867 class ConstInvokeStructure<R, A> extends NewStructure<R, A> { | 1867 class ConstInvokeStructure<R, A> extends NewStructure<R, A> { |
| 1868 final ConstructedConstantExpression constant; | 1868 final ConstructedConstantExpression constant; |
| 1869 | 1869 |
| 1870 ConstInvokeStructure(this.constant); | 1870 ConstInvokeStructure(this.constant); |
| 1871 | 1871 |
| 1872 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) { | 1872 R dispatch(SemanticSendVisitor<R, A> visitor, NewExpression node, A arg) { |
| 1873 return visitor.visitConstConstructorInvoke(node, constant, arg); | 1873 return visitor.visitConstConstructorInvoke(node, constant, arg); |
| 1874 } | 1874 } |
| 1875 } | 1875 } |
| 1876 | 1876 |
| 1877 /// The structure of a parameter declaration. |
| 1878 abstract class ParameterStructure<R, A> { |
| 1879 /// Calls the matching visit method on [visitor] with [definitions] and [arg]. |
| 1880 R dispatch(SemanticDeclVisitor<R, A> visitor, |
| 1881 VariableDefinitions definitions, |
| 1882 A arg); |
| 1883 } |
| 1884 |
| 1885 /// The structure of a required parameter declaration. |
| 1886 class RequiredParameterStructure<R, A> extends ParameterStructure<R, A> { |
| 1887 final ParameterElement parameter; |
| 1888 final Node node; |
| 1889 final int index; |
| 1890 |
| 1891 RequiredParameterStructure(this.node, this.parameter, this.index); |
| 1892 |
| 1893 R dispatch(SemanticDeclVisitor<R, A> visitor, |
| 1894 VariableDefinitions definitions, |
| 1895 A arg) { |
| 1896 if (parameter.isInitializingFormal) { |
| 1897 return visitor.visitInitializingFormalDecl( |
| 1898 definitions, node, parameter, index, arg); |
| 1899 } else { |
| 1900 return visitor.visitParameterDecl( |
| 1901 definitions, node, parameter, index, arg); |
| 1902 } |
| 1903 } |
| 1904 } |
| 1905 |
| 1906 /// The structure of a optional positional parameter declaration. |
| 1907 class OptionalParameterStructure<R, A> extends ParameterStructure<R, A> { |
| 1908 final ParameterElement parameter; |
| 1909 final Node node; |
| 1910 final ConstantExpression defaultValue; |
| 1911 final int index; |
| 1912 |
| 1913 OptionalParameterStructure( |
| 1914 this.node, this.parameter, this.defaultValue, this.index); |
| 1915 |
| 1916 R dispatch(SemanticDeclVisitor<R, A> visitor, |
| 1917 VariableDefinitions definitions, |
| 1918 A arg) { |
| 1919 if (parameter.isInitializingFormal) { |
| 1920 return visitor.visitOptionalInitializingFormalDecl( |
| 1921 definitions, node, parameter, defaultValue, index, arg); |
| 1922 } else { |
| 1923 return visitor.visitOptionalParameterDecl( |
| 1924 definitions, node, parameter, defaultValue, index, arg); |
| 1925 } |
| 1926 } |
| 1927 } |
| 1928 |
| 1929 /// The structure of a optional named parameter declaration. |
| 1930 class NamedParameterStructure<R, A> extends ParameterStructure<R, A> { |
| 1931 final ParameterElement parameter; |
| 1932 final Node node; |
| 1933 final ConstantExpression defaultValue; |
| 1934 |
| 1935 NamedParameterStructure(this.node, this.parameter, this.defaultValue); |
| 1936 |
| 1937 R dispatch(SemanticDeclVisitor<R, A> visitor, |
| 1938 VariableDefinitions definitions, |
| 1939 A arg) { |
| 1940 if (parameter.isInitializingFormal) { |
| 1941 return visitor.visitNamedInitializingFormalDecl( |
| 1942 definitions, node, parameter, defaultValue, arg); |
| 1943 } else { |
| 1944 return visitor.visitNamedParameterDecl( |
| 1945 definitions, node, parameter, defaultValue, arg); |
| 1946 } |
| 1947 } |
| 1948 } |
| 1949 |
| 1950 |
| 1951 enum VariableKind { |
| 1952 TOP_LEVEL_FIELD, |
| 1953 STATIC_FIELD, |
| 1954 INSTANCE_FIELD, |
| 1955 LOCAL_VARIABLE, |
| 1956 } |
| 1957 |
| 1958 abstract class VariableStructure<R, A> { |
| 1959 final VariableKind kind; |
| 1960 final Node node; |
| 1961 final VariableElement variable; |
| 1962 |
| 1963 VariableStructure(this.kind, this.node, this.variable); |
| 1964 |
| 1965 R dispatch(SemanticDeclVisitor<R, A> visitor, |
| 1966 VariableDefinitions definitions, |
| 1967 A arg); |
| 1968 } |
| 1969 |
| 1970 class NonConstantVariableStructure<R, A> |
| 1971 extends VariableStructure<R, A> { |
| 1972 NonConstantVariableStructure( |
| 1973 VariableKind kind, Node node, VariableElement variable) |
| 1974 : super(kind, node, variable); |
| 1975 |
| 1976 R dispatch(SemanticDeclVisitor<R, A> visitor, |
| 1977 VariableDefinitions definitions, |
| 1978 A arg) { |
| 1979 switch (kind) { |
| 1980 case VariableKind.TOP_LEVEL_FIELD: |
| 1981 return visitor.visitTopLevelFieldDecl( |
| 1982 definitions, node, variable, variable.initializer, arg); |
| 1983 case VariableKind.STATIC_FIELD: |
| 1984 return visitor.visitStaticFieldDecl( |
| 1985 definitions, node, variable, variable.initializer, arg); |
| 1986 case VariableKind.INSTANCE_FIELD: |
| 1987 return visitor.visitInstanceFieldDecl( |
| 1988 definitions, node, variable, variable.initializer, arg); |
| 1989 case VariableKind.LOCAL_VARIABLE: |
| 1990 return visitor.visitLocalVariableDecl( |
| 1991 definitions, node, variable, variable.initializer, arg); |
| 1992 } |
| 1993 } |
| 1994 } |
| 1995 |
| 1996 class ConstantVariableStructure<R, A> |
| 1997 extends VariableStructure<R, A> { |
| 1998 final ConstantExpression constant; |
| 1999 |
| 2000 ConstantVariableStructure( |
| 2001 VariableKind kind, Node node, VariableElement variable, this.constant) |
| 2002 : super(kind, node, variable); |
| 2003 |
| 2004 R dispatch(SemanticDeclVisitor<R, A> visitor, |
| 2005 VariableDefinitions definitions, |
| 2006 A arg) { |
| 2007 switch (kind) { |
| 2008 case VariableKind.TOP_LEVEL_FIELD: |
| 2009 return visitor.visitTopLevelConstantDecl( |
| 2010 definitions, node, variable, constant, arg); |
| 2011 case VariableKind.STATIC_FIELD: |
| 2012 return visitor.visitStaticConstantDecl( |
| 2013 definitions, node, variable, constant, arg); |
| 2014 case VariableKind.LOCAL_VARIABLE: |
| 2015 return visitor.visitLocalConstantDecl( |
| 2016 definitions, node, variable, constant, arg); |
| 2017 default: |
| 2018 } |
| 2019 throw new SpannableAssertionFailure( |
| 2020 node, "Invalid constant variable: $variable"); |
| 2021 } |
| 2022 } |
| 2023 |
| 2024 abstract class InitializerStructure<R, A> { |
| 2025 R dispatch(SemanticDeclVisitor<R, A> visitor, Send node, A arg); |
| 2026 } |
| 2027 |
| 2028 class FieldInitializerStructure<R, A> extends InitializerStructure<R, A> { |
| 2029 final FieldElement field; |
| 2030 |
| 2031 FieldInitializerStructure(this.field); |
| 2032 |
| 2033 R dispatch(SemanticDeclVisitor<R, A> visitor, Send node, A arg) { |
| 2034 return visitor.visitFieldInitializer( |
| 2035 node, field, node.arguments.single, arg); |
| 2036 } |
| 2037 } |
| 2038 |
| 2039 class SuperConstructorInvokeStructure<R, A> extends InitializerStructure<R, A> { |
| 2040 final ConstructorElement constructor; |
| 2041 final InterfaceType type; |
| 2042 final Selector selector; |
| 2043 |
| 2044 SuperConstructorInvokeStructure(this.constructor, this.type, this.selector); |
| 2045 |
| 2046 R dispatch(SemanticDeclVisitor<R, A> visitor, Send node, A arg) { |
| 2047 return visitor.visitSuperConstructorInvoke( |
| 2048 node, constructor, type, node.argumentsNode, selector, arg); |
| 2049 } |
| 2050 } |
| 2051 |
| 2052 class ThisConstructorInvokeStructure<R, A> extends InitializerStructure<R, A> { |
| 2053 final ConstructorElement constructor; |
| 2054 final Selector selector; |
| 2055 |
| 2056 ThisConstructorInvokeStructure(this.constructor, this.selector); |
| 2057 |
| 2058 R dispatch(SemanticDeclVisitor<R, A> visitor, Send node, A arg) { |
| 2059 return visitor.visitThisConstructorInvoke( |
| 2060 node, constructor, node.argumentsNode, selector, arg); |
| 2061 } |
| 2062 } |
| OLD | NEW |