| 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 part of dart2js; | 5 part of dart2js; |
| 6 | 6 |
| 7 class TypeCheckerTask extends CompilerTask { | 7 class TypeCheckerTask extends CompilerTask { |
| 8 TypeCheckerTask(Compiler compiler) : super(compiler); | 8 TypeCheckerTask(Compiler compiler) : super(compiler); |
| 9 String get name => "Type checker"; | 9 String get name => "Type checker"; |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 */ | 119 */ |
| 120 class ResolvedAccess extends ElementAccess { | 120 class ResolvedAccess extends ElementAccess { |
| 121 final Element element; | 121 final Element element; |
| 122 | 122 |
| 123 ResolvedAccess(Element this.element) { | 123 ResolvedAccess(Element this.element) { |
| 124 assert(element != null); | 124 assert(element != null); |
| 125 } | 125 } |
| 126 | 126 |
| 127 DartType computeType(Compiler compiler) { | 127 DartType computeType(Compiler compiler) { |
| 128 if (element.isGetter) { | 128 if (element.isGetter) { |
| 129 FunctionType functionType = element.computeType(compiler); | 129 GetterElement getter = element; |
| 130 FunctionType functionType = getter.computeType(compiler); |
| 130 return functionType.returnType; | 131 return functionType.returnType; |
| 131 } else if (element.isSetter) { | 132 } else if (element.isSetter) { |
| 132 FunctionType functionType = element.computeType(compiler); | 133 SetterElement setter = element; |
| 134 FunctionType functionType = setter.computeType(compiler); |
| 133 if (functionType.parameterTypes.length != 1) { | 135 if (functionType.parameterTypes.length != 1) { |
| 134 // TODO(johnniwinther,karlklose): this happens for malformed static | 136 // TODO(johnniwinther,karlklose): this happens for malformed static |
| 135 // setters. Treat them the same as instance members. | 137 // setters. Treat them the same as instance members. |
| 136 return const DynamicType(); | 138 return const DynamicType(); |
| 137 } | 139 } |
| 138 return functionType.parameterTypes.first; | 140 return functionType.parameterTypes.first; |
| 141 } else if (element.isTypedef || element.isClass) { |
| 142 TypeDeclarationElement typeDeclaration = element; |
| 143 typeDeclaration.computeType(compiler); |
| 144 return typeDeclaration.thisType; |
| 139 } else { | 145 } else { |
| 140 return element.computeType(compiler); | 146 TypedElement typedElement = element; |
| 147 typedElement.computeType(compiler); |
| 148 return typedElement.type; |
| 141 } | 149 } |
| 142 } | 150 } |
| 143 | 151 |
| 144 String toString() => 'ResolvedAccess($element)'; | 152 String toString() => 'ResolvedAccess($element)'; |
| 145 } | 153 } |
| 146 | 154 |
| 147 /// An access to a promoted variable. | 155 /// An access to a promoted variable. |
| 148 class PromotedAccess extends ElementAccess { | 156 class PromotedAccess extends ElementAccess { |
| 149 final VariableElement element; | 157 final VariableElement element; |
| 150 final DartType type; | 158 final DartType type; |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 currentAsyncMarker = previousAsyncMarker; | 638 currentAsyncMarker = previousAsyncMarker; |
| 631 return type; | 639 return type; |
| 632 } | 640 } |
| 633 | 641 |
| 634 DartType visitIdentifier(Identifier node) { | 642 DartType visitIdentifier(Identifier node) { |
| 635 if (node.isThis()) { | 643 if (node.isThis()) { |
| 636 return thisType; | 644 return thisType; |
| 637 } else if (node.isSuper()) { | 645 } else if (node.isSuper()) { |
| 638 return superType; | 646 return superType; |
| 639 } else { | 647 } else { |
| 640 Element element = elements[node]; | 648 TypedElement element = elements[node]; |
| 641 assert(invariant(node, element != null, | 649 assert(invariant(node, element != null, |
| 642 message: 'Missing element for identifier')); | 650 message: 'Missing element for identifier')); |
| 643 assert(invariant(node, element.isVariable || | 651 assert(invariant(node, element.isVariable || |
| 644 element.isParameter || | 652 element.isParameter || |
| 645 element.isField, | 653 element.isField, |
| 646 message: 'Unexpected context element ${element}')); | 654 message: 'Unexpected context element ${element}')); |
| 647 return element.computeType(compiler); | 655 return element.computeType(compiler); |
| 648 } | 656 } |
| 649 } | 657 } |
| 650 | 658 |
| (...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 } | 1525 } |
| 1518 | 1526 |
| 1519 DartType visitLiteralNull(LiteralNull node) { | 1527 DartType visitLiteralNull(LiteralNull node) { |
| 1520 return const DynamicType(); | 1528 return const DynamicType(); |
| 1521 } | 1529 } |
| 1522 | 1530 |
| 1523 DartType visitLiteralSymbol(LiteralSymbol node) { | 1531 DartType visitLiteralSymbol(LiteralSymbol node) { |
| 1524 return compiler.symbolClass.rawType; | 1532 return compiler.symbolClass.rawType; |
| 1525 } | 1533 } |
| 1526 | 1534 |
| 1527 DartType computeConstructorType(Element constructor, DartType type) { | 1535 DartType computeConstructorType(ConstructorElement constructor, |
| 1536 DartType type) { |
| 1528 if (Elements.isUnresolved(constructor)) return const DynamicType(); | 1537 if (Elements.isUnresolved(constructor)) return const DynamicType(); |
| 1529 DartType constructorType = constructor.computeType(compiler); | 1538 DartType constructorType = constructor.computeType(compiler); |
| 1530 if (identical(type.kind, TypeKind.INTERFACE)) { | 1539 if (identical(type.kind, TypeKind.INTERFACE)) { |
| 1531 if (constructor.isSynthesized) { | 1540 if (constructor.isSynthesized) { |
| 1532 // TODO(johnniwinther): Remove this when synthesized constructors handle | 1541 // TODO(johnniwinther): Remove this when synthesized constructors handle |
| 1533 // type variables correctly. | 1542 // type variables correctly. |
| 1534 InterfaceType interfaceType = type; | 1543 InterfaceType interfaceType = type; |
| 1535 ClassElement receiverElement = interfaceType.element; | 1544 ClassElement receiverElement = interfaceType.element; |
| 1536 while (receiverElement.isMixinApplication) { | 1545 while (receiverElement.isMixinApplication) { |
| 1537 receiverElement = receiverElement.supertype.element; | 1546 receiverElement = receiverElement.supertype.element; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1863 | 1872 |
| 1864 visitTypedef(Typedef node) { | 1873 visitTypedef(Typedef node) { |
| 1865 // Do not typecheck [Typedef] nodes. | 1874 // Do not typecheck [Typedef] nodes. |
| 1866 } | 1875 } |
| 1867 | 1876 |
| 1868 visitNode(Node node) { | 1877 visitNode(Node node) { |
| 1869 compiler.internalError(node, | 1878 compiler.internalError(node, |
| 1870 'Unexpected node ${node.getObjectDescription()} in the type checker.'); | 1879 'Unexpected node ${node.getObjectDescription()} in the type checker.'); |
| 1871 } | 1880 } |
| 1872 } | 1881 } |
| OLD | NEW |