| 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 10833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10844 LocalVariableElement loopElement = loopVariable.element; | 10844 LocalVariableElement loopElement = loopVariable.element; |
| 10845 if (loopElement != null) { | 10845 if (loopElement != null) { |
| 10846 DartType propagatedType = null; | 10846 DartType propagatedType = null; |
| 10847 if (node.awaitKeyword == null) { | 10847 if (node.awaitKeyword == null) { |
| 10848 propagatedType = _getIteratorElementType(iterable); | 10848 propagatedType = _getIteratorElementType(iterable); |
| 10849 } else { | 10849 } else { |
| 10850 propagatedType = _getStreamElementType(iterable); | 10850 propagatedType = _getStreamElementType(iterable); |
| 10851 } | 10851 } |
| 10852 if (propagatedType != null) { | 10852 if (propagatedType != null) { |
| 10853 overrideVariable(loopElement, propagatedType, true); | 10853 overrideVariable(loopElement, propagatedType, true); |
| 10854 _recordPropagatedType(loopVariable.identifier, propagatedType); | 10854 recordPropagatedTypeIfBetter( |
| 10855 loopVariable.identifier, propagatedType); |
| 10855 } | 10856 } |
| 10856 } | 10857 } |
| 10857 } else if (identifier != null && iterable != null) { | 10858 } else if (identifier != null && iterable != null) { |
| 10858 Element identifierElement = identifier.staticElement; | 10859 Element identifierElement = identifier.staticElement; |
| 10859 if (identifierElement is VariableElement) { | 10860 if (identifierElement is VariableElement) { |
| 10860 DartType iteratorElementType = _getIteratorElementType(iterable); | 10861 DartType iteratorElementType = _getIteratorElementType(iterable); |
| 10861 overrideVariable(identifierElement, iteratorElementType, true); | 10862 overrideVariable(identifierElement, iteratorElementType, true); |
| 10862 _recordPropagatedType(identifier, iteratorElementType); | 10863 recordPropagatedTypeIfBetter(identifier, iteratorElementType); |
| 10863 } | 10864 } |
| 10864 } | 10865 } |
| 10865 visitStatementInScope(body); | 10866 visitStatementInScope(body); |
| 10866 } finally { | 10867 } finally { |
| 10867 _overrideManager.exitScope(); | 10868 _overrideManager.exitScope(); |
| 10868 } | 10869 } |
| 10869 } | 10870 } |
| 10870 node.accept(elementResolver); | 10871 node.accept(elementResolver); |
| 10871 node.accept(typeAnalyzer); | 10872 node.accept(typeAnalyzer); |
| 10872 } | 10873 } |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11592 } | 11593 } |
| 11593 } else if (condition is PrefixExpression) { | 11594 } else if (condition is PrefixExpression) { |
| 11594 PrefixExpression prefix = condition; | 11595 PrefixExpression prefix = condition; |
| 11595 if (prefix.operator.type == sc.TokenType.BANG) { | 11596 if (prefix.operator.type == sc.TokenType.BANG) { |
| 11596 _propagateFalseState(prefix.operand); | 11597 _propagateFalseState(prefix.operand); |
| 11597 } | 11598 } |
| 11598 } else if (condition is ParenthesizedExpression) { | 11599 } else if (condition is ParenthesizedExpression) { |
| 11599 _propagateTrueState(condition.expression); | 11600 _propagateTrueState(condition.expression); |
| 11600 } | 11601 } |
| 11601 } | 11602 } |
| 11602 | |
| 11603 /** | |
| 11604 * Record that the propagated type of the given node is the given type. | |
| 11605 * | |
| 11606 * @param expression the node whose type is to be recorded | |
| 11607 * @param type the propagated type of the node | |
| 11608 */ | |
| 11609 void _recordPropagatedType(Expression expression, DartType type) { | |
| 11610 if (type != null && !type.isDynamic) { | |
| 11611 expression.propagatedType = type; | |
| 11612 } | |
| 11613 } | |
| 11614 } | 11603 } |
| 11615 | 11604 |
| 11616 /** | 11605 /** |
| 11617 * The abstract class `Scope` defines the behavior common to name scopes used by
the resolver | 11606 * The abstract class `Scope` defines the behavior common to name scopes used by
the resolver |
| 11618 * to determine which names are visible at any given point in the code. | 11607 * to determine which names are visible at any given point in the code. |
| 11619 */ | 11608 */ |
| 11620 abstract class Scope { | 11609 abstract class Scope { |
| 11621 /** | 11610 /** |
| 11622 * The prefix used to mark an identifier as being private to its library. | 11611 * The prefix used to mark an identifier as being private to its library. |
| 11623 */ | 11612 */ |
| (...skipping 3776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15400 nonFields.add(node); | 15389 nonFields.add(node); |
| 15401 return null; | 15390 return null; |
| 15402 } | 15391 } |
| 15403 | 15392 |
| 15404 @override | 15393 @override |
| 15405 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); | 15394 Object visitNode(AstNode node) => node.accept(TypeResolverVisitor_this); |
| 15406 | 15395 |
| 15407 @override | 15396 @override |
| 15408 Object visitWithClause(WithClause node) => null; | 15397 Object visitWithClause(WithClause node) => null; |
| 15409 } | 15398 } |
| OLD | NEW |