| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library engine.resolver; | 5 library engine.resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'constant.dart'; | 10 import 'constant.dart'; |
| (...skipping 10688 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10699 // of the statement. | 10699 // of the statement. |
| 10700 // | 10700 // |
| 10701 node.accept(elementResolver); | 10701 node.accept(elementResolver); |
| 10702 node.accept(typeAnalyzer); | 10702 node.accept(typeAnalyzer); |
| 10703 return null; | 10703 return null; |
| 10704 } | 10704 } |
| 10705 | 10705 |
| 10706 @override | 10706 @override |
| 10707 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | 10707 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 10708 super.visitDefaultFormalParameter(node); | 10708 super.visitDefaultFormalParameter(node); |
| 10709 ParameterElement element = node.element; |
| 10710 if (element.initializer != null && node.defaultValue != null) { |
| 10711 (element.initializer as FunctionElementImpl).returnType = |
| 10712 node.defaultValue.staticType; |
| 10713 } |
| 10709 FormalParameterList parent = node.parent; | 10714 FormalParameterList parent = node.parent; |
| 10710 AstNode grandparent = parent.parent; | 10715 AstNode grandparent = parent.parent; |
| 10711 if (grandparent is ConstructorDeclaration && | 10716 if (grandparent is ConstructorDeclaration && |
| 10712 grandparent.constKeyword != null) { | 10717 grandparent.constKeyword != null) { |
| 10713 // For const constructors, we need to clone the ASTs for default formal | 10718 // For const constructors, we need to clone the ASTs for default formal |
| 10714 // parameters, so that we can use them during constant evaluation. | 10719 // parameters, so that we can use them during constant evaluation. |
| 10715 ParameterElement element = node.element; | 10720 ParameterElement element = node.element; |
| 10716 (element as ConstVariableElement).constantInitializer = | 10721 (element as ConstVariableElement).constantInitializer = |
| 10717 new ConstantAstCloner().cloneNode(node.defaultValue); | 10722 new ConstantAstCloner().cloneNode(node.defaultValue); |
| 10718 } | 10723 } |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11124 return null; | 11129 return null; |
| 11125 } | 11130 } |
| 11126 | 11131 |
| 11127 @override | 11132 @override |
| 11128 Object visitTypeName(TypeName node) => null; | 11133 Object visitTypeName(TypeName node) => null; |
| 11129 | 11134 |
| 11130 @override | 11135 @override |
| 11131 Object visitVariableDeclaration(VariableDeclaration node) { | 11136 Object visitVariableDeclaration(VariableDeclaration node) { |
| 11132 super.visitVariableDeclaration(node); | 11137 super.visitVariableDeclaration(node); |
| 11133 VariableElement element = node.element; | 11138 VariableElement element = node.element; |
| 11139 if (element.initializer != null && node.initializer != null) { |
| 11140 (element.initializer as FunctionElementImpl).returnType = |
| 11141 node.initializer.staticType; |
| 11142 } |
| 11134 // Note: in addition to cloning the initializers for const variables, we | 11143 // Note: in addition to cloning the initializers for const variables, we |
| 11135 // have to clone the initializers for non-static final fields (because if | 11144 // have to clone the initializers for non-static final fields (because if |
| 11136 // they occur in a class with a const constructor, they will be needed to | 11145 // they occur in a class with a const constructor, they will be needed to |
| 11137 // evaluate the const constructor). | 11146 // evaluate the const constructor). |
| 11138 if ((element.isConst || | 11147 if ((element.isConst || |
| 11139 (element is FieldElement && | 11148 (element is FieldElement && |
| 11140 element.isFinal && | 11149 element.isFinal && |
| 11141 !element.isStatic)) && | 11150 !element.isStatic)) && |
| 11142 node.initializer != null) { | 11151 node.initializer != null) { |
| 11143 (element as ConstVariableElement).constantInitializer = | 11152 (element as ConstVariableElement).constantInitializer = |
| (...skipping 3522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14666 abstract class TypeSystem { | 14675 abstract class TypeSystem { |
| 14667 /** | 14676 /** |
| 14668 * Return the [TypeProvider] associated with this [TypeSystem]. | 14677 * Return the [TypeProvider] associated with this [TypeSystem]. |
| 14669 */ | 14678 */ |
| 14670 TypeProvider get typeProvider; | 14679 TypeProvider get typeProvider; |
| 14671 | 14680 |
| 14672 /** | 14681 /** |
| 14673 * Compute the least upper bound of two types. | 14682 * Compute the least upper bound of two types. |
| 14674 */ | 14683 */ |
| 14675 DartType getLeastUpperBound(DartType type1, DartType type2); | 14684 DartType getLeastUpperBound(DartType type1, DartType type2); |
| 14685 |
| 14686 /** |
| 14687 * Return `true` if the [leftType] is a subtype of the [rightType] (that is, |
| 14688 * if leftType <: rightType). |
| 14689 */ |
| 14690 bool isSubtypeOf(DartType leftType, DartType rightType); |
| 14676 } | 14691 } |
| 14677 | 14692 |
| 14678 /** | 14693 /** |
| 14679 * Implementation of [TypeSystem] using the rules in the Dart specification. | 14694 * Implementation of [TypeSystem] using the rules in the Dart specification. |
| 14680 */ | 14695 */ |
| 14681 class TypeSystemImpl implements TypeSystem { | 14696 class TypeSystemImpl implements TypeSystem { |
| 14682 @override | 14697 @override |
| 14683 final TypeProvider typeProvider; | 14698 final TypeProvider typeProvider; |
| 14684 | 14699 |
| 14685 TypeSystemImpl(this.typeProvider); | 14700 TypeSystemImpl(this.typeProvider); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14755 if (result == null) { | 14770 if (result == null) { |
| 14756 return typeProvider.functionType; | 14771 return typeProvider.functionType; |
| 14757 } | 14772 } |
| 14758 return result; | 14773 return result; |
| 14759 } else { | 14774 } else { |
| 14760 // Should never happen. As a defensive measure, return the dynamic type. | 14775 // Should never happen. As a defensive measure, return the dynamic type. |
| 14761 assert(false); | 14776 assert(false); |
| 14762 return typeProvider.dynamicType; | 14777 return typeProvider.dynamicType; |
| 14763 } | 14778 } |
| 14764 } | 14779 } |
| 14780 |
| 14781 @override |
| 14782 bool isSubtypeOf(DartType leftType, DartType rightType) { |
| 14783 return leftType.isSubtypeOf(rightType); |
| 14784 } |
| 14765 } | 14785 } |
| 14766 | 14786 |
| 14767 /** | 14787 /** |
| 14768 * Instances of the class [UnusedLocalElementsVerifier] traverse an element | 14788 * Instances of the class [UnusedLocalElementsVerifier] traverse an element |
| 14769 * structure looking for cases of [HintCode.UNUSED_ELEMENT], | 14789 * structure looking for cases of [HintCode.UNUSED_ELEMENT], |
| 14770 * [HintCode.UNUSED_FIELD], [HintCode.UNUSED_LOCAL_VARIABLE], etc. | 14790 * [HintCode.UNUSED_FIELD], [HintCode.UNUSED_LOCAL_VARIABLE], etc. |
| 14771 */ | 14791 */ |
| 14772 class UnusedLocalElementsVerifier extends RecursiveElementVisitor { | 14792 class UnusedLocalElementsVerifier extends RecursiveElementVisitor { |
| 14773 /** | 14793 /** |
| 14774 * The error listener to which errors will be reported. | 14794 * The error listener to which errors will be reported. |
| (...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15323 nonFields.add(node); | 15343 nonFields.add(node); |
| 15324 return null; | 15344 return null; |
| 15325 } | 15345 } |
| 15326 | 15346 |
| 15327 @override | 15347 @override |
| 15328 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15348 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15329 | 15349 |
| 15330 @override | 15350 @override |
| 15331 Object visitWithClause(WithClause node) => null; | 15351 Object visitWithClause(WithClause node) => null; |
| 15332 } | 15352 } |
| OLD | NEW |