| 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 class TypeCheckerTask extends CompilerTask { | 5 class TypeCheckerTask extends CompilerTask { |
| 6 TypeCheckerTask(Compiler compiler) : super(compiler); | 6 TypeCheckerTask(Compiler compiler) : super(compiler); |
| 7 String get name => "Type checker"; | 7 String get name => "Type checker"; |
| 8 | 8 |
| 9 static const bool LOG_FAILURES = false; | 9 static const bool LOG_FAILURES = false; |
| 10 | 10 |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 DartType visitFunctionDeclaration(FunctionDeclaration node) { | 388 DartType visitFunctionDeclaration(FunctionDeclaration node) { |
| 389 analyze(node.function); | 389 analyze(node.function); |
| 390 return StatementType.NOT_RETURNING; | 390 return StatementType.NOT_RETURNING; |
| 391 } | 391 } |
| 392 | 392 |
| 393 DartType visitFunctionExpression(FunctionExpression node) { | 393 DartType visitFunctionExpression(FunctionExpression node) { |
| 394 DartType type; | 394 DartType type; |
| 395 DartType returnType; | 395 DartType returnType; |
| 396 DartType previousType; | 396 DartType previousType; |
| 397 final FunctionElement element = elements[node]; | 397 final FunctionElement element = elements[node]; |
| 398 if (Element.isInvalid(element)) return types.dynamicType; | 398 if (Element.isUnresolved(element)) return types.dynamicType; |
| 399 if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR || | 399 if (element.kind === ElementKind.GENERATIVE_CONSTRUCTOR || |
| 400 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { | 400 element.kind === ElementKind.GENERATIVE_CONSTRUCTOR_BODY) { |
| 401 type = types.dynamicType; | 401 type = types.dynamicType; |
| 402 returnType = types.voidType; | 402 returnType = types.voidType; |
| 403 } else { | 403 } else { |
| 404 FunctionType functionType = computeType(element); | 404 FunctionType functionType = computeType(element); |
| 405 returnType = functionType.returnType; | 405 returnType = functionType.returnType; |
| 406 type = functionType; | 406 type = functionType; |
| 407 } | 407 } |
| 408 DartType previous = expectedReturnType; | 408 DartType previous = expectedReturnType; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 if (receiverKind !== ElementKind.CLASS) { | 566 if (receiverKind !== ElementKind.CLASS) { |
| 567 fail(node.receiver, 'unexpected receiver kind: ${receiverKind}'); | 567 fail(node.receiver, 'unexpected receiver kind: ${receiverKind}'); |
| 568 } | 568 } |
| 569 ClassElement classElement = receiverType.element; | 569 ClassElement classElement = receiverType.element; |
| 570 // TODO(karlklose): substitute type arguments. | 570 // TODO(karlklose): substitute type arguments. |
| 571 DartType memberType = | 571 DartType memberType = |
| 572 lookupMethodType(selector, classElement, selector.source); | 572 lookupMethodType(selector, classElement, selector.source); |
| 573 if (memberType.element === compiler.dynamicClass) return null; | 573 if (memberType.element === compiler.dynamicClass) return null; |
| 574 return memberType; | 574 return memberType; |
| 575 } else { | 575 } else { |
| 576 if (element === null) { | 576 if (Element.isUnresolved(element)) { |
| 577 fail(node, 'unresolved ${node.selector}'); | 577 fail(node, 'unresolved ${node.selector}'); |
| 578 } else if (element.kind === ElementKind.FUNCTION) { | 578 } else if (element.kind === ElementKind.FUNCTION) { |
| 579 return computeType(element); | 579 return computeType(element); |
| 580 } else if (element.kind === ElementKind.FOREIGN) { | 580 } else if (element.kind === ElementKind.FOREIGN) { |
| 581 return null; | 581 return null; |
| 582 } else if (element.kind === ElementKind.VARIABLE | 582 } else if (element.kind === ElementKind.VARIABLE |
| 583 || element.kind === ElementKind.FIELD) { | 583 || element.kind === ElementKind.FIELD) { |
| 584 // TODO(karlklose): handle object invocations. | 584 // TODO(karlklose): handle object invocations. |
| 585 return null; | 585 return null; |
| 586 } else { | 586 } else { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 } | 703 } |
| 704 return StatementType.RETURNING; | 704 return StatementType.RETURNING; |
| 705 } | 705 } |
| 706 | 706 |
| 707 DartType visitThrow(Throw node) { | 707 DartType visitThrow(Throw node) { |
| 708 if (node.expression !== null) analyze(node.expression); | 708 if (node.expression !== null) analyze(node.expression); |
| 709 return StatementType.RETURNING; | 709 return StatementType.RETURNING; |
| 710 } | 710 } |
| 711 | 711 |
| 712 DartType computeType(Element element) { | 712 DartType computeType(Element element) { |
| 713 if (Element.isInvalid(element)) return types.dynamicType; | 713 if (Element.isUnresolved(element)) return types.dynamicType; |
| 714 DartType result = element.computeType(compiler); | 714 DartType result = element.computeType(compiler); |
| 715 return (result !== null) ? result : types.dynamicType; | 715 return (result !== null) ? result : types.dynamicType; |
| 716 } | 716 } |
| 717 | 717 |
| 718 DartType visitTypeAnnotation(TypeAnnotation node) { | 718 DartType visitTypeAnnotation(TypeAnnotation node) { |
| 719 return elements.getType(node); | 719 return elements.getType(node); |
| 720 } | 720 } |
| 721 | 721 |
| 722 visitTypeVariable(TypeVariable node) { | 722 visitTypeVariable(TypeVariable node) { |
| 723 return types.dynamicType; | 723 return types.dynamicType; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 } | 844 } |
| 845 | 845 |
| 846 visitCatchBlock(CatchBlock node) { | 846 visitCatchBlock(CatchBlock node) { |
| 847 return unhandledStatement(); | 847 return unhandledStatement(); |
| 848 } | 848 } |
| 849 | 849 |
| 850 visitTypedef(Typedef node) { | 850 visitTypedef(Typedef node) { |
| 851 return unhandledStatement(); | 851 return unhandledStatement(); |
| 852 } | 852 } |
| 853 } | 853 } |
| OLD | NEW |