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 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) { | |
| 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 1774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1940 // The only valid [Send] can be in constructors and must be of the form | 1944 // The only valid [Send] can be in constructors and must be of the form |
| 1941 // [:this.x:] (where [:x:] represents an instance field). | 1945 // [:this.x:] (where [:x:] represents an instance field). |
| 1942 FieldParameterElement visitSend(Send node) { | 1946 FieldParameterElement visitSend(Send node) { |
| 1943 FieldParameterElement element; | 1947 FieldParameterElement element; |
| 1944 if (node.receiver.asIdentifier() === null || | 1948 if (node.receiver.asIdentifier() === null || |
| 1945 !node.receiver.asIdentifier().isThis()) { | 1949 !node.receiver.asIdentifier().isThis()) { |
| 1946 error(node, MessageKind.INVALID_PARAMETER, []); | 1950 error(node, MessageKind.INVALID_PARAMETER, []); |
| 1947 } else if (enclosingElement.kind !== ElementKind.GENERATIVE_CONSTRUCTOR) { | 1951 } else if (enclosingElement.kind !== ElementKind.GENERATIVE_CONSTRUCTOR) { |
| 1948 error(node, MessageKind.FIELD_PARAMETER_NOT_ALLOWED, []); | 1952 error(node, MessageKind.FIELD_PARAMETER_NOT_ALLOWED, []); |
| 1949 } else { | 1953 } else { |
| 1950 if (node.selector.asIdentifier() == null) { | 1954 SourceString name; |
|
kasperl
2012/07/06 12:40:41
Would it make sense to factor this code (the compu
Johnni Winther
2012/07/09 14:57:18
For clarity only. I don't think the computation is
| |
| 1951 cancel(node, | 1955 var identifier = node.selector.asIdentifier(); |
| 1952 'internal error: unimplemented receiver on parameter send'); | 1956 if (identifier !== null) { |
| 1957 // Normal parameter: [:Type name:]. | |
| 1958 name = identifier.source; | |
| 1959 } else { | |
| 1960 // Function type parameter: [:void name(Type arg):]. | |
| 1961 var functionExpression = node.selector.asFunctionExpression(); | |
| 1962 if (functionExpression !== null && | |
| 1963 functionExpression.name.asIdentifier() !== null) { | |
| 1964 name = functionExpression.name.asIdentifier().source; | |
| 1965 } else { | |
| 1966 cancel(node, | |
| 1967 'internal error: unimplemented receiver on parameter send'); | |
| 1968 } | |
| 1953 } | 1969 } |
| 1954 SourceString name = node.selector.asIdentifier().source; | |
| 1955 Element fieldElement = currentClass.lookupLocalMember(name); | 1970 Element fieldElement = currentClass.lookupLocalMember(name); |
| 1956 if (fieldElement === null || fieldElement.kind !== ElementKind.FIELD) { | 1971 if (fieldElement === null || fieldElement.kind !== ElementKind.FIELD) { |
| 1957 error(node, MessageKind.NOT_A_FIELD, [name]); | 1972 error(node, MessageKind.NOT_A_FIELD, [name]); |
| 1958 } else if (!fieldElement.isInstanceMember()) { | 1973 } else if (!fieldElement.isInstanceMember()) { |
| 1959 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]); | 1974 error(node, MessageKind.NOT_INSTANCE_FIELD, [name]); |
| 1960 } | 1975 } |
| 1961 Element variables = new VariableListElement.node(currentDefinitions, | 1976 Element variables = new VariableListElement.node(currentDefinitions, |
| 1962 ElementKind.VARIABLE_LIST, enclosingElement); | 1977 ElementKind.VARIABLE_LIST, enclosingElement); |
| 1963 element = new FieldParameterElement(node.selector.asIdentifier().source, | 1978 element = new FieldParameterElement(name, |
| 1964 fieldElement, variables, enclosingElement, node); | 1979 fieldElement, variables, enclosingElement, node); |
| 1965 } | 1980 } |
| 1966 return element; | 1981 return element; |
| 1967 } | 1982 } |
| 1968 | 1983 |
| 1969 Element visitSendSet(SendSet node) { | 1984 Element visitSendSet(SendSet node) { |
| 1970 Element element; | 1985 Element element; |
| 1971 if (node.receiver != null) { | 1986 if (node.receiver != null) { |
| 1972 element = visitSend(node); | 1987 element = visitSend(node); |
| 1973 } else if (node.selector.asIdentifier() != null) { | 1988 } else if (node.selector.asIdentifier() != null) { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2187 | 2202 |
| 2188 TopScope(LibraryElement library) : super(null, library); | 2203 TopScope(LibraryElement library) : super(null, library); |
| 2189 Element lookup(SourceString name) { | 2204 Element lookup(SourceString name) { |
| 2190 return library.find(name); | 2205 return library.find(name); |
| 2191 } | 2206 } |
| 2192 | 2207 |
| 2193 Element add(Element newElement) { | 2208 Element add(Element newElement) { |
| 2194 throw "Cannot add an element in the top scope"; | 2209 throw "Cannot add an element in the top scope"; |
| 2195 } | 2210 } |
| 2196 } | 2211 } |
| OLD | NEW |