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 interface TreeElements { | 5 interface TreeElements { |
6 Element operator[](Node node); | 6 Element operator[](Node node); |
7 Selector getSelector(Send send); | 7 Selector getSelector(Send send); |
8 Type getType(TypeAnnotation annotation); | 8 Type getType(TypeAnnotation annotation); |
9 } | 9 } |
10 | 10 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 // resolution in case there is an implicit super constructor call. | 132 // resolution in case there is an implicit super constructor call. |
133 InitializerResolver resolver = new InitializerResolver(visitor); | 133 InitializerResolver resolver = new InitializerResolver(visitor); |
134 FunctionElement redirection = | 134 FunctionElement redirection = |
135 resolver.resolveInitializers(element, tree); | 135 resolver.resolveInitializers(element, tree); |
136 if (redirection !== null) { | 136 if (redirection !== null) { |
137 resolveRedirectingConstructor(resolver, tree, element, redirection); | 137 resolveRedirectingConstructor(resolver, tree, element, redirection); |
138 } | 138 } |
139 } else if (tree.initializers != null) { | 139 } else if (tree.initializers != null) { |
140 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER); | 140 error(tree, MessageKind.FUNCTION_WITH_INITIALIZER); |
141 } | 141 } |
142 visitor.visit(tree.body); | 142 visitBody(visitor, tree.body); |
143 | 143 |
144 // Resolve the type annotations encountered in the method. | 144 // Resolve the type annotations encountered in the method. |
145 while (!toResolve.isEmpty()) { | 145 while (!toResolve.isEmpty()) { |
146 ClassElement classElement = toResolve.removeFirst(); | 146 ClassElement classElement = toResolve.removeFirst(); |
147 classElement.ensureResolved(compiler); | 147 classElement.ensureResolved(compiler); |
148 } | 148 } |
149 if (isConstructor) { | 149 if (isConstructor) { |
150 constructorElements[element] = visitor.mapping; | 150 constructorElements[element] = visitor.mapping; |
151 } | 151 } |
152 return visitor.mapping; | 152 return visitor.mapping; |
153 }); | 153 }); |
154 } | 154 } |
155 | 155 |
156 void visitBody(ResolverVisitor visitor, Statement body) { | |
ahe
2012/08/02 19:56:23
What is the purpose of this method?
| |
157 visitor.visit(body); | |
158 } | |
159 | |
156 void resolveConstructorImplementation(FunctionElement constructor, | 160 void resolveConstructorImplementation(FunctionElement constructor, |
157 FunctionExpression node) { | 161 FunctionExpression node) { |
158 if (constructor.defaultImplementation !== constructor) return; | 162 if (constructor.defaultImplementation !== constructor) return; |
159 ClassElement intrface = constructor.enclosingElement; | 163 ClassElement intrface = constructor.enclosingElement; |
160 if (!intrface.isInterface()) return; | 164 if (!intrface.isInterface()) return; |
161 Type defaultType = intrface.defaultClass; | 165 Type defaultType = intrface.defaultClass; |
162 if (defaultType === null) { | 166 if (defaultType === null) { |
163 error(node, MessageKind.NO_DEFAULT_CLASS, [intrface.name]); | 167 error(node, MessageKind.NO_DEFAULT_CLASS, [intrface.name]); |
164 } | 168 } |
165 ClassElement defaultClass = defaultType.element; | 169 ClassElement defaultClass = defaultType.element; |
(...skipping 1764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1930 return element; | 1934 return element; |
1931 } | 1935 } |
1932 | 1936 |
1933 Element visitIdentifier(Identifier node) { | 1937 Element visitIdentifier(Identifier node) { |
1934 Element variables = new VariableListElement.node(currentDefinitions, | 1938 Element variables = new VariableListElement.node(currentDefinitions, |
1935 ElementKind.VARIABLE_LIST, enclosingElement); | 1939 ElementKind.VARIABLE_LIST, enclosingElement); |
1936 return new VariableElement(node.source, variables, | 1940 return new VariableElement(node.source, variables, |
1937 ElementKind.PARAMETER, enclosingElement, node: node); | 1941 ElementKind.PARAMETER, enclosingElement, node: node); |
1938 } | 1942 } |
1939 | 1943 |
1944 SourceString getParameterName(Send node) { | |
1945 var identifier = node.selector.asIdentifier(); | |
1946 if (identifier !== null) { | |
1947 // Normal parameter: [:Type name:]. | |
1948 return identifier.source; | |
1949 } else { | |
1950 // Function type parameter: [:void name(Type arg):]. | |
1951 var functionExpression = node.selector.asFunctionExpression(); | |
1952 if (functionExpression !== null && | |
1953 functionExpression.name.asIdentifier() !== null) { | |
1954 return functionExpression.name.asIdentifier().source; | |
1955 } else { | |
1956 cancel(node, | |
1957 'internal error: unimplemented receiver on parameter send'); | |
1958 } | |
1959 } | |
1960 } | |
1961 | |
1940 // The only valid [Send] can be in constructors and must be of the form | 1962 // The only valid [Send] can be in constructors and must be of the form |
1941 // [:this.x:] (where [:x:] represents an instance field). | 1963 // [:this.x:] (where [:x:] represents an instance field). |
1942 FieldParameterElement visitSend(Send node) { | 1964 FieldParameterElement visitSend(Send node) { |
1943 FieldParameterElement element; | 1965 FieldParameterElement element; |
1944 if (node.receiver.asIdentifier() === null || | 1966 if (node.receiver.asIdentifier() === null || |
1945 !node.receiver.asIdentifier().isThis()) { | 1967 !node.receiver.asIdentifier().isThis()) { |
1946 error(node, MessageKind.INVALID_PARAMETER, []); | 1968 error(node, MessageKind.INVALID_PARAMETER, []); |
1947 } else if (enclosingElement.kind !== ElementKind.GENERATIVE_CONSTRUCTOR) { | 1969 } else if (enclosingElement.kind !== ElementKind.GENERATIVE_CONSTRUCTOR) { |
1948 error(node, MessageKind.FIELD_PARAMETER_NOT_ALLOWED, []); | 1970 error(node, MessageKind.FIELD_PARAMETER_NOT_ALLOWED, []); |
1949 } else { | 1971 } else { |
1950 if (node.selector.asIdentifier() == null) { | 1972 SourceString name = getParameterName(node); |
1951 cancel(node, | |
1952 'internal error: unimplemented receiver on parameter send'); | |
1953 } | |
1954 SourceString name = node.selector.asIdentifier().source; | |
1955 Element fieldElement = currentClass.lookupLocalMember(name); | 1973 Element fieldElement = currentClass.lookupLocalMember(name); |
1956 if (fieldElement === null || fieldElement.kind !== ElementKind.FIELD) { | 1974 if (fieldElement === null || fieldElement.kind !== ElementKind.FIELD) { |
1957 error(node, MessageKind.NOT_A_FIELD, [name]); | 1975 error(node, MessageKind.NOT_A_FIELD, [name]); |
1958 } else if (!fieldElement.isInstanceMember()) { | 1976 } else if (!fieldElement.isInstanceMember()) { |
1959 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]); | 1977 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]); |
1960 } | 1978 } |
1961 Element variables = new VariableListElement.node(currentDefinitions, | 1979 Element variables = new VariableListElement.node(currentDefinitions, |
1962 ElementKind.VARIABLE_LIST, enclosingElement); | 1980 ElementKind.VARIABLE_LIST, enclosingElement); |
1963 element = new FieldParameterElement(node.selector.asIdentifier().source, | 1981 element = new FieldParameterElement(name, |
1964 fieldElement, variables, enclosingElement, node); | 1982 fieldElement, variables, enclosingElement, node); |
1965 } | 1983 } |
1966 return element; | 1984 return element; |
1967 } | 1985 } |
1968 | 1986 |
1969 Element visitSendSet(SendSet node) { | 1987 Element visitSendSet(SendSet node) { |
1970 Element element; | 1988 Element element; |
1971 if (node.receiver != null) { | 1989 if (node.receiver != null) { |
1972 element = visitSend(node); | 1990 element = visitSend(node); |
1973 } else if (node.selector.asIdentifier() != null) { | 1991 } else if (node.selector.asIdentifier() != null) { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2187 | 2205 |
2188 TopScope(LibraryElement library) : super(null, library); | 2206 TopScope(LibraryElement library) : super(null, library); |
2189 Element lookup(SourceString name) { | 2207 Element lookup(SourceString name) { |
2190 return library.find(name); | 2208 return library.find(name); |
2191 } | 2209 } |
2192 | 2210 |
2193 Element add(Element newElement) { | 2211 Element add(Element newElement) { |
2194 throw "Cannot add an element in the top scope"; | 2212 throw "Cannot add an element in the top scope"; |
2195 } | 2213 } |
2196 } | 2214 } |
OLD | NEW |