| 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(TypeAnnotation annotation); | 8 DartType getType(TypeAnnotation annotation); |
| 9 bool isParameterChecked(Element element); | 9 bool isParameterChecked(Element element); |
| 10 } | 10 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 204 } |
| 205 | 205 |
| 206 TreeElements resolveParameter(Element element) { | 206 TreeElements resolveParameter(Element element) { |
| 207 Node tree = element.parseNode(compiler); | 207 Node tree = element.parseNode(compiler); |
| 208 ResolverVisitor visitor = | 208 ResolverVisitor visitor = |
| 209 new ResolverVisitor(compiler, element.enclosingElement); | 209 new ResolverVisitor(compiler, element.enclosingElement); |
| 210 initializerDo(tree, visitor.visit); | 210 initializerDo(tree, visitor.visit); |
| 211 return visitor.mapping; | 211 return visitor.mapping; |
| 212 } | 212 } |
| 213 | 213 |
| 214 DartType resolveTypeAnnotation(Element element, TypeAnnotation annotation) { | 214 DartType resolveTypeAnnotation(Element element, |
| 215 TypeAnnotation annotation, |
| 216 {bool isVoidAllowed: false}) { |
| 215 if (annotation === null) return compiler.types.dynamicType; | 217 if (annotation === null) return compiler.types.dynamicType; |
| 216 ResolverVisitor visitor = new ResolverVisitor(compiler, element); | 218 ResolverVisitor visitor = new ResolverVisitor(compiler, element); |
| 217 DartType result = visitor.resolveTypeAnnotation(annotation); | 219 DartType result = visitor.resolveTypeAnnotation(annotation); |
| 218 if (result === null) { | 220 if (result === null) { |
| 219 // TODO(karklose): warning. | 221 // TODO(karklose): warning. |
| 220 return compiler.types.dynamicType; | 222 return compiler.types.dynamicType; |
| 221 } | 223 } |
| 224 if (result == compiler.types.voidType && !isVoidAllowed) { |
| 225 error(annotation, MessageKind.VOID_NOT_ALLOWED); |
| 226 } |
| 222 return result; | 227 return result; |
| 223 } | 228 } |
| 224 | 229 |
| 225 /** | 230 /** |
| 226 * Load and resolve the supertypes of [cls]. | 231 * Load and resolve the supertypes of [cls]. |
| 227 * | 232 * |
| 228 * Warning: do not call this method directly. It should only be | 233 * Warning: do not call this method directly. It should only be |
| 229 * called by [resolveClass] and [ClassSupertypeResolver]. | 234 * called by [resolveClass] and [ClassSupertypeResolver]. |
| 230 */ | 235 */ |
| 231 void loadSupertypes(ClassElement cls, Node from) { | 236 void loadSupertypes(ClassElement cls, Node from) { |
| (...skipping 2133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2365 } | 2370 } |
| 2366 currentDefinitions = node; | 2371 currentDefinitions = node; |
| 2367 Element element = definition.accept(this); | 2372 Element element = definition.accept(this); |
| 2368 currentDefinitions = null; | 2373 currentDefinitions = null; |
| 2369 return element; | 2374 return element; |
| 2370 } | 2375 } |
| 2371 | 2376 |
| 2372 Element visitIdentifier(Identifier node) { | 2377 Element visitIdentifier(Identifier node) { |
| 2373 Element variables = new VariableListElement.node(currentDefinitions, | 2378 Element variables = new VariableListElement.node(currentDefinitions, |
| 2374 ElementKind.VARIABLE_LIST, enclosingElement); | 2379 ElementKind.VARIABLE_LIST, enclosingElement); |
| 2380 // Ensure a parameter is not typed 'void'. |
| 2381 variables.computeType(compiler); |
| 2375 return new VariableElement(node.source, variables, | 2382 return new VariableElement(node.source, variables, |
| 2376 ElementKind.PARAMETER, enclosingElement, node: node); | 2383 ElementKind.PARAMETER, enclosingElement, node: node); |
| 2377 } | 2384 } |
| 2378 | 2385 |
| 2379 SourceString getParameterName(Send node) { | 2386 SourceString getParameterName(Send node) { |
| 2380 var identifier = node.selector.asIdentifier(); | 2387 var identifier = node.selector.asIdentifier(); |
| 2381 if (identifier !== null) { | 2388 if (identifier !== null) { |
| 2382 // Normal parameter: [:Type name:]. | 2389 // Normal parameter: [:Type name:]. |
| 2383 return identifier.source; | 2390 return identifier.source; |
| 2384 } else { | 2391 } else { |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2484 MessageKind.EXTRA_FORMALS.error([]), | 2491 MessageKind.EXTRA_FORMALS.error([]), |
| 2485 api.Diagnostic.WARNING); | 2492 api.Diagnostic.WARNING); |
| 2486 } | 2493 } |
| 2487 } | 2494 } |
| 2488 } | 2495 } |
| 2489 LinkBuilder<Element> parametersBuilder = | 2496 LinkBuilder<Element> parametersBuilder = |
| 2490 visitor.analyzeNodes(formalParameters.nodes); | 2497 visitor.analyzeNodes(formalParameters.nodes); |
| 2491 requiredParameterCount = parametersBuilder.length; | 2498 requiredParameterCount = parametersBuilder.length; |
| 2492 parameters = parametersBuilder.toLink(); | 2499 parameters = parametersBuilder.toLink(); |
| 2493 } | 2500 } |
| 2494 DartType returnType = compiler.resolveTypeAnnotation(element, returnNode); | 2501 DartType returnType = compiler.resolveTypeAnnotation( |
| 2502 element, returnNode, isVoidAllowed: true); |
| 2495 return new FunctionSignature(parameters, | 2503 return new FunctionSignature(parameters, |
| 2496 visitor.optionalParameters, | 2504 visitor.optionalParameters, |
| 2497 requiredParameterCount, | 2505 requiredParameterCount, |
| 2498 visitor.optionalParameterCount, | 2506 visitor.optionalParameterCount, |
| 2499 visitor.optionalParametersAreNamed, | 2507 visitor.optionalParametersAreNamed, |
| 2500 returnType); | 2508 returnType); |
| 2501 } | 2509 } |
| 2502 | 2510 |
| 2503 // TODO(ahe): This is temporary. | 2511 // TODO(ahe): This is temporary. |
| 2504 void resolveExpression(Node node) { | 2512 void resolveExpression(Node node) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2763 | 2771 |
| 2764 Element localLookup(SourceString name) => library.find(name); | 2772 Element localLookup(SourceString name) => library.find(name); |
| 2765 Element lookup(SourceString name) => localLookup(name); | 2773 Element lookup(SourceString name) => localLookup(name); |
| 2766 Element lexicalLookup(SourceString name) => localLookup(name); | 2774 Element lexicalLookup(SourceString name) => localLookup(name); |
| 2767 | 2775 |
| 2768 Element add(Element newElement) { | 2776 Element add(Element newElement) { |
| 2769 throw "Cannot add an element in the top scope"; | 2777 throw "Cannot add an element in the top scope"; |
| 2770 } | 2778 } |
| 2771 String toString() => '$element'; | 2779 String toString() => '$element'; |
| 2772 } | 2780 } |
| OLD | NEW |