Chromium Code Reviews| 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 7215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7226 INIT_IN_INITIALIZERS]; | 7226 INIT_IN_INITIALIZERS]; |
| 7227 | 7227 |
| 7228 const INIT_STATE(String name, int ordinal) : super(name, ordinal); | 7228 const INIT_STATE(String name, int ordinal) : super(name, ordinal); |
| 7229 } | 7229 } |
| 7230 | 7230 |
| 7231 /** | 7231 /** |
| 7232 * Instances of the class `LabelScope` represent a scope in which a single label is defined. | 7232 * Instances of the class `LabelScope` represent a scope in which a single label is defined. |
| 7233 */ | 7233 */ |
| 7234 class LabelScope { | 7234 class LabelScope { |
| 7235 /** | 7235 /** |
| 7236 * The marker used to look up a label element for an unlabeled `break` or `con tinue`. | |
| 7237 */ | |
| 7238 static String EMPTY_LABEL = ""; | |
| 7239 | |
| 7240 /** | |
| 7241 * The label element returned for scopes that can be the target of an unlabele d `break` or | |
| 7242 * `continue`. | |
| 7243 */ | |
| 7244 static SimpleIdentifier _EMPTY_LABEL_IDENTIFIER = | |
| 7245 new SimpleIdentifier(new sc.StringToken(sc.TokenType.IDENTIFIER, "", 0)); | |
| 7246 | |
| 7247 /** | |
| 7248 * The label scope enclosing this label scope. | 7236 * The label scope enclosing this label scope. |
| 7249 */ | 7237 */ |
| 7250 final LabelScope _outerScope; | 7238 final LabelScope _outerScope; |
| 7251 | 7239 |
| 7252 /** | 7240 /** |
| 7253 * The label defined in this scope. | 7241 * The label defined in this scope. |
| 7254 */ | 7242 */ |
| 7255 final String _label; | 7243 final String _label; |
| 7256 | 7244 |
| 7257 /** | 7245 /** |
| 7258 * The element to which the label resolves. | 7246 * The element to which the label resolves. |
| 7259 */ | 7247 */ |
| 7260 final LabelElement _element; | 7248 final LabelElement element; |
| 7261 | 7249 |
| 7262 /** | 7250 /** |
| 7263 * Initialize a newly created scope to represent the potential target of an un labeled | 7251 * The AST node to which the label resolves. |
| 7264 * `break` or `continue`. | |
| 7265 * | |
| 7266 * @param outerScope the label scope enclosing the new label scope | |
| 7267 * @param onSwitchStatement `true` if this label is associated with a `switch` | |
| 7268 * statement | |
| 7269 * @param onSwitchMember `true` if this label is associated with a `switch` me mber | |
| 7270 */ | 7252 */ |
| 7271 LabelScope.con1(LabelScope outerScope, bool onSwitchStatement, | 7253 final AstNode node; |
| 7272 bool onSwitchMember) | |
| 7273 : this.con2( | |
| 7274 outerScope, | |
| 7275 EMPTY_LABEL, | |
| 7276 new LabelElementImpl( | |
| 7277 _EMPTY_LABEL_IDENTIFIER, | |
| 7278 onSwitchStatement, | |
| 7279 onSwitchMember)); | |
| 7280 | 7254 |
| 7281 /** | 7255 /** |
| 7282 * Initialize a newly created scope to represent the given label. | 7256 * Initialize a newly created scope to represent the label [_label]. |
| 7283 * | 7257 * [_outerScope] is the scope enclosing the new label scope. [node] is the |
| 7284 * @param outerScope the label scope enclosing the new label scope | 7258 * AST node the label resolves to. [element] is the element the label |
| 7285 * @param label the label defined in this scope | 7259 * resolves to. |
| 7286 * @param element the element to which the label resolves | |
| 7287 */ | 7260 */ |
| 7288 LabelScope.con2(this._outerScope, this._label, this._element); | 7261 LabelScope(this._outerScope, this._label, this.node, this.element); |
| 7289 | 7262 |
| 7290 /** | 7263 /** |
| 7291 * Return the label element corresponding to the given label, or `null` if the given label | 7264 * Return the LabelScope which defines [targetLabel], or `null` if it is not |
| 7292 * is not defined in this scope. | 7265 * defined in this scope. |
| 7293 * | |
| 7294 * @param targetLabel the label being looked up | |
| 7295 * @return the label element corresponding to the given label | |
| 7296 */ | 7266 */ |
| 7297 LabelElement lookup(String targetLabel) { | 7267 LabelScope lookup(String targetLabel) { |
| 7298 if (_label == targetLabel) { | 7268 if (_label == targetLabel) { |
| 7299 return _element; | 7269 return this; |
| 7300 } else if (_outerScope != null) { | 7270 } else if (_outerScope != null) { |
| 7301 return _outerScope.lookup(targetLabel); | 7271 return _outerScope.lookup(targetLabel); |
| 7302 } else { | 7272 } else { |
| 7303 return null; | 7273 return null; |
| 7304 } | 7274 } |
| 7305 } | 7275 } |
| 7306 } | 7276 } |
| 7307 | 7277 |
| 7308 /** | 7278 /** |
| 7309 * Instances of the class `Library` represent the data about a single library du ring the | 7279 * Instances of the class `Library` represent the data about a single library du ring the |
| (...skipping 3739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11049 * The object keeping track of which elements have had their types overridden. | 11019 * The object keeping track of which elements have had their types overridden. |
| 11050 */ | 11020 */ |
| 11051 TypeOverrideManager _overrideManager = new TypeOverrideManager(); | 11021 TypeOverrideManager _overrideManager = new TypeOverrideManager(); |
| 11052 | 11022 |
| 11053 /** | 11023 /** |
| 11054 * The object keeping track of which elements have had their types promoted. | 11024 * The object keeping track of which elements have had their types promoted. |
| 11055 */ | 11025 */ |
| 11056 TypePromotionManager _promoteManager = new TypePromotionManager(); | 11026 TypePromotionManager _promoteManager = new TypePromotionManager(); |
| 11057 | 11027 |
| 11058 /** | 11028 /** |
| 11029 * The AST node representing the innermost enclosing statement that can be | |
| 11030 * target of an unlabeled "break" statement, or null if there is no such | |
|
Brian Wilkerson
2014/11/24 23:20:53
"target" --> "the target"
"null" --> "`null`"
(bo
| |
| 11031 * statement. | |
| 11032 */ | |
| 11033 Statement _unlabeledBreakTarget; | |
|
Brian Wilkerson
2014/11/24 23:20:53
I'm not thrilled with this implementation for two
| |
| 11034 | |
| 11035 /** | |
| 11036 * The AST node representing the innermost enclosing statement that can be | |
| 11037 * target of an unlabeled "continue" statement, or null if there is no such | |
| 11038 * statement. | |
| 11039 */ | |
| 11040 Statement _unlabeledContinueTarget; | |
| 11041 | |
| 11042 /** | |
| 11059 * Initialize a newly created visitor to resolve the nodes in a compilation un it. | 11043 * Initialize a newly created visitor to resolve the nodes in a compilation un it. |
| 11060 * | 11044 * |
| 11061 * @param library the library containing the compilation unit being resolved | 11045 * @param library the library containing the compilation unit being resolved |
| 11062 * @param source the source representing the compilation unit being visited | 11046 * @param source the source representing the compilation unit being visited |
| 11063 * @param typeProvider the object used to access the types from the core libra ry | 11047 * @param typeProvider the object used to access the types from the core libra ry |
| 11064 */ | 11048 */ |
| 11065 ResolverVisitor.con1(Library library, Source source, | 11049 ResolverVisitor.con1(Library library, Source source, |
| 11066 TypeProvider typeProvider) | 11050 TypeProvider typeProvider) |
| 11067 : super.con1(library, source, typeProvider) { | 11051 : super.con1(library, source, typeProvider) { |
| 11068 this._inheritanceManager = library.inheritanceManager; | 11052 this._inheritanceManager = library.inheritanceManager; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11231 ElementKind kind = element.kind; | 11215 ElementKind kind = element.kind; |
| 11232 if (kind == ElementKind.LOCAL_VARIABLE) { | 11216 if (kind == ElementKind.LOCAL_VARIABLE) { |
| 11233 return element as VariableElement; | 11217 return element as VariableElement; |
| 11234 } | 11218 } |
| 11235 if (kind == ElementKind.PARAMETER) { | 11219 if (kind == ElementKind.PARAMETER) { |
| 11236 return element as VariableElement; | 11220 return element as VariableElement; |
| 11237 } | 11221 } |
| 11238 return null; | 11222 return null; |
| 11239 } | 11223 } |
| 11240 | 11224 |
| 11225 AstNode getUnlabeledBreakOrContinueTarget(bool isContinue) { | |
| 11226 if (isContinue) { | |
| 11227 return _unlabeledContinueTarget; | |
| 11228 } else { | |
| 11229 return _unlabeledBreakTarget; | |
| 11230 } | |
| 11231 } | |
| 11232 | |
| 11241 /** | 11233 /** |
| 11242 * If it is appropriate to do so, override the current type of the static and propagated elements | 11234 * If it is appropriate to do so, override the current type of the static and propagated elements |
| 11243 * associated with the given expression with the given type. Generally speakin g, it is appropriate | 11235 * associated with the given expression with the given type. Generally speakin g, it is appropriate |
| 11244 * if the given type is more specific than the current type. | 11236 * if the given type is more specific than the current type. |
| 11245 * | 11237 * |
| 11246 * @param expression the expression used to access the static and propagated e lements whose types | 11238 * @param expression the expression used to access the static and propagated e lements whose types |
| 11247 * might be overridden | 11239 * might be overridden |
| 11248 * @param potentialType the potential type of the elements | 11240 * @param potentialType the potential type of the elements |
| 11249 * @param allowPrecisionLoss see @{code overrideVariable} docs | 11241 * @param allowPrecisionLoss see @{code overrideVariable} docs |
| 11250 */ | 11242 */ |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11383 } | 11375 } |
| 11384 node.accept(_elementResolver); | 11376 node.accept(_elementResolver); |
| 11385 node.accept(_typeAnalyzer); | 11377 node.accept(_typeAnalyzer); |
| 11386 return null; | 11378 return null; |
| 11387 } | 11379 } |
| 11388 | 11380 |
| 11389 @override | 11381 @override |
| 11390 Object visitBlockFunctionBody(BlockFunctionBody node) { | 11382 Object visitBlockFunctionBody(BlockFunctionBody node) { |
| 11391 safelyVisit(_commentBeforeFunction); | 11383 safelyVisit(_commentBeforeFunction); |
| 11392 _overrideManager.enterScope(); | 11384 _overrideManager.enterScope(); |
| 11385 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 11386 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | |
| 11393 try { | 11387 try { |
| 11388 _unlabeledBreakTarget = null; | |
| 11389 _unlabeledContinueTarget = null; | |
| 11394 super.visitBlockFunctionBody(node); | 11390 super.visitBlockFunctionBody(node); |
| 11395 } finally { | 11391 } finally { |
| 11396 _overrideManager.exitScope(); | 11392 _overrideManager.exitScope(); |
| 11393 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 11394 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | |
| 11397 } | 11395 } |
| 11398 return null; | 11396 return null; |
| 11399 } | 11397 } |
| 11400 | 11398 |
| 11401 @override | 11399 @override |
| 11402 Object visitBreakStatement(BreakStatement node) { | 11400 Object visitBreakStatement(BreakStatement node) { |
| 11403 // | 11401 // |
| 11404 // We do not visit the label because it needs to be visited in the context | 11402 // We do not visit the label because it needs to be visited in the context |
| 11405 // of the statement. | 11403 // of the statement. |
| 11406 // | 11404 // |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11595 // We do not visit the label because it needs to be visited in the context | 11593 // We do not visit the label because it needs to be visited in the context |
| 11596 // of the statement. | 11594 // of the statement. |
| 11597 // | 11595 // |
| 11598 node.accept(_elementResolver); | 11596 node.accept(_elementResolver); |
| 11599 node.accept(_typeAnalyzer); | 11597 node.accept(_typeAnalyzer); |
| 11600 return null; | 11598 return null; |
| 11601 } | 11599 } |
| 11602 | 11600 |
| 11603 @override | 11601 @override |
| 11604 Object visitDoStatement(DoStatement node) { | 11602 Object visitDoStatement(DoStatement node) { |
| 11603 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 11604 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | |
| 11605 _overrideManager.enterScope(); | 11605 _overrideManager.enterScope(); |
| 11606 try { | 11606 try { |
| 11607 _unlabeledBreakTarget = node; | |
| 11608 _unlabeledContinueTarget = node; | |
| 11607 super.visitDoStatement(node); | 11609 super.visitDoStatement(node); |
| 11608 } finally { | 11610 } finally { |
| 11609 _overrideManager.exitScope(); | 11611 _overrideManager.exitScope(); |
| 11612 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 11613 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | |
| 11610 } | 11614 } |
| 11611 // TODO(brianwilkerson) If the loop can only be exited because the condition | 11615 // TODO(brianwilkerson) If the loop can only be exited because the condition |
| 11612 // is false, then propagateFalseState(node.getCondition()); | 11616 // is false, then propagateFalseState(node.getCondition()); |
| 11613 return null; | 11617 return null; |
| 11614 } | 11618 } |
| 11615 | 11619 |
| 11616 @override | 11620 @override |
| 11617 Object visitEmptyFunctionBody(EmptyFunctionBody node) { | 11621 Object visitEmptyFunctionBody(EmptyFunctionBody node) { |
| 11618 safelyVisit(_commentBeforeFunction); | 11622 safelyVisit(_commentBeforeFunction); |
| 11619 return super.visitEmptyFunctionBody(node); | 11623 return super.visitEmptyFunctionBody(node); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11655 Map<VariableElement, DartType> overrides = | 11659 Map<VariableElement, DartType> overrides = |
| 11656 _overrideManager.captureOverrides(node.fields); | 11660 _overrideManager.captureOverrides(node.fields); |
| 11657 _overrideManager.exitScope(); | 11661 _overrideManager.exitScope(); |
| 11658 _overrideManager.applyOverrides(overrides); | 11662 _overrideManager.applyOverrides(overrides); |
| 11659 } | 11663 } |
| 11660 return null; | 11664 return null; |
| 11661 } | 11665 } |
| 11662 | 11666 |
| 11663 @override | 11667 @override |
| 11664 Object visitForEachStatement(ForEachStatement node) { | 11668 Object visitForEachStatement(ForEachStatement node) { |
| 11669 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 11670 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | |
| 11665 _overrideManager.enterScope(); | 11671 _overrideManager.enterScope(); |
| 11666 try { | 11672 try { |
| 11673 _unlabeledBreakTarget = node; | |
| 11674 _unlabeledContinueTarget = node; | |
| 11667 super.visitForEachStatement(node); | 11675 super.visitForEachStatement(node); |
| 11668 } finally { | 11676 } finally { |
| 11669 _overrideManager.exitScope(); | 11677 _overrideManager.exitScope(); |
| 11678 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 11679 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | |
| 11670 } | 11680 } |
| 11671 return null; | 11681 return null; |
| 11672 } | 11682 } |
| 11673 | 11683 |
| 11674 @override | 11684 @override |
| 11675 void visitForEachStatementInScope(ForEachStatement node) { | 11685 void visitForEachStatementInScope(ForEachStatement node) { |
| 11676 // | 11686 // |
| 11677 // We visit the iterator before the loop variable because the loop variable | 11687 // We visit the iterator before the loop variable because the loop variable |
| 11678 // cannot be in scope while visiting the iterator. | 11688 // cannot be in scope while visiting the iterator. |
| 11679 // | 11689 // |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 11706 } finally { | 11716 } finally { |
| 11707 _overrideManager.exitScope(); | 11717 _overrideManager.exitScope(); |
| 11708 } | 11718 } |
| 11709 } | 11719 } |
| 11710 node.accept(_elementResolver); | 11720 node.accept(_elementResolver); |
| 11711 node.accept(_typeAnalyzer); | 11721 node.accept(_typeAnalyzer); |
| 11712 } | 11722 } |
| 11713 | 11723 |
| 11714 @override | 11724 @override |
| 11715 Object visitForStatement(ForStatement node) { | 11725 Object visitForStatement(ForStatement node) { |
| 11726 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 11727 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | |
| 11716 _overrideManager.enterScope(); | 11728 _overrideManager.enterScope(); |
| 11717 try { | 11729 try { |
| 11730 _unlabeledBreakTarget = node; | |
| 11731 _unlabeledContinueTarget = node; | |
| 11718 super.visitForStatement(node); | 11732 super.visitForStatement(node); |
| 11719 } finally { | 11733 } finally { |
| 11720 _overrideManager.exitScope(); | 11734 _overrideManager.exitScope(); |
| 11735 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 11736 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | |
| 11721 } | 11737 } |
| 11722 return null; | 11738 return null; |
| 11723 } | 11739 } |
| 11724 | 11740 |
| 11725 @override | 11741 @override |
| 11726 void visitForStatementInScope(ForStatement node) { | 11742 void visitForStatementInScope(ForStatement node) { |
| 11727 safelyVisit(node.variables); | 11743 safelyVisit(node.variables); |
| 11728 safelyVisit(node.initialization); | 11744 safelyVisit(node.initialization); |
| 11729 safelyVisit(node.condition); | 11745 safelyVisit(node.condition); |
| 11730 _overrideManager.enterScope(); | 11746 _overrideManager.enterScope(); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11972 _overrideManager.enterScope(); | 11988 _overrideManager.enterScope(); |
| 11973 try { | 11989 try { |
| 11974 super.visitSwitchDefault(node); | 11990 super.visitSwitchDefault(node); |
| 11975 } finally { | 11991 } finally { |
| 11976 _overrideManager.exitScope(); | 11992 _overrideManager.exitScope(); |
| 11977 } | 11993 } |
| 11978 return null; | 11994 return null; |
| 11979 } | 11995 } |
| 11980 | 11996 |
| 11981 @override | 11997 @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 | |
| 11982 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { | 12010 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { |
| 11983 _overrideManager.enterScope(); | 12011 _overrideManager.enterScope(); |
| 11984 try { | 12012 try { |
| 11985 super.visitTopLevelVariableDeclaration(node); | 12013 super.visitTopLevelVariableDeclaration(node); |
| 11986 } finally { | 12014 } finally { |
| 11987 Map<VariableElement, DartType> overrides = | 12015 Map<VariableElement, DartType> overrides = |
| 11988 _overrideManager.captureOverrides(node.variables); | 12016 _overrideManager.captureOverrides(node.variables); |
| 11989 _overrideManager.exitScope(); | 12017 _overrideManager.exitScope(); |
| 11990 _overrideManager.applyOverrides(overrides); | 12018 _overrideManager.applyOverrides(overrides); |
| 11991 } | 12019 } |
| 11992 return null; | 12020 return null; |
| 11993 } | 12021 } |
| 11994 | 12022 |
| 11995 @override | 12023 @override |
| 11996 Object visitTypeName(TypeName node) => null; | 12024 Object visitTypeName(TypeName node) => null; |
| 11997 | 12025 |
| 11998 @override | 12026 @override |
| 11999 Object visitWhileStatement(WhileStatement node) { | 12027 Object visitWhileStatement(WhileStatement node) { |
| 12000 Expression condition = node.condition; | 12028 Expression condition = node.condition; |
| 12001 safelyVisit(condition); | 12029 safelyVisit(condition); |
| 12002 Statement body = node.body; | 12030 Statement body = node.body; |
| 12003 if (body != null) { | 12031 if (body != null) { |
| 12032 Statement previousUnlabeledBreakTarget = _unlabeledBreakTarget; | |
| 12033 Statement previousUnlabeledContinueTarget = _unlabeledContinueTarget; | |
| 12004 _overrideManager.enterScope(); | 12034 _overrideManager.enterScope(); |
| 12005 try { | 12035 try { |
| 12036 _unlabeledBreakTarget = node; | |
| 12037 _unlabeledContinueTarget = node; | |
| 12006 _propagateTrueState(condition); | 12038 _propagateTrueState(condition); |
| 12007 visitStatementInScope(body); | 12039 visitStatementInScope(body); |
| 12008 } finally { | 12040 } finally { |
| 12009 _overrideManager.exitScope(); | 12041 _overrideManager.exitScope(); |
| 12042 _unlabeledBreakTarget = previousUnlabeledBreakTarget; | |
| 12043 _unlabeledContinueTarget = previousUnlabeledContinueTarget; | |
| 12010 } | 12044 } |
| 12011 } | 12045 } |
| 12012 // TODO(brianwilkerson) If the loop can only be exited because the condition | 12046 // TODO(brianwilkerson) If the loop can only be exited because the condition |
| 12013 // is false, then propagateFalseState(condition); | 12047 // is false, then propagateFalseState(condition); |
| 12014 node.accept(_elementResolver); | 12048 node.accept(_elementResolver); |
| 12015 node.accept(_typeAnalyzer); | 12049 node.accept(_typeAnalyzer); |
| 12016 return null; | 12050 return null; |
| 12017 } | 12051 } |
| 12018 | 12052 |
| 12019 /** | 12053 /** |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12915 VariableElement element = node.element; | 12949 VariableElement element = node.element; |
| 12916 if (element != null) { | 12950 if (element != null) { |
| 12917 _nameScope.define(element); | 12951 _nameScope.define(element); |
| 12918 } | 12952 } |
| 12919 super.visitDeclaredIdentifier(node); | 12953 super.visitDeclaredIdentifier(node); |
| 12920 return null; | 12954 return null; |
| 12921 } | 12955 } |
| 12922 | 12956 |
| 12923 @override | 12957 @override |
| 12924 Object visitDoStatement(DoStatement node) { | 12958 Object visitDoStatement(DoStatement node) { |
| 12925 LabelScope outerLabelScope = _labelScope; | 12959 visitStatementInScope(node.body); |
| 12926 try { | 12960 safelyVisit(node.condition); |
| 12927 _labelScope = new LabelScope.con1(_labelScope, false, false); | |
| 12928 visitStatementInScope(node.body); | |
| 12929 safelyVisit(node.condition); | |
| 12930 } finally { | |
| 12931 _labelScope = outerLabelScope; | |
| 12932 } | |
| 12933 return null; | 12961 return null; |
| 12934 } | 12962 } |
| 12935 | 12963 |
| 12936 @override | 12964 @override |
| 12937 Object visitForEachStatement(ForEachStatement node) { | 12965 Object visitForEachStatement(ForEachStatement node) { |
| 12938 Scope outerNameScope = _nameScope; | 12966 Scope outerNameScope = _nameScope; |
| 12939 LabelScope outerLabelScope = _labelScope; | |
| 12940 try { | 12967 try { |
| 12941 _nameScope = new EnclosedScope(_nameScope); | 12968 _nameScope = new EnclosedScope(_nameScope); |
| 12942 _labelScope = new LabelScope.con1(outerLabelScope, false, false); | |
| 12943 visitForEachStatementInScope(node); | 12969 visitForEachStatementInScope(node); |
| 12944 } finally { | 12970 } finally { |
| 12945 _labelScope = outerLabelScope; | |
| 12946 _nameScope = outerNameScope; | 12971 _nameScope = outerNameScope; |
| 12947 } | 12972 } |
| 12948 return null; | 12973 return null; |
| 12949 } | 12974 } |
| 12950 | 12975 |
| 12951 /** | 12976 /** |
| 12952 * Visit the given statement after it's scope has been created. This replaces the normal call to | 12977 * Visit the given statement after it's scope has been created. This replaces the normal call to |
| 12953 * the inherited visit method so that ResolverVisitor can intervene when type propagation is | 12978 * the inherited visit method so that ResolverVisitor can intervene when type propagation is |
| 12954 * enabled. | 12979 * enabled. |
| 12955 * | 12980 * |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 12976 } | 13001 } |
| 12977 if (_nameScope is FunctionTypeScope) { | 13002 if (_nameScope is FunctionTypeScope) { |
| 12978 (_nameScope as FunctionTypeScope).defineParameters(); | 13003 (_nameScope as FunctionTypeScope).defineParameters(); |
| 12979 } | 13004 } |
| 12980 return null; | 13005 return null; |
| 12981 } | 13006 } |
| 12982 | 13007 |
| 12983 @override | 13008 @override |
| 12984 Object visitForStatement(ForStatement node) { | 13009 Object visitForStatement(ForStatement node) { |
| 12985 Scope outerNameScope = _nameScope; | 13010 Scope outerNameScope = _nameScope; |
| 12986 LabelScope outerLabelScope = _labelScope; | |
| 12987 try { | 13011 try { |
| 12988 _nameScope = new EnclosedScope(_nameScope); | 13012 _nameScope = new EnclosedScope(_nameScope); |
| 12989 _labelScope = new LabelScope.con1(outerLabelScope, false, false); | |
| 12990 visitForStatementInScope(node); | 13013 visitForStatementInScope(node); |
| 12991 } finally { | 13014 } finally { |
| 12992 _labelScope = outerLabelScope; | |
| 12993 _nameScope = outerNameScope; | 13015 _nameScope = outerNameScope; |
| 12994 } | 13016 } |
| 12995 return null; | 13017 return null; |
| 12996 } | 13018 } |
| 12997 | 13019 |
| 12998 /** | 13020 /** |
| 12999 * Visit the given statement after it's scope has been created. This replaces the normal call to | 13021 * Visit the given statement after it's scope has been created. This replaces the normal call to |
| 13000 * the inherited visit method so that ResolverVisitor can intervene when type propagation is | 13022 * the inherited visit method so that ResolverVisitor can intervene when type propagation is |
| 13001 * enabled. | 13023 * enabled. |
| 13002 * | 13024 * |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13085 @override | 13107 @override |
| 13086 Object visitIfStatement(IfStatement node) { | 13108 Object visitIfStatement(IfStatement node) { |
| 13087 safelyVisit(node.condition); | 13109 safelyVisit(node.condition); |
| 13088 visitStatementInScope(node.thenStatement); | 13110 visitStatementInScope(node.thenStatement); |
| 13089 visitStatementInScope(node.elseStatement); | 13111 visitStatementInScope(node.elseStatement); |
| 13090 return null; | 13112 return null; |
| 13091 } | 13113 } |
| 13092 | 13114 |
| 13093 @override | 13115 @override |
| 13094 Object visitLabeledStatement(LabeledStatement node) { | 13116 Object visitLabeledStatement(LabeledStatement node) { |
| 13095 LabelScope outerScope = _addScopesFor(node.labels); | 13117 LabelScope outerScope = _addScopesFor(node.labels, node.unlabeled); |
| 13096 try { | 13118 try { |
| 13097 super.visitLabeledStatement(node); | 13119 super.visitLabeledStatement(node); |
| 13098 } finally { | 13120 } finally { |
| 13099 _labelScope = outerScope; | 13121 _labelScope = outerScope; |
| 13100 } | 13122 } |
| 13101 return null; | 13123 return null; |
| 13102 } | 13124 } |
| 13103 | 13125 |
| 13104 @override | 13126 @override |
| 13105 Object visitMethodDeclaration(MethodDeclaration node) { | 13127 Object visitMethodDeclaration(MethodDeclaration node) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13161 try { | 13183 try { |
| 13162 _nameScope = new EnclosedScope(_nameScope); | 13184 _nameScope = new EnclosedScope(_nameScope); |
| 13163 node.statements.accept(this); | 13185 node.statements.accept(this); |
| 13164 } finally { | 13186 } finally { |
| 13165 _nameScope = outerNameScope; | 13187 _nameScope = outerNameScope; |
| 13166 } | 13188 } |
| 13167 return null; | 13189 return null; |
| 13168 } | 13190 } |
| 13169 | 13191 |
| 13170 @override | 13192 @override |
| 13171 Object visitSwitchStatement(SwitchStatement node) { | 13193 Object visitSwitchStatement(SwitchStatement node) { |
|
Brian Wilkerson
2014/11/24 23:20:53
This change looks wrong to me. The purpose of the
| |
| 13172 LabelScope outerScope = _labelScope; | 13194 for (SwitchMember member in node.members) { |
| 13173 try { | 13195 for (Label label in member.labels) { |
| 13174 _labelScope = new LabelScope.con1(outerScope, true, false); | 13196 SimpleIdentifier labelName = label.label; |
| 13175 for (SwitchMember member in node.members) { | 13197 LabelElement labelElement = labelName.staticElement as LabelElement; |
| 13176 for (Label label in member.labels) { | 13198 _labelScope = |
| 13177 SimpleIdentifier labelName = label.label; | 13199 new LabelScope(_labelScope, labelName.name, member, labelElement); |
| 13178 LabelElement labelElement = labelName.staticElement as LabelElement; | |
| 13179 _labelScope = | |
| 13180 new LabelScope.con2(_labelScope, labelName.name, labelElement); | |
| 13181 } | |
| 13182 } | 13200 } |
| 13183 super.visitSwitchStatement(node); | |
| 13184 } finally { | |
| 13185 _labelScope = outerScope; | |
| 13186 } | 13201 } |
| 13202 super.visitSwitchStatement(node); | |
| 13187 return null; | 13203 return null; |
| 13188 } | 13204 } |
| 13189 | 13205 |
| 13190 @override | 13206 @override |
| 13191 Object visitVariableDeclaration(VariableDeclaration node) { | 13207 Object visitVariableDeclaration(VariableDeclaration node) { |
| 13192 super.visitVariableDeclaration(node); | 13208 super.visitVariableDeclaration(node); |
| 13193 if (node.parent.parent is! TopLevelVariableDeclaration && | 13209 if (node.parent.parent is! TopLevelVariableDeclaration && |
| 13194 node.parent.parent is! FieldDeclaration) { | 13210 node.parent.parent is! FieldDeclaration) { |
| 13195 VariableElement element = node.element; | 13211 VariableElement element = node.element; |
| 13196 if (element != null) { | 13212 if (element != null) { |
| 13197 _nameScope.define(element); | 13213 _nameScope.define(element); |
| 13198 } | 13214 } |
| 13199 } | 13215 } |
| 13200 return null; | 13216 return null; |
| 13201 } | 13217 } |
| 13202 | 13218 |
| 13203 @override | 13219 @override |
| 13204 Object visitWhileStatement(WhileStatement node) { | 13220 Object visitWhileStatement(WhileStatement node) { |
| 13205 LabelScope outerScope = _labelScope; | 13221 safelyVisit(node.condition); |
| 13206 try { | 13222 visitStatementInScope(node.body); |
| 13207 _labelScope = new LabelScope.con1(outerScope, false, false); | |
| 13208 safelyVisit(node.condition); | |
| 13209 visitStatementInScope(node.body); | |
| 13210 } finally { | |
| 13211 _labelScope = outerScope; | |
| 13212 } | |
| 13213 return null; | 13223 return null; |
| 13214 } | 13224 } |
| 13215 | 13225 |
| 13216 /** | 13226 /** |
| 13217 * Add scopes for each of the given labels. | 13227 * Add scopes for each of the given labels. |
| 13218 * | 13228 * |
| 13219 * @param labels the labels for which new scopes are to be added | 13229 * @param labels the labels for which new scopes are to be added |
| 13220 * @return the scope that was in effect before the new scopes were added | 13230 * @return the scope that was in effect before the new scopes were added |
| 13221 */ | 13231 */ |
| 13222 LabelScope _addScopesFor(NodeList<Label> labels) { | 13232 LabelScope _addScopesFor(NodeList<Label> labels, AstNode node) { |
| 13223 LabelScope outerScope = _labelScope; | 13233 LabelScope outerScope = _labelScope; |
| 13224 for (Label label in labels) { | 13234 for (Label label in labels) { |
| 13225 SimpleIdentifier labelNameNode = label.label; | 13235 SimpleIdentifier labelNameNode = label.label; |
| 13226 String labelName = labelNameNode.name; | 13236 String labelName = labelNameNode.name; |
| 13227 LabelElement labelElement = labelNameNode.staticElement as LabelElement; | 13237 LabelElement labelElement = labelNameNode.staticElement as LabelElement; |
| 13228 _labelScope = new LabelScope.con2(_labelScope, labelName, labelElement); | 13238 _labelScope = new LabelScope(_labelScope, labelName, node, labelElement); |
| 13229 } | 13239 } |
| 13230 return outerScope; | 13240 return outerScope; |
| 13231 } | 13241 } |
| 13232 | 13242 |
| 13233 /** | 13243 /** |
| 13234 * Marks the local declarations of the given [Block] hidden in the enclosing s cope. | 13244 * Marks the local declarations of the given [Block] hidden in the enclosing s cope. |
| 13235 * According to the scoping rules name is hidden if block defines it, but name is defined after | 13245 * According to the scoping rules name is hidden if block defines it, but name is defined after |
| 13236 * its declaration statement. | 13246 * its declaration statement. |
| 13237 */ | 13247 */ |
| 13238 void _hideNamesDefinedInBlock(EnclosedScope scope, Block block) { | 13248 void _hideNamesDefinedInBlock(EnclosedScope scope, Block block) { |
| (...skipping 2971 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 16210 * library. | 16220 * library. |
| 16211 */ | 16221 */ |
| 16212 final HashSet<String> members = new HashSet<String>(); | 16222 final HashSet<String> members = new HashSet<String>(); |
| 16213 | 16223 |
| 16214 /** | 16224 /** |
| 16215 * Names of resolved or unresolved class members that are read in the | 16225 * Names of resolved or unresolved class members that are read in the |
| 16216 * library. | 16226 * library. |
| 16217 */ | 16227 */ |
| 16218 final HashSet<String> readMembers = new HashSet<String>(); | 16228 final HashSet<String> readMembers = new HashSet<String>(); |
| 16219 } | 16229 } |
| OLD | NEW |