| 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:math" as math; | 7 import "dart:math" as math; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'ast.dart'; | 10 import 'ast.dart'; |
| (...skipping 5755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5766 } | 5766 } |
| 5767 for (int i = argumentCount; i < parameterCount; i++) { | 5767 for (int i = argumentCount; i < parameterCount; i++) { |
| 5768 types[i] = dynamic; | 5768 types[i] = dynamic; |
| 5769 } | 5769 } |
| 5770 } | 5770 } |
| 5771 return types; | 5771 return types; |
| 5772 } | 5772 } |
| 5773 } | 5773 } |
| 5774 | 5774 |
| 5775 /** | 5775 /** |
| 5776 * Instances of the class `ImplicitLabelScope` represent the scope statements |
| 5777 * that can be the target of unlabeled break and continue statements. |
| 5778 */ |
| 5779 class ImplicitLabelScope { |
| 5780 /** |
| 5781 * The implicit label scope associated with the top level of a function. |
| 5782 */ |
| 5783 static const ImplicitLabelScope ROOT = const ImplicitLabelScope._(null, null); |
| 5784 |
| 5785 /** |
| 5786 * The implicit label scope enclosing this implicit label scope. |
| 5787 */ |
| 5788 final ImplicitLabelScope outerScope; |
| 5789 |
| 5790 /** |
| 5791 * The statement that acts as a target for break and/or continue statements |
| 5792 * at this scoping level. |
| 5793 */ |
| 5794 final Statement statement; |
| 5795 |
| 5796 /** |
| 5797 * Private constructor. |
| 5798 */ |
| 5799 const ImplicitLabelScope._(this.outerScope, this.statement); |
| 5800 |
| 5801 /** |
| 5802 * Get the statement which should be the target of an unlabeled `break` or |
| 5803 * `continue` statement, or `null` if there is no appropriate target. |
| 5804 */ |
| 5805 Statement getTarget(bool isContinue) { |
| 5806 if (outerScope == null) { |
| 5807 // This scope represents the toplevel of a function body, so it doesn't |
| 5808 // match either break or continue. |
| 5809 return null; |
| 5810 } |
| 5811 if (isContinue && statement is SwitchStatement) { |
| 5812 return outerScope.getTarget(isContinue); |
| 5813 } |
| 5814 return statement; |
| 5815 } |
| 5816 |
| 5817 /** |
| 5818 * Initialize a newly created scope to represent a switch statement or loop |
| 5819 * nested within the current scope. [statement] is the statement associated |
| 5820 * with the newly created scope. |
| 5821 */ |
| 5822 ImplicitLabelScope nest(Statement statement) => |
| 5823 new ImplicitLabelScope._(this, statement); |
| 5824 } |
| 5825 |
| 5826 /** |
| 5776 * Instances of the class `ImportsVerifier` visit all of the referenced librarie
s in the | 5827 * Instances of the class `ImportsVerifier` visit all of the referenced librarie
s in the |
| 5777 * source code verifying that all of the imports are used, otherwise a | 5828 * source code verifying that all of the imports are used, otherwise a |
| 5778 * [HintCode.UNUSED_IMPORT] is generated with | 5829 * [HintCode.UNUSED_IMPORT] is generated with |
| 5779 * [generateUnusedImportHints]. | 5830 * [generateUnusedImportHints]. |
| 5780 * | 5831 * |
| 5781 * While this class does not yet have support for an "Organize Imports" action,
this logic built up | 5832 * While this class does not yet have support for an "Organize Imports" action,
this logic built up |
| 5782 * in this class could be used for such an action in the future. | 5833 * in this class could be used for such an action in the future. |
| 5783 */ | 5834 */ |
| 5784 class ImportsVerifier extends RecursiveAstVisitor<Object> { | 5835 class ImportsVerifier extends RecursiveAstVisitor<Object> { |
| 5785 /** | 5836 /** |
| (...skipping 5233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11019 * The object keeping track of which elements have had their types overridden. | 11070 * The object keeping track of which elements have had their types overridden. |
| 11020 */ | 11071 */ |
| 11021 TypeOverrideManager _overrideManager = new TypeOverrideManager(); | 11072 TypeOverrideManager _overrideManager = new TypeOverrideManager(); |
| 11022 | 11073 |
| 11023 /** | 11074 /** |
| 11024 * The object keeping track of which elements have had their types promoted. | 11075 * The object keeping track of which elements have had their types promoted. |
| 11025 */ | 11076 */ |
| 11026 TypePromotionManager _promoteManager = new TypePromotionManager(); | 11077 TypePromotionManager _promoteManager = new TypePromotionManager(); |
| 11027 | 11078 |
| 11028 /** | 11079 /** |
| 11029 * The AST node representing the innermost enclosing statement that can be | |
| 11030 * the target of an unlabeled "break" statement, or `null` if there is no | |
| 11031 * such statement. | |
| 11032 */ | |
| 11033 Statement _unlabeledBreakTarget; | |
| 11034 | |
| 11035 /** | |
| 11036 * The AST node representing the innermost enclosing statement that can be | |
| 11037 * the target of an unlabeled "continue" statement, or `null` if there is no | |
| 11038 * such statement. | |
| 11039 */ | |
| 11040 Statement _unlabeledContinueTarget; | |
| 11041 | |
| 11042 /** | |
| 11043 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 11080 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 11044 * | 11081 * |
| 11045 * @param library the library containing the compilation unit being resolved | 11082 * @param library the library containing the compilation unit being resolved |
| 11046 * @param source the source representing the compilation unit being visited | 11083 * @param source the source representing the compilation unit being visited |
| 11047 * @param typeProvider the object used to access the types from the core libra
ry | 11084 * @param typeProvider the object used to access the types from the core libra
ry |
| 11048 */ | 11085 */ |
| 11049 ResolverVisitor.con1(Library library, Source source, | 11086 ResolverVisitor.con1(Library library, Source source, |
| 11050 TypeProvider typeProvider) | 11087 TypeProvider typeProvider) |
| 11051 : super.con1(library, source, typeProvider) { | 11088 : super.con1(library, source, typeProvider) { |
| 11052 this._inheritanceManager = library.inheritanceManager; | 11089 this._inheritanceManager = library.inheritanceManager; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11215 ElementKind kind = element.kind; | 11252 ElementKind kind = element.kind; |
| 11216 if (kind == ElementKind.LOCAL_VARIABLE) { | 11253 if (kind == ElementKind.LOCAL_VARIABLE) { |
| 11217 return element as VariableElement; | 11254 return element as VariableElement; |
| 11218 } | 11255 } |
| 11219 if (kind == ElementKind.PARAMETER) { | 11256 if (kind == ElementKind.PARAMETER) { |
| 11220 return element as VariableElement; | 11257 return element as VariableElement; |
| 11221 } | 11258 } |
| 11222 return null; | 11259 return null; |
| 11223 } | 11260 } |
| 11224 | 11261 |
| 11225 AstNode getUnlabeledBreakOrContinueTarget(bool isContinue) { | |
| 11226 if (isContinue) { | |
| 11227 return _unlabeledContinueTarget; | |
| 11228 } else { | |
| 11229 return _unlabeledBreakTarget; | |
| 11230 } | |
| 11231 } | |
| 11232 | |
| 11233 /** | 11262 /** |
| 11234 * If it is appropriate to do so, override the current type of the static and
propagated elements | 11263 * If it is appropriate to do so, override the current type of the static and
propagated elements |
| 11235 * associated with the given expression with the given type. Generally speakin
g, it is appropriate | 11264 * associated with the given expression with the given type. Generally speakin
g, it is appropriate |
| 11236 * if the given type is more specific than the current type. | 11265 * if the given type is more specific than the current type. |
| 11237 * | 11266 * |
| 11238 * @param expression the expression used to access the static and propagated e
lements whose types | 11267 * @param expression the expression used to access the static and propagated e
lements whose types |
| 11239 * might be overridden | 11268 * might be overridden |
| 11240 * @param potentialType the potential type of the elements | 11269 * @param potentialType the potential type of the elements |
| 11241 * @param allowPrecisionLoss see @{code overrideVariable} docs | 11270 * @param allowPrecisionLoss see @{code overrideVariable} docs |
| 11242 */ | 11271 */ |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11375 } | 11404 } |
| 11376 node.accept(_elementResolver); | 11405 node.accept(_elementResolver); |
| 11377 node.accept(_typeAnalyzer); | 11406 node.accept(_typeAnalyzer); |
| 11378 return null; | 11407 return null; |
| 11379 } | 11408 } |
| 11380 | 11409 |
| 11381 @override | 11410 @override |
| 11382 Object visitBlockFunctionBody(BlockFunctionBody node) { | 11411 Object visitBlockFunctionBody(BlockFunctionBody node) { |
| 11383 safelyVisit(_commentBeforeFunction); | 11412 safelyVisit(_commentBeforeFunction); |
| 11384 _overrideManager.enterScope(); | 11413 _overrideManager.enterScope(); |
| 11385 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 11386 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | |
| 11387 try { | 11414 try { |
| 11388 _unlabeledBreakTarget = null; | |
| 11389 _unlabeledContinueTarget = null; | |
| 11390 super.visitBlockFunctionBody(node); | 11415 super.visitBlockFunctionBody(node); |
| 11391 } finally { | 11416 } finally { |
| 11392 _overrideManager.exitScope(); | 11417 _overrideManager.exitScope(); |
| 11393 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 11394 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | |
| 11395 } | 11418 } |
| 11396 return null; | 11419 return null; |
| 11397 } | 11420 } |
| 11398 | 11421 |
| 11399 @override | 11422 @override |
| 11400 Object visitBreakStatement(BreakStatement node) { | 11423 Object visitBreakStatement(BreakStatement node) { |
| 11401 // | 11424 // |
| 11402 // We do not visit the label because it needs to be visited in the context | 11425 // We do not visit the label because it needs to be visited in the context |
| 11403 // of the statement. | 11426 // of the statement. |
| 11404 // | 11427 // |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11593 // We do not visit the label because it needs to be visited in the context | 11616 // We do not visit the label because it needs to be visited in the context |
| 11594 // of the statement. | 11617 // of the statement. |
| 11595 // | 11618 // |
| 11596 node.accept(_elementResolver); | 11619 node.accept(_elementResolver); |
| 11597 node.accept(_typeAnalyzer); | 11620 node.accept(_typeAnalyzer); |
| 11598 return null; | 11621 return null; |
| 11599 } | 11622 } |
| 11600 | 11623 |
| 11601 @override | 11624 @override |
| 11602 Object visitDoStatement(DoStatement node) { | 11625 Object visitDoStatement(DoStatement node) { |
| 11603 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 11604 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | |
| 11605 _overrideManager.enterScope(); | 11626 _overrideManager.enterScope(); |
| 11606 try { | 11627 try { |
| 11607 _unlabeledBreakTarget = node; | |
| 11608 _unlabeledContinueTarget = node; | |
| 11609 super.visitDoStatement(node); | 11628 super.visitDoStatement(node); |
| 11610 } finally { | 11629 } finally { |
| 11611 _overrideManager.exitScope(); | 11630 _overrideManager.exitScope(); |
| 11612 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 11613 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | |
| 11614 } | 11631 } |
| 11615 // TODO(brianwilkerson) If the loop can only be exited because the condition | 11632 // TODO(brianwilkerson) If the loop can only be exited because the condition |
| 11616 // is false, then propagateFalseState(node.getCondition()); | 11633 // is false, then propagateFalseState(node.getCondition()); |
| 11617 return null; | 11634 return null; |
| 11618 } | 11635 } |
| 11619 | 11636 |
| 11620 @override | 11637 @override |
| 11621 Object visitEmptyFunctionBody(EmptyFunctionBody node) { | 11638 Object visitEmptyFunctionBody(EmptyFunctionBody node) { |
| 11622 safelyVisit(_commentBeforeFunction); | 11639 safelyVisit(_commentBeforeFunction); |
| 11623 return super.visitEmptyFunctionBody(node); | 11640 return super.visitEmptyFunctionBody(node); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11659 Map<VariableElement, DartType> overrides = | 11676 Map<VariableElement, DartType> overrides = |
| 11660 _overrideManager.captureOverrides(node.fields); | 11677 _overrideManager.captureOverrides(node.fields); |
| 11661 _overrideManager.exitScope(); | 11678 _overrideManager.exitScope(); |
| 11662 _overrideManager.applyOverrides(overrides); | 11679 _overrideManager.applyOverrides(overrides); |
| 11663 } | 11680 } |
| 11664 return null; | 11681 return null; |
| 11665 } | 11682 } |
| 11666 | 11683 |
| 11667 @override | 11684 @override |
| 11668 Object visitForEachStatement(ForEachStatement node) { | 11685 Object visitForEachStatement(ForEachStatement node) { |
| 11669 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 11670 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | |
| 11671 _overrideManager.enterScope(); | 11686 _overrideManager.enterScope(); |
| 11672 try { | 11687 try { |
| 11673 _unlabeledBreakTarget = node; | |
| 11674 _unlabeledContinueTarget = node; | |
| 11675 super.visitForEachStatement(node); | 11688 super.visitForEachStatement(node); |
| 11676 } finally { | 11689 } finally { |
| 11677 _overrideManager.exitScope(); | 11690 _overrideManager.exitScope(); |
| 11678 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 11679 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | |
| 11680 } | 11691 } |
| 11681 return null; | 11692 return null; |
| 11682 } | 11693 } |
| 11683 | 11694 |
| 11684 @override | 11695 @override |
| 11685 void visitForEachStatementInScope(ForEachStatement node) { | 11696 void visitForEachStatementInScope(ForEachStatement node) { |
| 11686 // | 11697 // |
| 11687 // We visit the iterator before the loop variable because the loop variable | 11698 // We visit the iterator before the loop variable because the loop variable |
| 11688 // cannot be in scope while visiting the iterator. | 11699 // cannot be in scope while visiting the iterator. |
| 11689 // | 11700 // |
| (...skipping 26 matching lines...) Expand all Loading... |
| 11716 } finally { | 11727 } finally { |
| 11717 _overrideManager.exitScope(); | 11728 _overrideManager.exitScope(); |
| 11718 } | 11729 } |
| 11719 } | 11730 } |
| 11720 node.accept(_elementResolver); | 11731 node.accept(_elementResolver); |
| 11721 node.accept(_typeAnalyzer); | 11732 node.accept(_typeAnalyzer); |
| 11722 } | 11733 } |
| 11723 | 11734 |
| 11724 @override | 11735 @override |
| 11725 Object visitForStatement(ForStatement node) { | 11736 Object visitForStatement(ForStatement node) { |
| 11726 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 11727 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | |
| 11728 _overrideManager.enterScope(); | 11737 _overrideManager.enterScope(); |
| 11729 try { | 11738 try { |
| 11730 _unlabeledBreakTarget = node; | |
| 11731 _unlabeledContinueTarget = node; | |
| 11732 super.visitForStatement(node); | 11739 super.visitForStatement(node); |
| 11733 } finally { | 11740 } finally { |
| 11734 _overrideManager.exitScope(); | 11741 _overrideManager.exitScope(); |
| 11735 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 11736 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | |
| 11737 } | 11742 } |
| 11738 return null; | 11743 return null; |
| 11739 } | 11744 } |
| 11740 | 11745 |
| 11741 @override | 11746 @override |
| 11742 void visitForStatementInScope(ForStatement node) { | 11747 void visitForStatementInScope(ForStatement node) { |
| 11743 safelyVisit(node.variables); | 11748 safelyVisit(node.variables); |
| 11744 safelyVisit(node.initialization); | 11749 safelyVisit(node.initialization); |
| 11745 safelyVisit(node.condition); | 11750 safelyVisit(node.condition); |
| 11746 _overrideManager.enterScope(); | 11751 _overrideManager.enterScope(); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11988 _overrideManager.enterScope(); | 11993 _overrideManager.enterScope(); |
| 11989 try { | 11994 try { |
| 11990 super.visitSwitchDefault(node); | 11995 super.visitSwitchDefault(node); |
| 11991 } finally { | 11996 } finally { |
| 11992 _overrideManager.exitScope(); | 11997 _overrideManager.exitScope(); |
| 11993 } | 11998 } |
| 11994 return null; | 11999 return null; |
| 11995 } | 12000 } |
| 11996 | 12001 |
| 11997 @override | 12002 @override |
| 11998 Object visitSwitchStatement(SwitchStatement node) { | |
| 11999 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 12000 try { | |
| 12001 _unlabeledBreakTarget = node; | |
| 12002 super.visitSwitchStatement(node); | |
| 12003 } finally { | |
| 12004 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 12005 } | |
| 12006 return null; | |
| 12007 } | |
| 12008 | |
| 12009 @override | |
| 12010 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 12003 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 12011 _overrideManager.enterScope(); | 12004 _overrideManager.enterScope(); |
| 12012 try { | 12005 try { |
| 12013 super.visitTopLevelVariableDeclaration(node); | 12006 super.visitTopLevelVariableDeclaration(node); |
| 12014 } finally { | 12007 } finally { |
| 12015 Map<VariableElement, DartType> overrides = | 12008 Map<VariableElement, DartType> overrides = |
| 12016 _overrideManager.captureOverrides(node.variables); | 12009 _overrideManager.captureOverrides(node.variables); |
| 12017 _overrideManager.exitScope(); | 12010 _overrideManager.exitScope(); |
| 12018 _overrideManager.applyOverrides(overrides); | 12011 _overrideManager.applyOverrides(overrides); |
| 12019 } | 12012 } |
| 12020 return null; | 12013 return null; |
| 12021 } | 12014 } |
| 12022 | 12015 |
| 12023 @override | 12016 @override |
| 12024 Object visitTypeName(TypeName node) => null; | 12017 Object visitTypeName(TypeName node) => null; |
| 12025 | 12018 |
| 12026 @override | 12019 @override |
| 12027 Object visitWhileStatement(WhileStatement node) { | 12020 Object visitWhileStatement(WhileStatement node) { |
| 12028 Expression condition = node.condition; | 12021 // Note: since we don't call the base class, we have to maintain |
| 12029 safelyVisit(condition); | 12022 // _implicitLabelScope ourselves. |
| 12030 Statement body = node.body; | 12023 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 12031 if (body != null) { | 12024 try { |
| 12032 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | 12025 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 12033 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | 12026 Expression condition = node.condition; |
| 12034 _overrideManager.enterScope(); | 12027 safelyVisit(condition); |
| 12035 try { | 12028 Statement body = node.body; |
| 12036 _unlabeledBreakTarget = node; | 12029 if (body != null) { |
| 12037 _unlabeledContinueTarget = node; | 12030 _overrideManager.enterScope(); |
| 12038 _propagateTrueState(condition); | 12031 try { |
| 12039 visitStatementInScope(body); | 12032 _propagateTrueState(condition); |
| 12040 } finally { | 12033 visitStatementInScope(body); |
| 12041 _overrideManager.exitScope(); | 12034 } finally { |
| 12042 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | 12035 _overrideManager.exitScope(); |
| 12043 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | 12036 } |
| 12044 } | 12037 } |
| 12038 } finally { |
| 12039 _implicitLabelScope = outerImplicitScope; |
| 12045 } | 12040 } |
| 12046 // TODO(brianwilkerson) If the loop can only be exited because the condition | 12041 // TODO(brianwilkerson) If the loop can only be exited because the condition |
| 12047 // is false, then propagateFalseState(condition); | 12042 // is false, then propagateFalseState(condition); |
| 12048 node.accept(_elementResolver); | 12043 node.accept(_elementResolver); |
| 12049 node.accept(_typeAnalyzer); | 12044 node.accept(_typeAnalyzer); |
| 12050 return null; | 12045 return null; |
| 12051 } | 12046 } |
| 12052 | 12047 |
| 12053 /** | 12048 /** |
| 12054 * Checks each promoted variable in the current scope for compliance with the
following | 12049 * Checks each promoted variable in the current scope for compliance with the
following |
| (...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12643 * The scope used to resolve identifiers. | 12638 * The scope used to resolve identifiers. |
| 12644 */ | 12639 */ |
| 12645 Scope _nameScope; | 12640 Scope _nameScope; |
| 12646 | 12641 |
| 12647 /** | 12642 /** |
| 12648 * The object used to access the types from the core library. | 12643 * The object used to access the types from the core library. |
| 12649 */ | 12644 */ |
| 12650 final TypeProvider typeProvider; | 12645 final TypeProvider typeProvider; |
| 12651 | 12646 |
| 12652 /** | 12647 /** |
| 12648 * The scope used to resolve unlabeled `break` and `continue` statements. |
| 12649 */ |
| 12650 ImplicitLabelScope _implicitLabelScope = ImplicitLabelScope.ROOT; |
| 12651 |
| 12652 /** |
| 12653 * The scope used to resolve labels for `break` and `continue` statements, or | 12653 * The scope used to resolve labels for `break` and `continue` statements, or |
| 12654 * `null` if no labels have been defined in the current context. | 12654 * `null` if no labels have been defined in the current context. |
| 12655 */ | 12655 */ |
| 12656 LabelScope _labelScope; | 12656 LabelScope _labelScope; |
| 12657 | 12657 |
| 12658 /** | 12658 /** |
| 12659 * The class containing the AST nodes being visited, | 12659 * The class containing the AST nodes being visited, |
| 12660 * or `null` if we are not in the scope of a class. | 12660 * or `null` if we are not in the scope of a class. |
| 12661 */ | 12661 */ |
| 12662 ClassElement enclosingClass; | 12662 ClassElement enclosingClass; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12726 } | 12726 } |
| 12727 | 12727 |
| 12728 /** | 12728 /** |
| 12729 * Return the library element for the library containing the compilation unit
being resolved. | 12729 * Return the library element for the library containing the compilation unit
being resolved. |
| 12730 * | 12730 * |
| 12731 * @return the library element for the library containing the compilation unit
being resolved | 12731 * @return the library element for the library containing the compilation unit
being resolved |
| 12732 */ | 12732 */ |
| 12733 LibraryElement get definingLibrary => _definingLibrary; | 12733 LibraryElement get definingLibrary => _definingLibrary; |
| 12734 | 12734 |
| 12735 /** | 12735 /** |
| 12736 * Return the implicit label scope in which the current node is being |
| 12737 * resolved. |
| 12738 */ |
| 12739 ImplicitLabelScope get implicitLabelScope => _implicitLabelScope; |
| 12740 |
| 12741 /** |
| 12736 * Return the label scope in which the current node is being resolved. | 12742 * Return the label scope in which the current node is being resolved. |
| 12737 * | 12743 * |
| 12738 * @return the label scope in which the current node is being resolved | 12744 * @return the label scope in which the current node is being resolved |
| 12739 */ | 12745 */ |
| 12740 LabelScope get labelScope => _labelScope; | 12746 LabelScope get labelScope => _labelScope; |
| 12741 | 12747 |
| 12742 /** | 12748 /** |
| 12743 * Return the name scope in which the current node is being resolved. | 12749 * Return the name scope in which the current node is being resolved. |
| 12744 * | 12750 * |
| 12745 * @return the name scope in which the current node is being resolved | 12751 * @return the name scope in which the current node is being resolved |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12831 _hideNamesDefinedInBlock(enclosedScope, node); | 12837 _hideNamesDefinedInBlock(enclosedScope, node); |
| 12832 _nameScope = enclosedScope; | 12838 _nameScope = enclosedScope; |
| 12833 super.visitBlock(node); | 12839 super.visitBlock(node); |
| 12834 } finally { | 12840 } finally { |
| 12835 _nameScope = outerScope; | 12841 _nameScope = outerScope; |
| 12836 } | 12842 } |
| 12837 return null; | 12843 return null; |
| 12838 } | 12844 } |
| 12839 | 12845 |
| 12840 @override | 12846 @override |
| 12847 Object visitBlockFunctionBody(BlockFunctionBody node) { |
| 12848 ImplicitLabelScope implicitOuterScope = _implicitLabelScope; |
| 12849 try { |
| 12850 _implicitLabelScope = ImplicitLabelScope.ROOT; |
| 12851 super.visitBlockFunctionBody(node); |
| 12852 } finally { |
| 12853 _implicitLabelScope = implicitOuterScope; |
| 12854 } |
| 12855 return null; |
| 12856 } |
| 12857 |
| 12858 @override |
| 12841 Object visitCatchClause(CatchClause node) { | 12859 Object visitCatchClause(CatchClause node) { |
| 12842 SimpleIdentifier exception = node.exceptionParameter; | 12860 SimpleIdentifier exception = node.exceptionParameter; |
| 12843 if (exception != null) { | 12861 if (exception != null) { |
| 12844 Scope outerScope = _nameScope; | 12862 Scope outerScope = _nameScope; |
| 12845 try { | 12863 try { |
| 12846 _nameScope = new EnclosedScope(_nameScope); | 12864 _nameScope = new EnclosedScope(_nameScope); |
| 12847 _nameScope.define(exception.staticElement); | 12865 _nameScope.define(exception.staticElement); |
| 12848 SimpleIdentifier stackTrace = node.stackTraceParameter; | 12866 SimpleIdentifier stackTrace = node.stackTraceParameter; |
| 12849 if (stackTrace != null) { | 12867 if (stackTrace != null) { |
| 12850 _nameScope.define(stackTrace.staticElement); | 12868 _nameScope.define(stackTrace.staticElement); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12949 VariableElement element = node.element; | 12967 VariableElement element = node.element; |
| 12950 if (element != null) { | 12968 if (element != null) { |
| 12951 _nameScope.define(element); | 12969 _nameScope.define(element); |
| 12952 } | 12970 } |
| 12953 super.visitDeclaredIdentifier(node); | 12971 super.visitDeclaredIdentifier(node); |
| 12954 return null; | 12972 return null; |
| 12955 } | 12973 } |
| 12956 | 12974 |
| 12957 @override | 12975 @override |
| 12958 Object visitDoStatement(DoStatement node) { | 12976 Object visitDoStatement(DoStatement node) { |
| 12959 visitStatementInScope(node.body); | 12977 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 12960 safelyVisit(node.condition); | 12978 try { |
| 12979 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 12980 visitStatementInScope(node.body); |
| 12981 safelyVisit(node.condition); |
| 12982 } finally { |
| 12983 _implicitLabelScope = outerImplicitScope; |
| 12984 } |
| 12961 return null; | 12985 return null; |
| 12962 } | 12986 } |
| 12963 | 12987 |
| 12964 @override | 12988 @override |
| 12965 Object visitForEachStatement(ForEachStatement node) { | 12989 Object visitForEachStatement(ForEachStatement node) { |
| 12966 Scope outerNameScope = _nameScope; | 12990 Scope outerNameScope = _nameScope; |
| 12991 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 12967 try { | 12992 try { |
| 12968 _nameScope = new EnclosedScope(_nameScope); | 12993 _nameScope = new EnclosedScope(_nameScope); |
| 12994 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 12969 visitForEachStatementInScope(node); | 12995 visitForEachStatementInScope(node); |
| 12970 } finally { | 12996 } finally { |
| 12971 _nameScope = outerNameScope; | 12997 _nameScope = outerNameScope; |
| 12998 _implicitLabelScope = outerImplicitScope; |
| 12972 } | 12999 } |
| 12973 return null; | 13000 return null; |
| 12974 } | 13001 } |
| 12975 | 13002 |
| 12976 /** | 13003 /** |
| 12977 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 13004 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
| 12978 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 13005 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
| 12979 * enabled. | 13006 * enabled. |
| 12980 * | 13007 * |
| 12981 * @param node the statement to be visited | 13008 * @param node the statement to be visited |
| (...skipping 19 matching lines...) Expand all Loading... |
| 13001 } | 13028 } |
| 13002 if (_nameScope is FunctionTypeScope) { | 13029 if (_nameScope is FunctionTypeScope) { |
| 13003 (_nameScope as FunctionTypeScope).defineParameters(); | 13030 (_nameScope as FunctionTypeScope).defineParameters(); |
| 13004 } | 13031 } |
| 13005 return null; | 13032 return null; |
| 13006 } | 13033 } |
| 13007 | 13034 |
| 13008 @override | 13035 @override |
| 13009 Object visitForStatement(ForStatement node) { | 13036 Object visitForStatement(ForStatement node) { |
| 13010 Scope outerNameScope = _nameScope; | 13037 Scope outerNameScope = _nameScope; |
| 13038 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 13011 try { | 13039 try { |
| 13012 _nameScope = new EnclosedScope(_nameScope); | 13040 _nameScope = new EnclosedScope(_nameScope); |
| 13041 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 13013 visitForStatementInScope(node); | 13042 visitForStatementInScope(node); |
| 13014 } finally { | 13043 } finally { |
| 13015 _nameScope = outerNameScope; | 13044 _nameScope = outerNameScope; |
| 13045 _implicitLabelScope = outerImplicitScope; |
| 13016 } | 13046 } |
| 13017 return null; | 13047 return null; |
| 13018 } | 13048 } |
| 13019 | 13049 |
| 13020 /** | 13050 /** |
| 13021 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 13051 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
| 13022 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 13052 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
| 13023 * enabled. | 13053 * enabled. |
| 13024 * | 13054 * |
| 13025 * @param node the statement to be visited | 13055 * @param node the statement to be visited |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13185 node.statements.accept(this); | 13215 node.statements.accept(this); |
| 13186 } finally { | 13216 } finally { |
| 13187 _nameScope = outerNameScope; | 13217 _nameScope = outerNameScope; |
| 13188 } | 13218 } |
| 13189 return null; | 13219 return null; |
| 13190 } | 13220 } |
| 13191 | 13221 |
| 13192 @override | 13222 @override |
| 13193 Object visitSwitchStatement(SwitchStatement node) { | 13223 Object visitSwitchStatement(SwitchStatement node) { |
| 13194 LabelScope outerScope = _labelScope; | 13224 LabelScope outerScope = _labelScope; |
| 13225 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 13195 try { | 13226 try { |
| 13227 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 13196 for (SwitchMember member in node.members) { | 13228 for (SwitchMember member in node.members) { |
| 13197 for (Label label in member.labels) { | 13229 for (Label label in member.labels) { |
| 13198 SimpleIdentifier labelName = label.label; | 13230 SimpleIdentifier labelName = label.label; |
| 13199 LabelElement labelElement = labelName.staticElement as LabelElement; | 13231 LabelElement labelElement = labelName.staticElement as LabelElement; |
| 13200 _labelScope = | 13232 _labelScope = |
| 13201 new LabelScope(_labelScope, labelName.name, member, labelElement); | 13233 new LabelScope(_labelScope, labelName.name, member, labelElement); |
| 13202 } | 13234 } |
| 13203 } | 13235 } |
| 13204 super.visitSwitchStatement(node); | 13236 super.visitSwitchStatement(node); |
| 13205 } finally { | 13237 } finally { |
| 13206 _labelScope = outerScope; | 13238 _labelScope = outerScope; |
| 13239 _implicitLabelScope = outerImplicitScope; |
| 13207 } | 13240 } |
| 13208 return null; | 13241 return null; |
| 13209 } | 13242 } |
| 13210 | 13243 |
| 13211 @override | 13244 @override |
| 13212 Object visitVariableDeclaration(VariableDeclaration node) { | 13245 Object visitVariableDeclaration(VariableDeclaration node) { |
| 13213 super.visitVariableDeclaration(node); | 13246 super.visitVariableDeclaration(node); |
| 13214 if (node.parent.parent is! TopLevelVariableDeclaration && | 13247 if (node.parent.parent is! TopLevelVariableDeclaration && |
| 13215 node.parent.parent is! FieldDeclaration) { | 13248 node.parent.parent is! FieldDeclaration) { |
| 13216 VariableElement element = node.element; | 13249 VariableElement element = node.element; |
| 13217 if (element != null) { | 13250 if (element != null) { |
| 13218 _nameScope.define(element); | 13251 _nameScope.define(element); |
| 13219 } | 13252 } |
| 13220 } | 13253 } |
| 13221 return null; | 13254 return null; |
| 13222 } | 13255 } |
| 13223 | 13256 |
| 13224 @override | 13257 @override |
| 13225 Object visitWhileStatement(WhileStatement node) { | 13258 Object visitWhileStatement(WhileStatement node) { |
| 13226 safelyVisit(node.condition); | 13259 safelyVisit(node.condition); |
| 13227 visitStatementInScope(node.body); | 13260 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 13261 try { |
| 13262 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 13263 visitStatementInScope(node.body); |
| 13264 } finally { |
| 13265 _implicitLabelScope = outerImplicitScope; |
| 13266 } |
| 13228 return null; | 13267 return null; |
| 13229 } | 13268 } |
| 13230 | 13269 |
| 13231 /** | 13270 /** |
| 13232 * Add scopes for each of the given labels. | 13271 * Add scopes for each of the given labels. |
| 13233 * | 13272 * |
| 13234 * @param labels the labels for which new scopes are to be added | 13273 * @param labels the labels for which new scopes are to be added |
| 13235 * @return the scope that was in effect before the new scopes were added | 13274 * @return the scope that was in effect before the new scopes were added |
| 13236 */ | 13275 */ |
| 13237 LabelScope _addScopesFor(NodeList<Label> labels, AstNode node) { | 13276 LabelScope _addScopesFor(NodeList<Label> labels, AstNode node) { |
| (...skipping 2987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16225 * library. | 16264 * library. |
| 16226 */ | 16265 */ |
| 16227 final HashSet<String> members = new HashSet<String>(); | 16266 final HashSet<String> members = new HashSet<String>(); |
| 16228 | 16267 |
| 16229 /** | 16268 /** |
| 16230 * Names of resolved or unresolved class members that are read in the | 16269 * Names of resolved or unresolved class members that are read in the |
| 16231 * library. | 16270 * library. |
| 16232 */ | 16271 */ |
| 16233 final HashSet<String> readMembers = new HashSet<String>(); | 16272 final HashSet<String> readMembers = new HashSet<String>(); |
| 16234 } | 16273 } |
| OLD | NEW |