| 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 'package:analyzer/src/generated/utilities_collection.dart'; | 10 import 'package:analyzer/src/generated/utilities_collection.dart'; |
| (...skipping 10069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10080 */ | 10080 */ |
| 10081 class ResolverVisitor extends ScopedVisitor { | 10081 class ResolverVisitor extends ScopedVisitor { |
| 10082 /** | 10082 /** |
| 10083 * The manager for the inheritance mappings. | 10083 * The manager for the inheritance mappings. |
| 10084 */ | 10084 */ |
| 10085 InheritanceManager _inheritanceManager; | 10085 InheritanceManager _inheritanceManager; |
| 10086 | 10086 |
| 10087 /** | 10087 /** |
| 10088 * The object used to resolve the element associated with the current node. | 10088 * The object used to resolve the element associated with the current node. |
| 10089 */ | 10089 */ |
| 10090 ElementResolver _elementResolver; | 10090 ElementResolver elementResolver; |
| 10091 | 10091 |
| 10092 /** | 10092 /** |
| 10093 * The object used to compute the type associated with the current node. | 10093 * The object used to compute the type associated with the current node. |
| 10094 */ | 10094 */ |
| 10095 StaticTypeAnalyzer _typeAnalyzer; | 10095 StaticTypeAnalyzer typeAnalyzer; |
| 10096 | 10096 |
| 10097 /** | 10097 /** |
| 10098 * The class element representing the class containing the current node, | 10098 * The class element representing the class containing the current node, |
| 10099 * or `null` if the current node is not contained in a class. | 10099 * or `null` if the current node is not contained in a class. |
| 10100 */ | 10100 */ |
| 10101 ClassElement enclosingClass = null; | 10101 ClassElement enclosingClass = null; |
| 10102 | 10102 |
| 10103 /** | 10103 /** |
| 10104 * The class declaration representing the class containing the current node, o
r `null` if | 10104 * The class declaration representing the class containing the current node, o
r `null` if |
| 10105 * the current node is not contained in a class. | 10105 * the current node is not contained in a class. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10150 * @param library the library containing the compilation unit being resolved | 10150 * @param library the library containing the compilation unit being resolved |
| 10151 * @param source the source representing the compilation unit being visited | 10151 * @param source the source representing the compilation unit being visited |
| 10152 * @param typeProvider the object used to access the types from the core libra
ry | 10152 * @param typeProvider the object used to access the types from the core libra
ry |
| 10153 */ | 10153 */ |
| 10154 ResolverVisitor.con1( | 10154 ResolverVisitor.con1( |
| 10155 Library library, Source source, TypeProvider typeProvider, | 10155 Library library, Source source, TypeProvider typeProvider, |
| 10156 {StaticTypeAnalyzer typeAnalyzer, | 10156 {StaticTypeAnalyzer typeAnalyzer, |
| 10157 StaticTypeAnalyzerFactory typeAnalyzerFactory}) | 10157 StaticTypeAnalyzerFactory typeAnalyzerFactory}) |
| 10158 : super.con1(library, source, typeProvider) { | 10158 : super.con1(library, source, typeProvider) { |
| 10159 this._inheritanceManager = library.inheritanceManager; | 10159 this._inheritanceManager = library.inheritanceManager; |
| 10160 this._elementResolver = new ElementResolver(this); | 10160 this.elementResolver = new ElementResolver(this); |
| 10161 this._typeAnalyzer = typeAnalyzer != null | 10161 this.typeAnalyzer = typeAnalyzer != null |
| 10162 ? typeAnalyzer | 10162 ? typeAnalyzer |
| 10163 : (typeAnalyzerFactory != null | 10163 : (typeAnalyzerFactory != null |
| 10164 ? typeAnalyzerFactory(this) | 10164 ? typeAnalyzerFactory(this) |
| 10165 : new StaticTypeAnalyzer(this)); | 10165 : new StaticTypeAnalyzer(this)); |
| 10166 } | 10166 } |
| 10167 | 10167 |
| 10168 /** | 10168 /** |
| 10169 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 10169 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 10170 * | 10170 * |
| 10171 * @param definingLibrary the element for the library containing the compilati
on unit being | 10171 * @param definingLibrary the element for the library containing the compilati
on unit being |
| 10172 * visited | 10172 * visited |
| 10173 * @param source the source representing the compilation unit being visited | 10173 * @param source the source representing the compilation unit being visited |
| 10174 * @param typeProvider the object used to access the types from the core libra
ry | 10174 * @param typeProvider the object used to access the types from the core libra
ry |
| 10175 * @param errorListener the error listener that will be informed of any errors
that are found | 10175 * @param errorListener the error listener that will be informed of any errors
that are found |
| 10176 * during resolution | 10176 * during resolution |
| 10177 */ | 10177 */ |
| 10178 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, | 10178 ResolverVisitor.con2(LibraryElement definingLibrary, Source source, |
| 10179 TypeProvider typeProvider, InheritanceManager inheritanceManager, | 10179 TypeProvider typeProvider, InheritanceManager inheritanceManager, |
| 10180 AnalysisErrorListener errorListener) | 10180 AnalysisErrorListener errorListener) |
| 10181 : super.con2(definingLibrary, source, typeProvider, errorListener) { | 10181 : super.con2(definingLibrary, source, typeProvider, errorListener) { |
| 10182 this._inheritanceManager = inheritanceManager; | 10182 this._inheritanceManager = inheritanceManager; |
| 10183 this._elementResolver = new ElementResolver(this); | 10183 this.elementResolver = new ElementResolver(this); |
| 10184 this._typeAnalyzer = new StaticTypeAnalyzer(this); | 10184 this.typeAnalyzer = new StaticTypeAnalyzer(this); |
| 10185 } | 10185 } |
| 10186 | 10186 |
| 10187 /** | 10187 /** |
| 10188 * Initialize a newly created visitor to resolve the nodes in an AST node. | 10188 * Initialize a newly created visitor to resolve the nodes in an AST node. |
| 10189 * | 10189 * |
| 10190 * @param definingLibrary the element for the library containing the node bein
g visited | 10190 * @param definingLibrary the element for the library containing the node bein
g visited |
| 10191 * @param source the source representing the compilation unit containing the n
ode being visited | 10191 * @param source the source representing the compilation unit containing the n
ode being visited |
| 10192 * @param typeProvider the object used to access the types from the core libra
ry | 10192 * @param typeProvider the object used to access the types from the core libra
ry |
| 10193 * @param nameScope the scope used to resolve identifiers in the node that wil
l first be visited | 10193 * @param nameScope the scope used to resolve identifiers in the node that wil
l first be visited |
| 10194 * @param errorListener the error listener that will be informed of any errors
that are found | 10194 * @param errorListener the error listener that will be informed of any errors
that are found |
| 10195 * during resolution | 10195 * during resolution |
| 10196 */ | 10196 */ |
| 10197 ResolverVisitor.con3(LibraryElement definingLibrary, Source source, | 10197 ResolverVisitor.con3(LibraryElement definingLibrary, Source source, |
| 10198 TypeProvider typeProvider, Scope nameScope, | 10198 TypeProvider typeProvider, Scope nameScope, |
| 10199 AnalysisErrorListener errorListener) | 10199 AnalysisErrorListener errorListener) |
| 10200 : super.con3( | 10200 : super.con3( |
| 10201 definingLibrary, source, typeProvider, nameScope, errorListener) { | 10201 definingLibrary, source, typeProvider, nameScope, errorListener) { |
| 10202 this._inheritanceManager = new InheritanceManager(definingLibrary); | 10202 this._inheritanceManager = new InheritanceManager(definingLibrary); |
| 10203 this._elementResolver = new ElementResolver(this); | 10203 this.elementResolver = new ElementResolver(this); |
| 10204 this._typeAnalyzer = new StaticTypeAnalyzer(this); | 10204 this.typeAnalyzer = new StaticTypeAnalyzer(this); |
| 10205 } | 10205 } |
| 10206 | 10206 |
| 10207 /** | 10207 /** |
| 10208 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 10208 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 10209 * | 10209 * |
| 10210 * @param library the library containing the compilation unit being resolved | 10210 * @param library the library containing the compilation unit being resolved |
| 10211 * @param source the source representing the compilation unit being visited | 10211 * @param source the source representing the compilation unit being visited |
| 10212 * @param typeProvider the object used to access the types from the core libra
ry | 10212 * @param typeProvider the object used to access the types from the core libra
ry |
| 10213 */ | 10213 */ |
| 10214 ResolverVisitor.con4( | 10214 ResolverVisitor.con4( |
| 10215 ResolvableLibrary library, Source source, TypeProvider typeProvider) | 10215 ResolvableLibrary library, Source source, TypeProvider typeProvider) |
| 10216 : super.con4(library, source, typeProvider) { | 10216 : super.con4(library, source, typeProvider) { |
| 10217 this._inheritanceManager = library.inheritanceManager; | 10217 this._inheritanceManager = library.inheritanceManager; |
| 10218 this._elementResolver = new ElementResolver(this); | 10218 this.elementResolver = new ElementResolver(this); |
| 10219 this._typeAnalyzer = new StaticTypeAnalyzer(this); | 10219 this.typeAnalyzer = new StaticTypeAnalyzer(this); |
| 10220 } | 10220 } |
| 10221 | 10221 |
| 10222 get elementResolver_J2DAccessor => _elementResolver; | |
| 10223 | |
| 10224 set elementResolver_J2DAccessor(__v) => _elementResolver = __v; | |
| 10225 | |
| 10226 /** | 10222 /** |
| 10227 * Return the element representing the function containing the current node, o
r `null` if | 10223 * Return the element representing the function containing the current node, o
r `null` if |
| 10228 * the current node is not contained in a function. | 10224 * the current node is not contained in a function. |
| 10229 * | 10225 * |
| 10230 * @return the element representing the function containing the current node | 10226 * @return the element representing the function containing the current node |
| 10231 */ | 10227 */ |
| 10232 ExecutableElement get enclosingFunction => _enclosingFunction; | 10228 ExecutableElement get enclosingFunction => _enclosingFunction; |
| 10233 | 10229 |
| 10234 get labelScope_J2DAccessor => _labelScope; | |
| 10235 | |
| 10236 set labelScope_J2DAccessor(__v) => _labelScope = __v; | |
| 10237 | |
| 10238 get nameScope_J2DAccessor => _nameScope; | |
| 10239 | |
| 10240 set nameScope_J2DAccessor(__v) => _nameScope = __v; | |
| 10241 | |
| 10242 /** | 10230 /** |
| 10243 * Return the object keeping track of which elements have had their types over
ridden. | 10231 * Return the object keeping track of which elements have had their types over
ridden. |
| 10244 * | 10232 * |
| 10245 * @return the object keeping track of which elements have had their types ove
rridden | 10233 * @return the object keeping track of which elements have had their types ove
rridden |
| 10246 */ | 10234 */ |
| 10247 TypeOverrideManager get overrideManager => _overrideManager; | 10235 TypeOverrideManager get overrideManager => _overrideManager; |
| 10248 | 10236 |
| 10249 /** | 10237 /** |
| 10250 * Return the object keeping track of which elements have had their types prom
oted. | 10238 * Return the object keeping track of which elements have had their types prom
oted. |
| 10251 * | 10239 * |
| 10252 * @return the object keeping track of which elements have had their types pro
moted | 10240 * @return the object keeping track of which elements have had their types pro
moted |
| 10253 */ | 10241 */ |
| 10254 TypePromotionManager get promoteManager => _promoteManager; | 10242 TypePromotionManager get promoteManager => _promoteManager; |
| 10255 | 10243 |
| 10256 get typeAnalyzer_J2DAccessor => _typeAnalyzer; | |
| 10257 | |
| 10258 set typeAnalyzer_J2DAccessor(__v) => _typeAnalyzer = __v; | |
| 10259 | |
| 10260 /** | 10244 /** |
| 10261 * Return the propagated element associated with the given expression whose ty
pe can be | 10245 * Return the propagated element associated with the given expression whose ty
pe can be |
| 10262 * overridden, or `null` if there is no element whose type can be overridden. | 10246 * overridden, or `null` if there is no element whose type can be overridden. |
| 10263 * | 10247 * |
| 10264 * @param expression the expression with which the element is associated | 10248 * @param expression the expression with which the element is associated |
| 10265 * @return the element associated with the given expression | 10249 * @return the element associated with the given expression |
| 10266 */ | 10250 */ |
| 10267 VariableElement getOverridablePropagatedElement(Expression expression) { | 10251 VariableElement getOverridablePropagatedElement(Expression expression) { |
| 10268 Element element = null; | 10252 Element element = null; |
| 10269 if (expression is SimpleIdentifier) { | 10253 if (expression is SimpleIdentifier) { |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10481 _propagateFalseState(leftOperand); | 10465 _propagateFalseState(leftOperand); |
| 10482 rightOperand.accept(this); | 10466 rightOperand.accept(this); |
| 10483 } finally { | 10467 } finally { |
| 10484 _overrideManager.exitScope(); | 10468 _overrideManager.exitScope(); |
| 10485 } | 10469 } |
| 10486 } | 10470 } |
| 10487 } else { | 10471 } else { |
| 10488 safelyVisit(leftOperand); | 10472 safelyVisit(leftOperand); |
| 10489 safelyVisit(rightOperand); | 10473 safelyVisit(rightOperand); |
| 10490 } | 10474 } |
| 10491 node.accept(_elementResolver); | 10475 node.accept(elementResolver); |
| 10492 node.accept(_typeAnalyzer); | 10476 node.accept(typeAnalyzer); |
| 10493 return null; | 10477 return null; |
| 10494 } | 10478 } |
| 10495 | 10479 |
| 10496 @override | 10480 @override |
| 10497 Object visitBlockFunctionBody(BlockFunctionBody node) { | 10481 Object visitBlockFunctionBody(BlockFunctionBody node) { |
| 10498 safelyVisit(_commentBeforeFunction); | 10482 safelyVisit(_commentBeforeFunction); |
| 10499 _overrideManager.enterScope(); | 10483 _overrideManager.enterScope(); |
| 10500 try { | 10484 try { |
| 10501 super.visitBlockFunctionBody(node); | 10485 super.visitBlockFunctionBody(node); |
| 10502 } finally { | 10486 } finally { |
| 10503 _overrideManager.exitScope(); | 10487 _overrideManager.exitScope(); |
| 10504 } | 10488 } |
| 10505 return null; | 10489 return null; |
| 10506 } | 10490 } |
| 10507 | 10491 |
| 10508 @override | 10492 @override |
| 10509 Object visitBreakStatement(BreakStatement node) { | 10493 Object visitBreakStatement(BreakStatement node) { |
| 10510 // | 10494 // |
| 10511 // We do not visit the label because it needs to be visited in the context | 10495 // We do not visit the label because it needs to be visited in the context |
| 10512 // of the statement. | 10496 // of the statement. |
| 10513 // | 10497 // |
| 10514 node.accept(_elementResolver); | 10498 node.accept(elementResolver); |
| 10515 node.accept(_typeAnalyzer); | 10499 node.accept(typeAnalyzer); |
| 10516 return null; | 10500 return null; |
| 10517 } | 10501 } |
| 10518 | 10502 |
| 10519 @override | 10503 @override |
| 10520 Object visitClassDeclaration(ClassDeclaration node) { | 10504 Object visitClassDeclaration(ClassDeclaration node) { |
| 10521 // | 10505 // |
| 10522 // Resolve the metadata in the library scope. | 10506 // Resolve the metadata in the library scope. |
| 10523 // | 10507 // |
| 10524 if (node.metadata != null) { | 10508 if (node.metadata != null) { |
| 10525 node.metadata.accept(this); | 10509 node.metadata.accept(this); |
| 10526 } | 10510 } |
| 10527 _enclosingClassDeclaration = node; | 10511 _enclosingClassDeclaration = node; |
| 10528 // | 10512 // |
| 10529 // Continue the class resolution. | 10513 // Continue the class resolution. |
| 10530 // | 10514 // |
| 10531 ClassElement outerType = enclosingClass; | 10515 ClassElement outerType = enclosingClass; |
| 10532 try { | 10516 try { |
| 10533 enclosingClass = node.element; | 10517 enclosingClass = node.element; |
| 10534 _typeAnalyzer.thisType = | 10518 typeAnalyzer.thisType = |
| 10535 enclosingClass == null ? null : enclosingClass.type; | 10519 enclosingClass == null ? null : enclosingClass.type; |
| 10536 super.visitClassDeclaration(node); | 10520 super.visitClassDeclaration(node); |
| 10537 node.accept(_elementResolver); | 10521 node.accept(elementResolver); |
| 10538 node.accept(_typeAnalyzer); | 10522 node.accept(typeAnalyzer); |
| 10539 } finally { | 10523 } finally { |
| 10540 _typeAnalyzer.thisType = outerType == null ? null : outerType.type; | 10524 typeAnalyzer.thisType = outerType == null ? null : outerType.type; |
| 10541 enclosingClass = outerType; | 10525 enclosingClass = outerType; |
| 10542 _enclosingClassDeclaration = null; | 10526 _enclosingClassDeclaration = null; |
| 10543 } | 10527 } |
| 10544 return null; | 10528 return null; |
| 10545 } | 10529 } |
| 10546 | 10530 |
| 10547 /** | 10531 /** |
| 10548 * Implementation of this method should be synchronized with | 10532 * Implementation of this method should be synchronized with |
| 10549 * [visitClassDeclaration]. | 10533 * [visitClassDeclaration]. |
| 10550 */ | 10534 */ |
| 10551 visitClassDeclarationIncrementally(ClassDeclaration node) { | 10535 visitClassDeclarationIncrementally(ClassDeclaration node) { |
| 10552 // | 10536 // |
| 10553 // Resolve the metadata in the library scope. | 10537 // Resolve the metadata in the library scope. |
| 10554 // | 10538 // |
| 10555 if (node.metadata != null) { | 10539 if (node.metadata != null) { |
| 10556 node.metadata.accept(this); | 10540 node.metadata.accept(this); |
| 10557 } | 10541 } |
| 10558 _enclosingClassDeclaration = node; | 10542 _enclosingClassDeclaration = node; |
| 10559 // | 10543 // |
| 10560 // Continue the class resolution. | 10544 // Continue the class resolution. |
| 10561 // | 10545 // |
| 10562 enclosingClass = node.element; | 10546 enclosingClass = node.element; |
| 10563 _typeAnalyzer.thisType = | 10547 typeAnalyzer.thisType = enclosingClass == null ? null : enclosingClass.type; |
| 10564 enclosingClass == null ? null : enclosingClass.type; | 10548 node.accept(elementResolver); |
| 10565 node.accept(_elementResolver); | 10549 node.accept(typeAnalyzer); |
| 10566 node.accept(_typeAnalyzer); | |
| 10567 } | 10550 } |
| 10568 | 10551 |
| 10569 @override | 10552 @override |
| 10570 Object visitComment(Comment node) { | 10553 Object visitComment(Comment node) { |
| 10571 if (node.parent is FunctionDeclaration || | 10554 if (node.parent is FunctionDeclaration || |
| 10572 node.parent is ConstructorDeclaration || | 10555 node.parent is ConstructorDeclaration || |
| 10573 node.parent is MethodDeclaration) { | 10556 node.parent is MethodDeclaration) { |
| 10574 if (!identical(node, _commentBeforeFunction)) { | 10557 if (!identical(node, _commentBeforeFunction)) { |
| 10575 _commentBeforeFunction = node; | 10558 _commentBeforeFunction = node; |
| 10576 return null; | 10559 return null; |
| 10577 } | 10560 } |
| 10578 } | 10561 } |
| 10579 super.visitComment(node); | 10562 super.visitComment(node); |
| 10580 _commentBeforeFunction = null; | 10563 _commentBeforeFunction = null; |
| 10581 return null; | 10564 return null; |
| 10582 } | 10565 } |
| 10583 | 10566 |
| 10584 @override | 10567 @override |
| 10585 Object visitCommentReference(CommentReference node) { | 10568 Object visitCommentReference(CommentReference node) { |
| 10586 // | 10569 // |
| 10587 // We do not visit the identifier because it needs to be visited in the | 10570 // We do not visit the identifier because it needs to be visited in the |
| 10588 // context of the reference. | 10571 // context of the reference. |
| 10589 // | 10572 // |
| 10590 node.accept(_elementResolver); | 10573 node.accept(elementResolver); |
| 10591 node.accept(_typeAnalyzer); | 10574 node.accept(typeAnalyzer); |
| 10592 return null; | 10575 return null; |
| 10593 } | 10576 } |
| 10594 | 10577 |
| 10595 @override | 10578 @override |
| 10596 Object visitCompilationUnit(CompilationUnit node) { | 10579 Object visitCompilationUnit(CompilationUnit node) { |
| 10597 // | 10580 // |
| 10598 // TODO(brianwilkerson) The goal of the code below is to visit the | 10581 // TODO(brianwilkerson) The goal of the code below is to visit the |
| 10599 // declarations in such an order that we can infer type information for | 10582 // declarations in such an order that we can infer type information for |
| 10600 // top-level variables before we visit references to them. This is better | 10583 // top-level variables before we visit references to them. This is better |
| 10601 // than making no effort, but still doesn't completely satisfy that goal | 10584 // than making no effort, but still doesn't completely satisfy that goal |
| (...skipping 19 matching lines...) Expand all Loading... |
| 10621 } | 10604 } |
| 10622 for (int i = 0; i < declarationCount; i++) { | 10605 for (int i = 0; i < declarationCount; i++) { |
| 10623 CompilationUnitMember declaration = declarations[i]; | 10606 CompilationUnitMember declaration = declarations[i]; |
| 10624 if (declaration is ClassDeclaration) { | 10607 if (declaration is ClassDeclaration) { |
| 10625 declaration.accept(this); | 10608 declaration.accept(this); |
| 10626 } | 10609 } |
| 10627 } | 10610 } |
| 10628 } finally { | 10611 } finally { |
| 10629 _overrideManager.exitScope(); | 10612 _overrideManager.exitScope(); |
| 10630 } | 10613 } |
| 10631 node.accept(_elementResolver); | 10614 node.accept(elementResolver); |
| 10632 node.accept(_typeAnalyzer); | 10615 node.accept(typeAnalyzer); |
| 10633 return null; | 10616 return null; |
| 10634 } | 10617 } |
| 10635 | 10618 |
| 10636 @override | 10619 @override |
| 10637 Object visitConditionalExpression(ConditionalExpression node) { | 10620 Object visitConditionalExpression(ConditionalExpression node) { |
| 10638 Expression condition = node.condition; | 10621 Expression condition = node.condition; |
| 10639 safelyVisit(condition); | 10622 safelyVisit(condition); |
| 10640 Expression thenExpression = node.thenExpression; | 10623 Expression thenExpression = node.thenExpression; |
| 10641 if (thenExpression != null) { | 10624 if (thenExpression != null) { |
| 10642 _overrideManager.enterScope(); | 10625 _overrideManager.enterScope(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 10661 Expression elseExpression = node.elseExpression; | 10644 Expression elseExpression = node.elseExpression; |
| 10662 if (elseExpression != null) { | 10645 if (elseExpression != null) { |
| 10663 _overrideManager.enterScope(); | 10646 _overrideManager.enterScope(); |
| 10664 try { | 10647 try { |
| 10665 _propagateFalseState(condition); | 10648 _propagateFalseState(condition); |
| 10666 elseExpression.accept(this); | 10649 elseExpression.accept(this); |
| 10667 } finally { | 10650 } finally { |
| 10668 _overrideManager.exitScope(); | 10651 _overrideManager.exitScope(); |
| 10669 } | 10652 } |
| 10670 } | 10653 } |
| 10671 node.accept(_elementResolver); | 10654 node.accept(elementResolver); |
| 10672 node.accept(_typeAnalyzer); | 10655 node.accept(typeAnalyzer); |
| 10673 bool thenIsAbrupt = _isAbruptTerminationExpression(thenExpression); | 10656 bool thenIsAbrupt = _isAbruptTerminationExpression(thenExpression); |
| 10674 bool elseIsAbrupt = _isAbruptTerminationExpression(elseExpression); | 10657 bool elseIsAbrupt = _isAbruptTerminationExpression(elseExpression); |
| 10675 if (elseIsAbrupt && !thenIsAbrupt) { | 10658 if (elseIsAbrupt && !thenIsAbrupt) { |
| 10676 _propagateTrueState(condition); | 10659 _propagateTrueState(condition); |
| 10677 _propagateState(thenExpression); | 10660 _propagateState(thenExpression); |
| 10678 } else if (thenIsAbrupt && !elseIsAbrupt) { | 10661 } else if (thenIsAbrupt && !elseIsAbrupt) { |
| 10679 _propagateFalseState(condition); | 10662 _propagateFalseState(condition); |
| 10680 _propagateState(elseExpression); | 10663 _propagateState(elseExpression); |
| 10681 } | 10664 } |
| 10682 return null; | 10665 return null; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 10694 return null; | 10677 return null; |
| 10695 } | 10678 } |
| 10696 | 10679 |
| 10697 @override | 10680 @override |
| 10698 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { | 10681 Object visitConstructorFieldInitializer(ConstructorFieldInitializer node) { |
| 10699 // | 10682 // |
| 10700 // We visit the expression, but do not visit the field name because it needs | 10683 // We visit the expression, but do not visit the field name because it needs |
| 10701 // to be visited in the context of the constructor field initializer node. | 10684 // to be visited in the context of the constructor field initializer node. |
| 10702 // | 10685 // |
| 10703 safelyVisit(node.expression); | 10686 safelyVisit(node.expression); |
| 10704 node.accept(_elementResolver); | 10687 node.accept(elementResolver); |
| 10705 node.accept(_typeAnalyzer); | 10688 node.accept(typeAnalyzer); |
| 10706 return null; | 10689 return null; |
| 10707 } | 10690 } |
| 10708 | 10691 |
| 10709 @override | 10692 @override |
| 10710 Object visitConstructorName(ConstructorName node) { | 10693 Object visitConstructorName(ConstructorName node) { |
| 10711 // | 10694 // |
| 10712 // We do not visit either the type name, because it won't be visited anyway, | 10695 // We do not visit either the type name, because it won't be visited anyway, |
| 10713 // or the name, because it needs to be visited in the context of the | 10696 // or the name, because it needs to be visited in the context of the |
| 10714 // constructor name. | 10697 // constructor name. |
| 10715 // | 10698 // |
| 10716 node.accept(_elementResolver); | 10699 node.accept(elementResolver); |
| 10717 node.accept(_typeAnalyzer); | 10700 node.accept(typeAnalyzer); |
| 10718 return null; | 10701 return null; |
| 10719 } | 10702 } |
| 10720 | 10703 |
| 10721 @override | 10704 @override |
| 10722 Object visitContinueStatement(ContinueStatement node) { | 10705 Object visitContinueStatement(ContinueStatement node) { |
| 10723 // | 10706 // |
| 10724 // We do not visit the label because it needs to be visited in the context | 10707 // We do not visit the label because it needs to be visited in the context |
| 10725 // of the statement. | 10708 // of the statement. |
| 10726 // | 10709 // |
| 10727 node.accept(_elementResolver); | 10710 node.accept(elementResolver); |
| 10728 node.accept(_typeAnalyzer); | 10711 node.accept(typeAnalyzer); |
| 10729 return null; | 10712 return null; |
| 10730 } | 10713 } |
| 10731 | 10714 |
| 10732 @override | 10715 @override |
| 10733 Object visitDoStatement(DoStatement node) { | 10716 Object visitDoStatement(DoStatement node) { |
| 10734 _overrideManager.enterScope(); | 10717 _overrideManager.enterScope(); |
| 10735 try { | 10718 try { |
| 10736 super.visitDoStatement(node); | 10719 super.visitDoStatement(node); |
| 10737 } finally { | 10720 } finally { |
| 10738 _overrideManager.exitScope(); | 10721 _overrideManager.exitScope(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10835 DartType iteratorElementType = _getIteratorElementType(iterable); | 10818 DartType iteratorElementType = _getIteratorElementType(iterable); |
| 10836 overrideVariable(identifierElement, iteratorElementType, true); | 10819 overrideVariable(identifierElement, iteratorElementType, true); |
| 10837 _recordPropagatedType(identifier, iteratorElementType); | 10820 _recordPropagatedType(identifier, iteratorElementType); |
| 10838 } | 10821 } |
| 10839 } | 10822 } |
| 10840 visitStatementInScope(body); | 10823 visitStatementInScope(body); |
| 10841 } finally { | 10824 } finally { |
| 10842 _overrideManager.exitScope(); | 10825 _overrideManager.exitScope(); |
| 10843 } | 10826 } |
| 10844 } | 10827 } |
| 10845 node.accept(_elementResolver); | 10828 node.accept(elementResolver); |
| 10846 node.accept(_typeAnalyzer); | 10829 node.accept(typeAnalyzer); |
| 10847 } | 10830 } |
| 10848 | 10831 |
| 10849 @override | 10832 @override |
| 10850 Object visitForStatement(ForStatement node) { | 10833 Object visitForStatement(ForStatement node) { |
| 10851 _overrideManager.enterScope(); | 10834 _overrideManager.enterScope(); |
| 10852 try { | 10835 try { |
| 10853 super.visitForStatement(node); | 10836 super.visitForStatement(node); |
| 10854 } finally { | 10837 } finally { |
| 10855 _overrideManager.exitScope(); | 10838 _overrideManager.exitScope(); |
| 10856 } | 10839 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10900 } | 10883 } |
| 10901 } finally { | 10884 } finally { |
| 10902 _enclosingFunction = outerFunction; | 10885 _enclosingFunction = outerFunction; |
| 10903 } | 10886 } |
| 10904 return null; | 10887 return null; |
| 10905 } | 10888 } |
| 10906 | 10889 |
| 10907 @override | 10890 @override |
| 10908 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 10891 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 10909 safelyVisit(node.function); | 10892 safelyVisit(node.function); |
| 10910 node.accept(_elementResolver); | 10893 node.accept(elementResolver); |
| 10911 _inferFunctionExpressionsParametersTypes(node.argumentList); | 10894 _inferFunctionExpressionsParametersTypes(node.argumentList); |
| 10912 safelyVisit(node.argumentList); | 10895 safelyVisit(node.argumentList); |
| 10913 node.accept(_typeAnalyzer); | 10896 node.accept(typeAnalyzer); |
| 10914 return null; | 10897 return null; |
| 10915 } | 10898 } |
| 10916 | 10899 |
| 10917 @override | 10900 @override |
| 10918 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 10901 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 10919 // Resolve the metadata in the library scope. | 10902 // Resolve the metadata in the library scope. |
| 10920 if (node.metadata != null) { | 10903 if (node.metadata != null) { |
| 10921 node.metadata.accept(this); | 10904 node.metadata.accept(this); |
| 10922 } | 10905 } |
| 10923 FunctionTypeAlias outerAlias = _enclosingFunctionTypeAlias; | 10906 FunctionTypeAlias outerAlias = _enclosingFunctionTypeAlias; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10967 if (elseStatement != null) { | 10950 if (elseStatement != null) { |
| 10968 _overrideManager.enterScope(); | 10951 _overrideManager.enterScope(); |
| 10969 try { | 10952 try { |
| 10970 _propagateFalseState(condition); | 10953 _propagateFalseState(condition); |
| 10971 visitStatementInScope(elseStatement); | 10954 visitStatementInScope(elseStatement); |
| 10972 } finally { | 10955 } finally { |
| 10973 elseOverrides = _overrideManager.captureLocalOverrides(); | 10956 elseOverrides = _overrideManager.captureLocalOverrides(); |
| 10974 _overrideManager.exitScope(); | 10957 _overrideManager.exitScope(); |
| 10975 } | 10958 } |
| 10976 } | 10959 } |
| 10977 node.accept(_elementResolver); | 10960 node.accept(elementResolver); |
| 10978 node.accept(_typeAnalyzer); | 10961 node.accept(typeAnalyzer); |
| 10979 // Join overrides. | 10962 // Join overrides. |
| 10980 bool thenIsAbrupt = _isAbruptTerminationStatement(thenStatement); | 10963 bool thenIsAbrupt = _isAbruptTerminationStatement(thenStatement); |
| 10981 bool elseIsAbrupt = _isAbruptTerminationStatement(elseStatement); | 10964 bool elseIsAbrupt = _isAbruptTerminationStatement(elseStatement); |
| 10982 if (elseIsAbrupt && !thenIsAbrupt) { | 10965 if (elseIsAbrupt && !thenIsAbrupt) { |
| 10983 _propagateTrueState(condition); | 10966 _propagateTrueState(condition); |
| 10984 _overrideManager.applyOverrides(thenOverrides); | 10967 _overrideManager.applyOverrides(thenOverrides); |
| 10985 } else if (thenIsAbrupt && !elseIsAbrupt) { | 10968 } else if (thenIsAbrupt && !elseIsAbrupt) { |
| 10986 _propagateFalseState(condition); | 10969 _propagateFalseState(condition); |
| 10987 _overrideManager.applyOverrides(elseOverrides); | 10970 _overrideManager.applyOverrides(elseOverrides); |
| 10988 } else if (!thenIsAbrupt && !elseIsAbrupt) { | 10971 } else if (!thenIsAbrupt && !elseIsAbrupt) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 11015 return null; | 10998 return null; |
| 11016 } | 10999 } |
| 11017 | 11000 |
| 11018 @override | 11001 @override |
| 11019 Object visitMethodInvocation(MethodInvocation node) { | 11002 Object visitMethodInvocation(MethodInvocation node) { |
| 11020 // | 11003 // |
| 11021 // We visit the target and argument list, but do not visit the method name | 11004 // We visit the target and argument list, but do not visit the method name |
| 11022 // because it needs to be visited in the context of the invocation. | 11005 // because it needs to be visited in the context of the invocation. |
| 11023 // | 11006 // |
| 11024 safelyVisit(node.target); | 11007 safelyVisit(node.target); |
| 11025 node.accept(_elementResolver); | 11008 node.accept(elementResolver); |
| 11026 _inferFunctionExpressionsParametersTypes(node.argumentList); | 11009 _inferFunctionExpressionsParametersTypes(node.argumentList); |
| 11027 safelyVisit(node.argumentList); | 11010 safelyVisit(node.argumentList); |
| 11028 node.accept(_typeAnalyzer); | 11011 node.accept(typeAnalyzer); |
| 11029 return null; | 11012 return null; |
| 11030 } | 11013 } |
| 11031 | 11014 |
| 11032 @override | 11015 @override |
| 11033 Object visitNode(AstNode node) { | 11016 Object visitNode(AstNode node) { |
| 11034 node.visitChildren(this); | 11017 node.visitChildren(this); |
| 11035 node.accept(_elementResolver); | 11018 node.accept(elementResolver); |
| 11036 node.accept(_typeAnalyzer); | 11019 node.accept(typeAnalyzer); |
| 11037 return null; | 11020 return null; |
| 11038 } | 11021 } |
| 11039 | 11022 |
| 11040 @override | 11023 @override |
| 11041 Object visitPrefixedIdentifier(PrefixedIdentifier node) { | 11024 Object visitPrefixedIdentifier(PrefixedIdentifier node) { |
| 11042 // | 11025 // |
| 11043 // We visit the prefix, but do not visit the identifier because it needs to | 11026 // We visit the prefix, but do not visit the identifier because it needs to |
| 11044 // be visited in the context of the prefix. | 11027 // be visited in the context of the prefix. |
| 11045 // | 11028 // |
| 11046 safelyVisit(node.prefix); | 11029 safelyVisit(node.prefix); |
| 11047 node.accept(_elementResolver); | 11030 node.accept(elementResolver); |
| 11048 node.accept(_typeAnalyzer); | 11031 node.accept(typeAnalyzer); |
| 11049 return null; | 11032 return null; |
| 11050 } | 11033 } |
| 11051 | 11034 |
| 11052 @override | 11035 @override |
| 11053 Object visitPropertyAccess(PropertyAccess node) { | 11036 Object visitPropertyAccess(PropertyAccess node) { |
| 11054 // | 11037 // |
| 11055 // We visit the target, but do not visit the property name because it needs | 11038 // We visit the target, but do not visit the property name because it needs |
| 11056 // to be visited in the context of the property access node. | 11039 // to be visited in the context of the property access node. |
| 11057 // | 11040 // |
| 11058 safelyVisit(node.target); | 11041 safelyVisit(node.target); |
| 11059 node.accept(_elementResolver); | 11042 node.accept(elementResolver); |
| 11060 node.accept(_typeAnalyzer); | 11043 node.accept(typeAnalyzer); |
| 11061 return null; | 11044 return null; |
| 11062 } | 11045 } |
| 11063 | 11046 |
| 11064 @override | 11047 @override |
| 11065 Object visitRedirectingConstructorInvocation( | 11048 Object visitRedirectingConstructorInvocation( |
| 11066 RedirectingConstructorInvocation node) { | 11049 RedirectingConstructorInvocation node) { |
| 11067 // | 11050 // |
| 11068 // We visit the argument list, but do not visit the optional identifier | 11051 // We visit the argument list, but do not visit the optional identifier |
| 11069 // because it needs to be visited in the context of the constructor | 11052 // because it needs to be visited in the context of the constructor |
| 11070 // invocation. | 11053 // invocation. |
| 11071 // | 11054 // |
| 11072 safelyVisit(node.argumentList); | 11055 safelyVisit(node.argumentList); |
| 11073 node.accept(_elementResolver); | 11056 node.accept(elementResolver); |
| 11074 node.accept(_typeAnalyzer); | 11057 node.accept(typeAnalyzer); |
| 11075 return null; | 11058 return null; |
| 11076 } | 11059 } |
| 11077 | 11060 |
| 11078 @override | 11061 @override |
| 11079 Object visitShowCombinator(ShowCombinator node) => null; | 11062 Object visitShowCombinator(ShowCombinator node) => null; |
| 11080 | 11063 |
| 11081 @override | 11064 @override |
| 11082 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { | 11065 Object visitSuperConstructorInvocation(SuperConstructorInvocation node) { |
| 11083 // | 11066 // |
| 11084 // We visit the argument list, but do not visit the optional identifier | 11067 // We visit the argument list, but do not visit the optional identifier |
| 11085 // because it needs to be visited in the context of the constructor | 11068 // because it needs to be visited in the context of the constructor |
| 11086 // invocation. | 11069 // invocation. |
| 11087 // | 11070 // |
| 11088 safelyVisit(node.argumentList); | 11071 safelyVisit(node.argumentList); |
| 11089 node.accept(_elementResolver); | 11072 node.accept(elementResolver); |
| 11090 node.accept(_typeAnalyzer); | 11073 node.accept(typeAnalyzer); |
| 11091 return null; | 11074 return null; |
| 11092 } | 11075 } |
| 11093 | 11076 |
| 11094 @override | 11077 @override |
| 11095 Object visitSwitchCase(SwitchCase node) { | 11078 Object visitSwitchCase(SwitchCase node) { |
| 11096 _overrideManager.enterScope(); | 11079 _overrideManager.enterScope(); |
| 11097 try { | 11080 try { |
| 11098 super.visitSwitchCase(node); | 11081 super.visitSwitchCase(node); |
| 11099 } finally { | 11082 } finally { |
| 11100 _overrideManager.exitScope(); | 11083 _overrideManager.exitScope(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11147 visitStatementInScope(body); | 11130 visitStatementInScope(body); |
| 11148 } finally { | 11131 } finally { |
| 11149 _overrideManager.exitScope(); | 11132 _overrideManager.exitScope(); |
| 11150 } | 11133 } |
| 11151 } | 11134 } |
| 11152 } finally { | 11135 } finally { |
| 11153 _implicitLabelScope = outerImplicitScope; | 11136 _implicitLabelScope = outerImplicitScope; |
| 11154 } | 11137 } |
| 11155 // TODO(brianwilkerson) If the loop can only be exited because the condition | 11138 // TODO(brianwilkerson) If the loop can only be exited because the condition |
| 11156 // is false, then propagateFalseState(condition); | 11139 // is false, then propagateFalseState(condition); |
| 11157 node.accept(_elementResolver); | 11140 node.accept(elementResolver); |
| 11158 node.accept(_typeAnalyzer); | 11141 node.accept(typeAnalyzer); |
| 11159 return null; | 11142 return null; |
| 11160 } | 11143 } |
| 11161 | 11144 |
| 11162 /** | 11145 /** |
| 11163 * Checks each promoted variable in the current scope for compliance with the
following | 11146 * Checks each promoted variable in the current scope for compliance with the
following |
| 11164 * specification statement: | 11147 * specification statement: |
| 11165 * | 11148 * |
| 11166 * If the variable <i>v</i> is accessed by a closure in <i>s<sub>1</sub></i> t
hen the variable | 11149 * If the variable <i>v</i> is accessed by a closure in <i>s<sub>1</sub></i> t
hen the variable |
| 11167 * <i>v</i> is not potentially mutated anywhere in the scope of <i>v</i>. | 11150 * <i>v</i> is not potentially mutated anywhere in the scope of <i>v</i>. |
| 11168 */ | 11151 */ |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11741 final Source source; | 11724 final Source source; |
| 11742 | 11725 |
| 11743 /** | 11726 /** |
| 11744 * The error listener that will be informed of any errors that are found durin
g resolution. | 11727 * The error listener that will be informed of any errors that are found durin
g resolution. |
| 11745 */ | 11728 */ |
| 11746 AnalysisErrorListener _errorListener; | 11729 AnalysisErrorListener _errorListener; |
| 11747 | 11730 |
| 11748 /** | 11731 /** |
| 11749 * The scope used to resolve identifiers. | 11732 * The scope used to resolve identifiers. |
| 11750 */ | 11733 */ |
| 11751 Scope _nameScope; | 11734 Scope nameScope; |
| 11752 | 11735 |
| 11753 /** | 11736 /** |
| 11754 * The object used to access the types from the core library. | 11737 * The object used to access the types from the core library. |
| 11755 */ | 11738 */ |
| 11756 final TypeProvider typeProvider; | 11739 final TypeProvider typeProvider; |
| 11757 | 11740 |
| 11758 /** | 11741 /** |
| 11759 * The scope used to resolve unlabeled `break` and `continue` statements. | 11742 * The scope used to resolve unlabeled `break` and `continue` statements. |
| 11760 */ | 11743 */ |
| 11761 ImplicitLabelScope _implicitLabelScope = ImplicitLabelScope.ROOT; | 11744 ImplicitLabelScope _implicitLabelScope = ImplicitLabelScope.ROOT; |
| 11762 | 11745 |
| 11763 /** | 11746 /** |
| 11764 * The scope used to resolve labels for `break` and `continue` statements, or | 11747 * The scope used to resolve labels for `break` and `continue` statements, or |
| 11765 * `null` if no labels have been defined in the current context. | 11748 * `null` if no labels have been defined in the current context. |
| 11766 */ | 11749 */ |
| 11767 LabelScope _labelScope; | 11750 LabelScope labelScope; |
| 11768 | 11751 |
| 11769 /** | 11752 /** |
| 11770 * The class containing the AST nodes being visited, | 11753 * The class containing the AST nodes being visited, |
| 11771 * or `null` if we are not in the scope of a class. | 11754 * or `null` if we are not in the scope of a class. |
| 11772 */ | 11755 */ |
| 11773 ClassElement enclosingClass; | 11756 ClassElement enclosingClass; |
| 11774 | 11757 |
| 11775 /** | 11758 /** |
| 11776 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 11759 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 11777 * | 11760 * |
| 11778 * @param library the library containing the compilation unit being resolved | 11761 * @param library the library containing the compilation unit being resolved |
| 11779 * @param source the source representing the compilation unit being visited | 11762 * @param source the source representing the compilation unit being visited |
| 11780 * @param typeProvider the object used to access the types from the core libra
ry | 11763 * @param typeProvider the object used to access the types from the core libra
ry |
| 11781 */ | 11764 */ |
| 11782 ScopedVisitor.con1(Library library, this.source, this.typeProvider) { | 11765 ScopedVisitor.con1(Library library, this.source, this.typeProvider) { |
| 11783 this._definingLibrary = library.libraryElement; | 11766 this._definingLibrary = library.libraryElement; |
| 11784 LibraryScope libraryScope = library.libraryScope; | 11767 LibraryScope libraryScope = library.libraryScope; |
| 11785 this._errorListener = libraryScope.errorListener; | 11768 this._errorListener = libraryScope.errorListener; |
| 11786 this._nameScope = libraryScope; | 11769 this.nameScope = libraryScope; |
| 11787 } | 11770 } |
| 11788 | 11771 |
| 11789 /** | 11772 /** |
| 11790 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 11773 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 11791 * | 11774 * |
| 11792 * @param definingLibrary the element for the library containing the compilati
on unit being | 11775 * @param definingLibrary the element for the library containing the compilati
on unit being |
| 11793 * visited | 11776 * visited |
| 11794 * @param source the source representing the compilation unit being visited | 11777 * @param source the source representing the compilation unit being visited |
| 11795 * @param typeProvider the object used to access the types from the core libra
ry | 11778 * @param typeProvider the object used to access the types from the core libra
ry |
| 11796 * @param errorListener the error listener that will be informed of any errors
that are found | 11779 * @param errorListener the error listener that will be informed of any errors
that are found |
| 11797 * during resolution | 11780 * during resolution |
| 11798 */ | 11781 */ |
| 11799 ScopedVisitor.con2(LibraryElement definingLibrary, this.source, | 11782 ScopedVisitor.con2(LibraryElement definingLibrary, this.source, |
| 11800 this.typeProvider, AnalysisErrorListener errorListener) { | 11783 this.typeProvider, AnalysisErrorListener errorListener) { |
| 11801 this._definingLibrary = definingLibrary; | 11784 this._definingLibrary = definingLibrary; |
| 11802 this._errorListener = errorListener; | 11785 this._errorListener = errorListener; |
| 11803 this._nameScope = new LibraryScope(definingLibrary, errorListener); | 11786 this.nameScope = new LibraryScope(definingLibrary, errorListener); |
| 11804 } | 11787 } |
| 11805 | 11788 |
| 11806 /** | 11789 /** |
| 11807 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 11790 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 11808 * | 11791 * |
| 11809 * @param definingLibrary the element for the library containing the compilati
on unit being | 11792 * @param definingLibrary the element for the library containing the compilati
on unit being |
| 11810 * visited | 11793 * visited |
| 11811 * @param source the source representing the compilation unit being visited | 11794 * @param source the source representing the compilation unit being visited |
| 11812 * @param typeProvider the object used to access the types from the core libra
ry | 11795 * @param typeProvider the object used to access the types from the core libra
ry |
| 11813 * @param nameScope the scope used to resolve identifiers in the node that wil
l first be visited | 11796 * @param nameScope the scope used to resolve identifiers in the node that wil
l first be visited |
| 11814 * @param errorListener the error listener that will be informed of any errors
that are found | 11797 * @param errorListener the error listener that will be informed of any errors
that are found |
| 11815 * during resolution | 11798 * during resolution |
| 11816 */ | 11799 */ |
| 11817 ScopedVisitor.con3(LibraryElement definingLibrary, this.source, | 11800 ScopedVisitor.con3(LibraryElement definingLibrary, this.source, |
| 11818 this.typeProvider, Scope nameScope, AnalysisErrorListener errorListener) { | 11801 this.typeProvider, Scope nameScope, AnalysisErrorListener errorListener) { |
| 11819 this._definingLibrary = definingLibrary; | 11802 this._definingLibrary = definingLibrary; |
| 11820 this._errorListener = errorListener; | 11803 this._errorListener = errorListener; |
| 11821 this._nameScope = nameScope; | 11804 this.nameScope = nameScope; |
| 11822 } | 11805 } |
| 11823 | 11806 |
| 11824 /** | 11807 /** |
| 11825 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 11808 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 11826 * | 11809 * |
| 11827 * @param library the library containing the compilation unit being resolved | 11810 * @param library the library containing the compilation unit being resolved |
| 11828 * @param source the source representing the compilation unit being visited | 11811 * @param source the source representing the compilation unit being visited |
| 11829 * @param typeProvider the object used to access the types from the core libra
ry | 11812 * @param typeProvider the object used to access the types from the core libra
ry |
| 11830 */ | 11813 */ |
| 11831 ScopedVisitor.con4( | 11814 ScopedVisitor.con4( |
| 11832 ResolvableLibrary library, this.source, this.typeProvider) { | 11815 ResolvableLibrary library, this.source, this.typeProvider) { |
| 11833 this._definingLibrary = library.libraryElement; | 11816 this._definingLibrary = library.libraryElement; |
| 11834 LibraryScope libraryScope = library.libraryScope; | 11817 LibraryScope libraryScope = library.libraryScope; |
| 11835 this._errorListener = libraryScope.errorListener; | 11818 this._errorListener = libraryScope.errorListener; |
| 11836 this._nameScope = libraryScope; | 11819 this.nameScope = libraryScope; |
| 11837 } | 11820 } |
| 11838 | 11821 |
| 11839 /** | 11822 /** |
| 11840 * Return the library element for the library containing the compilation unit
being resolved. | 11823 * Return the library element for the library containing the compilation unit
being resolved. |
| 11841 * | 11824 * |
| 11842 * @return the library element for the library containing the compilation unit
being resolved | 11825 * @return the library element for the library containing the compilation unit
being resolved |
| 11843 */ | 11826 */ |
| 11844 LibraryElement get definingLibrary => _definingLibrary; | 11827 LibraryElement get definingLibrary => _definingLibrary; |
| 11845 | 11828 |
| 11846 /** | 11829 /** |
| 11847 * Return the implicit label scope in which the current node is being | 11830 * Return the implicit label scope in which the current node is being |
| 11848 * resolved. | 11831 * resolved. |
| 11849 */ | 11832 */ |
| 11850 ImplicitLabelScope get implicitLabelScope => _implicitLabelScope; | 11833 ImplicitLabelScope get implicitLabelScope => _implicitLabelScope; |
| 11851 | 11834 |
| 11852 /** | 11835 /** |
| 11853 * Return the label scope in which the current node is being resolved. | |
| 11854 * | |
| 11855 * @return the label scope in which the current node is being resolved | |
| 11856 */ | |
| 11857 LabelScope get labelScope => _labelScope; | |
| 11858 | |
| 11859 /** | |
| 11860 * Return the name scope in which the current node is being resolved. | |
| 11861 * | |
| 11862 * @return the name scope in which the current node is being resolved | |
| 11863 */ | |
| 11864 Scope get nameScope => _nameScope; | |
| 11865 | |
| 11866 /** | |
| 11867 * Replaces the current [Scope] with the enclosing [Scope]. | 11836 * Replaces the current [Scope] with the enclosing [Scope]. |
| 11868 * | 11837 * |
| 11869 * @return the enclosing [Scope]. | 11838 * @return the enclosing [Scope]. |
| 11870 */ | 11839 */ |
| 11871 Scope popNameScope() { | 11840 Scope popNameScope() { |
| 11872 _nameScope = _nameScope.enclosingScope; | 11841 nameScope = nameScope.enclosingScope; |
| 11873 return _nameScope; | 11842 return nameScope; |
| 11874 } | 11843 } |
| 11875 | 11844 |
| 11876 /** | 11845 /** |
| 11877 * Pushes a new [Scope] into the visitor. | 11846 * Pushes a new [Scope] into the visitor. |
| 11878 * | 11847 * |
| 11879 * @return the new [Scope]. | 11848 * @return the new [Scope]. |
| 11880 */ | 11849 */ |
| 11881 Scope pushNameScope() { | 11850 Scope pushNameScope() { |
| 11882 Scope newScope = new EnclosedScope(_nameScope); | 11851 Scope newScope = new EnclosedScope(nameScope); |
| 11883 _nameScope = newScope; | 11852 nameScope = newScope; |
| 11884 return _nameScope; | 11853 return nameScope; |
| 11885 } | 11854 } |
| 11886 | 11855 |
| 11887 /** | 11856 /** |
| 11888 * Report an error with the given error code and arguments. | 11857 * Report an error with the given error code and arguments. |
| 11889 * | 11858 * |
| 11890 * @param errorCode the error code of the error to be reported | 11859 * @param errorCode the error code of the error to be reported |
| 11891 * @param node the node specifying the location of the error | 11860 * @param node the node specifying the location of the error |
| 11892 * @param arguments the arguments to the error, used to compose the error mess
age | 11861 * @param arguments the arguments to the error, used to compose the error mess
age |
| 11893 */ | 11862 */ |
| 11894 void reportErrorForNode(ErrorCode errorCode, AstNode node, | 11863 void reportErrorForNode(ErrorCode errorCode, AstNode node, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11930 * @param node the node to be visited | 11899 * @param node the node to be visited |
| 11931 */ | 11900 */ |
| 11932 void safelyVisit(AstNode node) { | 11901 void safelyVisit(AstNode node) { |
| 11933 if (node != null) { | 11902 if (node != null) { |
| 11934 node.accept(this); | 11903 node.accept(this); |
| 11935 } | 11904 } |
| 11936 } | 11905 } |
| 11937 | 11906 |
| 11938 @override | 11907 @override |
| 11939 Object visitBlock(Block node) { | 11908 Object visitBlock(Block node) { |
| 11940 Scope outerScope = _nameScope; | 11909 Scope outerScope = nameScope; |
| 11941 try { | 11910 try { |
| 11942 EnclosedScope enclosedScope = new EnclosedScope(_nameScope); | 11911 EnclosedScope enclosedScope = new EnclosedScope(nameScope); |
| 11943 _hideNamesDefinedInBlock(enclosedScope, node); | 11912 _hideNamesDefinedInBlock(enclosedScope, node); |
| 11944 _nameScope = enclosedScope; | 11913 nameScope = enclosedScope; |
| 11945 super.visitBlock(node); | 11914 super.visitBlock(node); |
| 11946 } finally { | 11915 } finally { |
| 11947 _nameScope = outerScope; | 11916 nameScope = outerScope; |
| 11948 } | 11917 } |
| 11949 return null; | 11918 return null; |
| 11950 } | 11919 } |
| 11951 | 11920 |
| 11952 @override | 11921 @override |
| 11953 Object visitBlockFunctionBody(BlockFunctionBody node) { | 11922 Object visitBlockFunctionBody(BlockFunctionBody node) { |
| 11954 ImplicitLabelScope implicitOuterScope = _implicitLabelScope; | 11923 ImplicitLabelScope implicitOuterScope = _implicitLabelScope; |
| 11955 try { | 11924 try { |
| 11956 _implicitLabelScope = ImplicitLabelScope.ROOT; | 11925 _implicitLabelScope = ImplicitLabelScope.ROOT; |
| 11957 super.visitBlockFunctionBody(node); | 11926 super.visitBlockFunctionBody(node); |
| 11958 } finally { | 11927 } finally { |
| 11959 _implicitLabelScope = implicitOuterScope; | 11928 _implicitLabelScope = implicitOuterScope; |
| 11960 } | 11929 } |
| 11961 return null; | 11930 return null; |
| 11962 } | 11931 } |
| 11963 | 11932 |
| 11964 @override | 11933 @override |
| 11965 Object visitCatchClause(CatchClause node) { | 11934 Object visitCatchClause(CatchClause node) { |
| 11966 SimpleIdentifier exception = node.exceptionParameter; | 11935 SimpleIdentifier exception = node.exceptionParameter; |
| 11967 if (exception != null) { | 11936 if (exception != null) { |
| 11968 Scope outerScope = _nameScope; | 11937 Scope outerScope = nameScope; |
| 11969 try { | 11938 try { |
| 11970 _nameScope = new EnclosedScope(_nameScope); | 11939 nameScope = new EnclosedScope(nameScope); |
| 11971 _nameScope.define(exception.staticElement); | 11940 nameScope.define(exception.staticElement); |
| 11972 SimpleIdentifier stackTrace = node.stackTraceParameter; | 11941 SimpleIdentifier stackTrace = node.stackTraceParameter; |
| 11973 if (stackTrace != null) { | 11942 if (stackTrace != null) { |
| 11974 _nameScope.define(stackTrace.staticElement); | 11943 nameScope.define(stackTrace.staticElement); |
| 11975 } | 11944 } |
| 11976 super.visitCatchClause(node); | 11945 super.visitCatchClause(node); |
| 11977 } finally { | 11946 } finally { |
| 11978 _nameScope = outerScope; | 11947 nameScope = outerScope; |
| 11979 } | 11948 } |
| 11980 } else { | 11949 } else { |
| 11981 super.visitCatchClause(node); | 11950 super.visitCatchClause(node); |
| 11982 } | 11951 } |
| 11983 return null; | 11952 return null; |
| 11984 } | 11953 } |
| 11985 | 11954 |
| 11986 @override | 11955 @override |
| 11987 Object visitClassDeclaration(ClassDeclaration node) { | 11956 Object visitClassDeclaration(ClassDeclaration node) { |
| 11988 ClassElement classElement = node.element; | 11957 ClassElement classElement = node.element; |
| 11989 Scope outerScope = _nameScope; | 11958 Scope outerScope = nameScope; |
| 11990 try { | 11959 try { |
| 11991 if (classElement == null) { | 11960 if (classElement == null) { |
| 11992 AnalysisEngine.instance.logger.logInformation( | 11961 AnalysisEngine.instance.logger.logInformation( |
| 11993 "Missing element for class declaration ${node.name.name} in ${defini
ngLibrary.source.fullName}", | 11962 "Missing element for class declaration ${node.name.name} in ${defini
ngLibrary.source.fullName}", |
| 11994 new CaughtException(new AnalysisException(), null)); | 11963 new CaughtException(new AnalysisException(), null)); |
| 11995 super.visitClassDeclaration(node); | 11964 super.visitClassDeclaration(node); |
| 11996 } else { | 11965 } else { |
| 11997 ClassElement outerClass = enclosingClass; | 11966 ClassElement outerClass = enclosingClass; |
| 11998 try { | 11967 try { |
| 11999 enclosingClass = node.element; | 11968 enclosingClass = node.element; |
| 12000 _nameScope = new TypeParameterScope(_nameScope, classElement); | 11969 nameScope = new TypeParameterScope(nameScope, classElement); |
| 12001 visitClassDeclarationInScope(node); | 11970 visitClassDeclarationInScope(node); |
| 12002 _nameScope = new ClassScope(_nameScope, classElement); | 11971 nameScope = new ClassScope(nameScope, classElement); |
| 12003 visitClassMembersInScope(node); | 11972 visitClassMembersInScope(node); |
| 12004 } finally { | 11973 } finally { |
| 12005 enclosingClass = outerClass; | 11974 enclosingClass = outerClass; |
| 12006 } | 11975 } |
| 12007 } | 11976 } |
| 12008 } finally { | 11977 } finally { |
| 12009 _nameScope = outerScope; | 11978 nameScope = outerScope; |
| 12010 } | 11979 } |
| 12011 return null; | 11980 return null; |
| 12012 } | 11981 } |
| 12013 | 11982 |
| 12014 void visitClassDeclarationInScope(ClassDeclaration node) { | 11983 void visitClassDeclarationInScope(ClassDeclaration node) { |
| 12015 safelyVisit(node.name); | 11984 safelyVisit(node.name); |
| 12016 safelyVisit(node.typeParameters); | 11985 safelyVisit(node.typeParameters); |
| 12017 safelyVisit(node.extendsClause); | 11986 safelyVisit(node.extendsClause); |
| 12018 safelyVisit(node.withClause); | 11987 safelyVisit(node.withClause); |
| 12019 safelyVisit(node.implementsClause); | 11988 safelyVisit(node.implementsClause); |
| 12020 safelyVisit(node.nativeClause); | 11989 safelyVisit(node.nativeClause); |
| 12021 } | 11990 } |
| 12022 | 11991 |
| 12023 void visitClassMembersInScope(ClassDeclaration node) { | 11992 void visitClassMembersInScope(ClassDeclaration node) { |
| 12024 safelyVisit(node.documentationComment); | 11993 safelyVisit(node.documentationComment); |
| 12025 node.metadata.accept(this); | 11994 node.metadata.accept(this); |
| 12026 node.members.accept(this); | 11995 node.members.accept(this); |
| 12027 } | 11996 } |
| 12028 | 11997 |
| 12029 @override | 11998 @override |
| 12030 Object visitClassTypeAlias(ClassTypeAlias node) { | 11999 Object visitClassTypeAlias(ClassTypeAlias node) { |
| 12031 Scope outerScope = _nameScope; | 12000 Scope outerScope = nameScope; |
| 12032 try { | 12001 try { |
| 12033 ClassElement element = node.element; | 12002 ClassElement element = node.element; |
| 12034 _nameScope = | 12003 nameScope = |
| 12035 new ClassScope(new TypeParameterScope(_nameScope, element), element); | 12004 new ClassScope(new TypeParameterScope(nameScope, element), element); |
| 12036 super.visitClassTypeAlias(node); | 12005 super.visitClassTypeAlias(node); |
| 12037 } finally { | 12006 } finally { |
| 12038 _nameScope = outerScope; | 12007 nameScope = outerScope; |
| 12039 } | 12008 } |
| 12040 return null; | 12009 return null; |
| 12041 } | 12010 } |
| 12042 | 12011 |
| 12043 @override | 12012 @override |
| 12044 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 12013 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 12045 ConstructorElement constructorElement = node.element; | 12014 ConstructorElement constructorElement = node.element; |
| 12046 Scope outerScope = _nameScope; | 12015 Scope outerScope = nameScope; |
| 12047 try { | 12016 try { |
| 12048 if (constructorElement == null) { | 12017 if (constructorElement == null) { |
| 12049 StringBuffer buffer = new StringBuffer(); | 12018 StringBuffer buffer = new StringBuffer(); |
| 12050 buffer.write("Missing element for constructor "); | 12019 buffer.write("Missing element for constructor "); |
| 12051 buffer.write(node.returnType.name); | 12020 buffer.write(node.returnType.name); |
| 12052 if (node.name != null) { | 12021 if (node.name != null) { |
| 12053 buffer.write("."); | 12022 buffer.write("."); |
| 12054 buffer.write(node.name.name); | 12023 buffer.write(node.name.name); |
| 12055 } | 12024 } |
| 12056 buffer.write(" in "); | 12025 buffer.write(" in "); |
| 12057 buffer.write(definingLibrary.source.fullName); | 12026 buffer.write(definingLibrary.source.fullName); |
| 12058 AnalysisEngine.instance.logger.logInformation(buffer.toString(), | 12027 AnalysisEngine.instance.logger.logInformation(buffer.toString(), |
| 12059 new CaughtException(new AnalysisException(), null)); | 12028 new CaughtException(new AnalysisException(), null)); |
| 12060 } else { | 12029 } else { |
| 12061 _nameScope = new FunctionScope(_nameScope, constructorElement); | 12030 nameScope = new FunctionScope(nameScope, constructorElement); |
| 12062 } | 12031 } |
| 12063 super.visitConstructorDeclaration(node); | 12032 super.visitConstructorDeclaration(node); |
| 12064 } finally { | 12033 } finally { |
| 12065 _nameScope = outerScope; | 12034 nameScope = outerScope; |
| 12066 } | 12035 } |
| 12067 return null; | 12036 return null; |
| 12068 } | 12037 } |
| 12069 | 12038 |
| 12070 @override | 12039 @override |
| 12071 Object visitDeclaredIdentifier(DeclaredIdentifier node) { | 12040 Object visitDeclaredIdentifier(DeclaredIdentifier node) { |
| 12072 VariableElement element = node.element; | 12041 VariableElement element = node.element; |
| 12073 if (element != null) { | 12042 if (element != null) { |
| 12074 _nameScope.define(element); | 12043 nameScope.define(element); |
| 12075 } | 12044 } |
| 12076 super.visitDeclaredIdentifier(node); | 12045 super.visitDeclaredIdentifier(node); |
| 12077 return null; | 12046 return null; |
| 12078 } | 12047 } |
| 12079 | 12048 |
| 12080 @override | 12049 @override |
| 12081 Object visitDoStatement(DoStatement node) { | 12050 Object visitDoStatement(DoStatement node) { |
| 12082 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; | 12051 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 12083 try { | 12052 try { |
| 12084 _implicitLabelScope = _implicitLabelScope.nest(node); | 12053 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 12085 visitStatementInScope(node.body); | 12054 visitStatementInScope(node.body); |
| 12086 safelyVisit(node.condition); | 12055 safelyVisit(node.condition); |
| 12087 } finally { | 12056 } finally { |
| 12088 _implicitLabelScope = outerImplicitScope; | 12057 _implicitLabelScope = outerImplicitScope; |
| 12089 } | 12058 } |
| 12090 return null; | 12059 return null; |
| 12091 } | 12060 } |
| 12092 | 12061 |
| 12093 @override | 12062 @override |
| 12094 Object visitForEachStatement(ForEachStatement node) { | 12063 Object visitForEachStatement(ForEachStatement node) { |
| 12095 Scope outerNameScope = _nameScope; | 12064 Scope outerNameScope = nameScope; |
| 12096 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; | 12065 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 12097 try { | 12066 try { |
| 12098 _nameScope = new EnclosedScope(_nameScope); | 12067 nameScope = new EnclosedScope(nameScope); |
| 12099 _implicitLabelScope = _implicitLabelScope.nest(node); | 12068 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 12100 visitForEachStatementInScope(node); | 12069 visitForEachStatementInScope(node); |
| 12101 } finally { | 12070 } finally { |
| 12102 _nameScope = outerNameScope; | 12071 nameScope = outerNameScope; |
| 12103 _implicitLabelScope = outerImplicitScope; | 12072 _implicitLabelScope = outerImplicitScope; |
| 12104 } | 12073 } |
| 12105 return null; | 12074 return null; |
| 12106 } | 12075 } |
| 12107 | 12076 |
| 12108 /** | 12077 /** |
| 12109 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 12078 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
| 12110 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 12079 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
| 12111 * enabled. | 12080 * enabled. |
| 12112 * | 12081 * |
| (...skipping 10 matching lines...) Expand all Loading... |
| 12123 visitStatementInScope(node.body); | 12092 visitStatementInScope(node.body); |
| 12124 } | 12093 } |
| 12125 | 12094 |
| 12126 @override | 12095 @override |
| 12127 Object visitFormalParameterList(FormalParameterList node) { | 12096 Object visitFormalParameterList(FormalParameterList node) { |
| 12128 super.visitFormalParameterList(node); | 12097 super.visitFormalParameterList(node); |
| 12129 // We finished resolving function signature, now include formal parameters | 12098 // We finished resolving function signature, now include formal parameters |
| 12130 // scope. Note: we must not do this if the parent is a | 12099 // scope. Note: we must not do this if the parent is a |
| 12131 // FunctionTypedFormalParameter, because in that case we aren't finished | 12100 // FunctionTypedFormalParameter, because in that case we aren't finished |
| 12132 // resolving the full function signature, just a part of it. | 12101 // resolving the full function signature, just a part of it. |
| 12133 if (_nameScope is FunctionScope && | 12102 if (nameScope is FunctionScope && |
| 12134 node.parent is! FunctionTypedFormalParameter) { | 12103 node.parent is! FunctionTypedFormalParameter) { |
| 12135 (_nameScope as FunctionScope).defineParameters(); | 12104 (nameScope as FunctionScope).defineParameters(); |
| 12136 } | 12105 } |
| 12137 if (_nameScope is FunctionTypeScope) { | 12106 if (nameScope is FunctionTypeScope) { |
| 12138 (_nameScope as FunctionTypeScope).defineParameters(); | 12107 (nameScope as FunctionTypeScope).defineParameters(); |
| 12139 } | 12108 } |
| 12140 return null; | 12109 return null; |
| 12141 } | 12110 } |
| 12142 | 12111 |
| 12143 @override | 12112 @override |
| 12144 Object visitForStatement(ForStatement node) { | 12113 Object visitForStatement(ForStatement node) { |
| 12145 Scope outerNameScope = _nameScope; | 12114 Scope outerNameScope = nameScope; |
| 12146 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; | 12115 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 12147 try { | 12116 try { |
| 12148 _nameScope = new EnclosedScope(_nameScope); | 12117 nameScope = new EnclosedScope(nameScope); |
| 12149 _implicitLabelScope = _implicitLabelScope.nest(node); | 12118 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 12150 visitForStatementInScope(node); | 12119 visitForStatementInScope(node); |
| 12151 } finally { | 12120 } finally { |
| 12152 _nameScope = outerNameScope; | 12121 nameScope = outerNameScope; |
| 12153 _implicitLabelScope = outerImplicitScope; | 12122 _implicitLabelScope = outerImplicitScope; |
| 12154 } | 12123 } |
| 12155 return null; | 12124 return null; |
| 12156 } | 12125 } |
| 12157 | 12126 |
| 12158 /** | 12127 /** |
| 12159 * Visit the given statement after it's scope has been created. This replaces
the normal call to | 12128 * Visit the given statement after it's scope has been created. This replaces
the normal call to |
| 12160 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is | 12129 * the inherited visit method so that ResolverVisitor can intervene when type
propagation is |
| 12161 * enabled. | 12130 * enabled. |
| 12162 * | 12131 * |
| 12163 * @param node the statement to be visited | 12132 * @param node the statement to be visited |
| 12164 */ | 12133 */ |
| 12165 void visitForStatementInScope(ForStatement node) { | 12134 void visitForStatementInScope(ForStatement node) { |
| 12166 safelyVisit(node.variables); | 12135 safelyVisit(node.variables); |
| 12167 safelyVisit(node.initialization); | 12136 safelyVisit(node.initialization); |
| 12168 safelyVisit(node.condition); | 12137 safelyVisit(node.condition); |
| 12169 node.updaters.accept(this); | 12138 node.updaters.accept(this); |
| 12170 visitStatementInScope(node.body); | 12139 visitStatementInScope(node.body); |
| 12171 } | 12140 } |
| 12172 | 12141 |
| 12173 @override | 12142 @override |
| 12174 Object visitFunctionDeclaration(FunctionDeclaration node) { | 12143 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 12175 ExecutableElement functionElement = node.element; | 12144 ExecutableElement functionElement = node.element; |
| 12176 if (functionElement != null && | 12145 if (functionElement != null && |
| 12177 functionElement.enclosingElement is! CompilationUnitElement) { | 12146 functionElement.enclosingElement is! CompilationUnitElement) { |
| 12178 _nameScope.define(functionElement); | 12147 nameScope.define(functionElement); |
| 12179 } | 12148 } |
| 12180 Scope outerScope = _nameScope; | 12149 Scope outerScope = nameScope; |
| 12181 try { | 12150 try { |
| 12182 if (functionElement == null) { | 12151 if (functionElement == null) { |
| 12183 AnalysisEngine.instance.logger.logInformation( | 12152 AnalysisEngine.instance.logger.logInformation( |
| 12184 "Missing element for top-level function ${node.name.name} in ${defin
ingLibrary.source.fullName}", | 12153 "Missing element for top-level function ${node.name.name} in ${defin
ingLibrary.source.fullName}", |
| 12185 new CaughtException(new AnalysisException(), null)); | 12154 new CaughtException(new AnalysisException(), null)); |
| 12186 } else { | 12155 } else { |
| 12187 _nameScope = new FunctionScope(_nameScope, functionElement); | 12156 nameScope = new FunctionScope(nameScope, functionElement); |
| 12188 } | 12157 } |
| 12189 super.visitFunctionDeclaration(node); | 12158 super.visitFunctionDeclaration(node); |
| 12190 } finally { | 12159 } finally { |
| 12191 _nameScope = outerScope; | 12160 nameScope = outerScope; |
| 12192 } | 12161 } |
| 12193 return null; | 12162 return null; |
| 12194 } | 12163 } |
| 12195 | 12164 |
| 12196 @override | 12165 @override |
| 12197 Object visitFunctionExpression(FunctionExpression node) { | 12166 Object visitFunctionExpression(FunctionExpression node) { |
| 12198 if (node.parent is FunctionDeclaration) { | 12167 if (node.parent is FunctionDeclaration) { |
| 12199 // We have already created a function scope and don't need to do so again. | 12168 // We have already created a function scope and don't need to do so again. |
| 12200 super.visitFunctionExpression(node); | 12169 super.visitFunctionExpression(node); |
| 12201 } else { | 12170 } else { |
| 12202 Scope outerScope = _nameScope; | 12171 Scope outerScope = nameScope; |
| 12203 try { | 12172 try { |
| 12204 ExecutableElement functionElement = node.element; | 12173 ExecutableElement functionElement = node.element; |
| 12205 if (functionElement == null) { | 12174 if (functionElement == null) { |
| 12206 StringBuffer buffer = new StringBuffer(); | 12175 StringBuffer buffer = new StringBuffer(); |
| 12207 buffer.write("Missing element for function "); | 12176 buffer.write("Missing element for function "); |
| 12208 AstNode parent = node.parent; | 12177 AstNode parent = node.parent; |
| 12209 while (parent != null) { | 12178 while (parent != null) { |
| 12210 if (parent is Declaration) { | 12179 if (parent is Declaration) { |
| 12211 Element parentElement = parent.element; | 12180 Element parentElement = parent.element; |
| 12212 buffer.write(parentElement == null | 12181 buffer.write(parentElement == null |
| 12213 ? "<unknown> " | 12182 ? "<unknown> " |
| 12214 : "${parentElement.name} "); | 12183 : "${parentElement.name} "); |
| 12215 } | 12184 } |
| 12216 parent = parent.parent; | 12185 parent = parent.parent; |
| 12217 } | 12186 } |
| 12218 buffer.write("in "); | 12187 buffer.write("in "); |
| 12219 buffer.write(definingLibrary.source.fullName); | 12188 buffer.write(definingLibrary.source.fullName); |
| 12220 AnalysisEngine.instance.logger.logInformation(buffer.toString(), | 12189 AnalysisEngine.instance.logger.logInformation(buffer.toString(), |
| 12221 new CaughtException(new AnalysisException(), null)); | 12190 new CaughtException(new AnalysisException(), null)); |
| 12222 } else { | 12191 } else { |
| 12223 _nameScope = new FunctionScope(_nameScope, functionElement); | 12192 nameScope = new FunctionScope(nameScope, functionElement); |
| 12224 } | 12193 } |
| 12225 super.visitFunctionExpression(node); | 12194 super.visitFunctionExpression(node); |
| 12226 } finally { | 12195 } finally { |
| 12227 _nameScope = outerScope; | 12196 nameScope = outerScope; |
| 12228 } | 12197 } |
| 12229 } | 12198 } |
| 12230 return null; | 12199 return null; |
| 12231 } | 12200 } |
| 12232 | 12201 |
| 12233 @override | 12202 @override |
| 12234 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 12203 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 12235 Scope outerScope = _nameScope; | 12204 Scope outerScope = nameScope; |
| 12236 try { | 12205 try { |
| 12237 _nameScope = new FunctionTypeScope(_nameScope, node.element); | 12206 nameScope = new FunctionTypeScope(nameScope, node.element); |
| 12238 super.visitFunctionTypeAlias(node); | 12207 super.visitFunctionTypeAlias(node); |
| 12239 } finally { | 12208 } finally { |
| 12240 _nameScope = outerScope; | 12209 nameScope = outerScope; |
| 12241 } | 12210 } |
| 12242 return null; | 12211 return null; |
| 12243 } | 12212 } |
| 12244 | 12213 |
| 12245 @override | 12214 @override |
| 12246 Object visitIfStatement(IfStatement node) { | 12215 Object visitIfStatement(IfStatement node) { |
| 12247 safelyVisit(node.condition); | 12216 safelyVisit(node.condition); |
| 12248 visitStatementInScope(node.thenStatement); | 12217 visitStatementInScope(node.thenStatement); |
| 12249 visitStatementInScope(node.elseStatement); | 12218 visitStatementInScope(node.elseStatement); |
| 12250 return null; | 12219 return null; |
| 12251 } | 12220 } |
| 12252 | 12221 |
| 12253 @override | 12222 @override |
| 12254 Object visitLabeledStatement(LabeledStatement node) { | 12223 Object visitLabeledStatement(LabeledStatement node) { |
| 12255 LabelScope outerScope = _addScopesFor(node.labels, node.unlabeled); | 12224 LabelScope outerScope = _addScopesFor(node.labels, node.unlabeled); |
| 12256 try { | 12225 try { |
| 12257 super.visitLabeledStatement(node); | 12226 super.visitLabeledStatement(node); |
| 12258 } finally { | 12227 } finally { |
| 12259 _labelScope = outerScope; | 12228 labelScope = outerScope; |
| 12260 } | 12229 } |
| 12261 return null; | 12230 return null; |
| 12262 } | 12231 } |
| 12263 | 12232 |
| 12264 @override | 12233 @override |
| 12265 Object visitMethodDeclaration(MethodDeclaration node) { | 12234 Object visitMethodDeclaration(MethodDeclaration node) { |
| 12266 Scope outerScope = _nameScope; | 12235 Scope outerScope = nameScope; |
| 12267 try { | 12236 try { |
| 12268 ExecutableElement methodElement = node.element; | 12237 ExecutableElement methodElement = node.element; |
| 12269 if (methodElement == null) { | 12238 if (methodElement == null) { |
| 12270 AnalysisEngine.instance.logger.logInformation( | 12239 AnalysisEngine.instance.logger.logInformation( |
| 12271 "Missing element for method ${node.name.name} in ${definingLibrary.s
ource.fullName}", | 12240 "Missing element for method ${node.name.name} in ${definingLibrary.s
ource.fullName}", |
| 12272 new CaughtException(new AnalysisException(), null)); | 12241 new CaughtException(new AnalysisException(), null)); |
| 12273 } else { | 12242 } else { |
| 12274 _nameScope = new FunctionScope(_nameScope, methodElement); | 12243 nameScope = new FunctionScope(nameScope, methodElement); |
| 12275 } | 12244 } |
| 12276 super.visitMethodDeclaration(node); | 12245 super.visitMethodDeclaration(node); |
| 12277 } finally { | 12246 } finally { |
| 12278 _nameScope = outerScope; | 12247 nameScope = outerScope; |
| 12279 } | 12248 } |
| 12280 return null; | 12249 return null; |
| 12281 } | 12250 } |
| 12282 | 12251 |
| 12283 /** | 12252 /** |
| 12284 * Visit the given statement after it's scope has been created. This is used b
y ResolverVisitor to | 12253 * Visit the given statement after it's scope has been created. This is used b
y ResolverVisitor to |
| 12285 * correctly visit the 'then' and 'else' statements of an 'if' statement. | 12254 * correctly visit the 'then' and 'else' statements of an 'if' statement. |
| 12286 * | 12255 * |
| 12287 * @param node the statement to be visited | 12256 * @param node the statement to be visited |
| 12288 */ | 12257 */ |
| 12289 void visitStatementInScope(Statement node) { | 12258 void visitStatementInScope(Statement node) { |
| 12290 if (node is Block) { | 12259 if (node is Block) { |
| 12291 // Don't create a scope around a block because the block will create it's | 12260 // Don't create a scope around a block because the block will create it's |
| 12292 // own scope. | 12261 // own scope. |
| 12293 visitBlock(node); | 12262 visitBlock(node); |
| 12294 } else if (node != null) { | 12263 } else if (node != null) { |
| 12295 Scope outerNameScope = _nameScope; | 12264 Scope outerNameScope = nameScope; |
| 12296 try { | 12265 try { |
| 12297 _nameScope = new EnclosedScope(_nameScope); | 12266 nameScope = new EnclosedScope(nameScope); |
| 12298 node.accept(this); | 12267 node.accept(this); |
| 12299 } finally { | 12268 } finally { |
| 12300 _nameScope = outerNameScope; | 12269 nameScope = outerNameScope; |
| 12301 } | 12270 } |
| 12302 } | 12271 } |
| 12303 } | 12272 } |
| 12304 | 12273 |
| 12305 @override | 12274 @override |
| 12306 Object visitSwitchCase(SwitchCase node) { | 12275 Object visitSwitchCase(SwitchCase node) { |
| 12307 node.expression.accept(this); | 12276 node.expression.accept(this); |
| 12308 Scope outerNameScope = _nameScope; | 12277 Scope outerNameScope = nameScope; |
| 12309 try { | 12278 try { |
| 12310 _nameScope = new EnclosedScope(_nameScope); | 12279 nameScope = new EnclosedScope(nameScope); |
| 12311 node.statements.accept(this); | 12280 node.statements.accept(this); |
| 12312 } finally { | 12281 } finally { |
| 12313 _nameScope = outerNameScope; | 12282 nameScope = outerNameScope; |
| 12314 } | 12283 } |
| 12315 return null; | 12284 return null; |
| 12316 } | 12285 } |
| 12317 | 12286 |
| 12318 @override | 12287 @override |
| 12319 Object visitSwitchDefault(SwitchDefault node) { | 12288 Object visitSwitchDefault(SwitchDefault node) { |
| 12320 Scope outerNameScope = _nameScope; | 12289 Scope outerNameScope = nameScope; |
| 12321 try { | 12290 try { |
| 12322 _nameScope = new EnclosedScope(_nameScope); | 12291 nameScope = new EnclosedScope(nameScope); |
| 12323 node.statements.accept(this); | 12292 node.statements.accept(this); |
| 12324 } finally { | 12293 } finally { |
| 12325 _nameScope = outerNameScope; | 12294 nameScope = outerNameScope; |
| 12326 } | 12295 } |
| 12327 return null; | 12296 return null; |
| 12328 } | 12297 } |
| 12329 | 12298 |
| 12330 @override | 12299 @override |
| 12331 Object visitSwitchStatement(SwitchStatement node) { | 12300 Object visitSwitchStatement(SwitchStatement node) { |
| 12332 LabelScope outerScope = _labelScope; | 12301 LabelScope outerScope = labelScope; |
| 12333 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; | 12302 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 12334 try { | 12303 try { |
| 12335 _implicitLabelScope = _implicitLabelScope.nest(node); | 12304 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 12336 for (SwitchMember member in node.members) { | 12305 for (SwitchMember member in node.members) { |
| 12337 for (Label label in member.labels) { | 12306 for (Label label in member.labels) { |
| 12338 SimpleIdentifier labelName = label.label; | 12307 SimpleIdentifier labelName = label.label; |
| 12339 LabelElement labelElement = labelName.staticElement as LabelElement; | 12308 LabelElement labelElement = labelName.staticElement as LabelElement; |
| 12340 _labelScope = | 12309 labelScope = |
| 12341 new LabelScope(_labelScope, labelName.name, member, labelElement); | 12310 new LabelScope(labelScope, labelName.name, member, labelElement); |
| 12342 } | 12311 } |
| 12343 } | 12312 } |
| 12344 super.visitSwitchStatement(node); | 12313 super.visitSwitchStatement(node); |
| 12345 } finally { | 12314 } finally { |
| 12346 _labelScope = outerScope; | 12315 labelScope = outerScope; |
| 12347 _implicitLabelScope = outerImplicitScope; | 12316 _implicitLabelScope = outerImplicitScope; |
| 12348 } | 12317 } |
| 12349 return null; | 12318 return null; |
| 12350 } | 12319 } |
| 12351 | 12320 |
| 12352 @override | 12321 @override |
| 12353 Object visitVariableDeclaration(VariableDeclaration node) { | 12322 Object visitVariableDeclaration(VariableDeclaration node) { |
| 12354 super.visitVariableDeclaration(node); | 12323 super.visitVariableDeclaration(node); |
| 12355 if (node.parent.parent is! TopLevelVariableDeclaration && | 12324 if (node.parent.parent is! TopLevelVariableDeclaration && |
| 12356 node.parent.parent is! FieldDeclaration) { | 12325 node.parent.parent is! FieldDeclaration) { |
| 12357 VariableElement element = node.element; | 12326 VariableElement element = node.element; |
| 12358 if (element != null) { | 12327 if (element != null) { |
| 12359 _nameScope.define(element); | 12328 nameScope.define(element); |
| 12360 } | 12329 } |
| 12361 } | 12330 } |
| 12362 return null; | 12331 return null; |
| 12363 } | 12332 } |
| 12364 | 12333 |
| 12365 @override | 12334 @override |
| 12366 Object visitWhileStatement(WhileStatement node) { | 12335 Object visitWhileStatement(WhileStatement node) { |
| 12367 safelyVisit(node.condition); | 12336 safelyVisit(node.condition); |
| 12368 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; | 12337 ImplicitLabelScope outerImplicitScope = _implicitLabelScope; |
| 12369 try { | 12338 try { |
| 12370 _implicitLabelScope = _implicitLabelScope.nest(node); | 12339 _implicitLabelScope = _implicitLabelScope.nest(node); |
| 12371 visitStatementInScope(node.body); | 12340 visitStatementInScope(node.body); |
| 12372 } finally { | 12341 } finally { |
| 12373 _implicitLabelScope = outerImplicitScope; | 12342 _implicitLabelScope = outerImplicitScope; |
| 12374 } | 12343 } |
| 12375 return null; | 12344 return null; |
| 12376 } | 12345 } |
| 12377 | 12346 |
| 12378 /** | 12347 /** |
| 12379 * Add scopes for each of the given labels. | 12348 * Add scopes for each of the given labels. |
| 12380 * | 12349 * |
| 12381 * @param labels the labels for which new scopes are to be added | 12350 * @param labels the labels for which new scopes are to be added |
| 12382 * @return the scope that was in effect before the new scopes were added | 12351 * @return the scope that was in effect before the new scopes were added |
| 12383 */ | 12352 */ |
| 12384 LabelScope _addScopesFor(NodeList<Label> labels, AstNode node) { | 12353 LabelScope _addScopesFor(NodeList<Label> labels, AstNode node) { |
| 12385 LabelScope outerScope = _labelScope; | 12354 LabelScope outerScope = labelScope; |
| 12386 for (Label label in labels) { | 12355 for (Label label in labels) { |
| 12387 SimpleIdentifier labelNameNode = label.label; | 12356 SimpleIdentifier labelNameNode = label.label; |
| 12388 String labelName = labelNameNode.name; | 12357 String labelName = labelNameNode.name; |
| 12389 LabelElement labelElement = labelNameNode.staticElement as LabelElement; | 12358 LabelElement labelElement = labelNameNode.staticElement as LabelElement; |
| 12390 _labelScope = new LabelScope(_labelScope, labelName, node, labelElement); | 12359 labelScope = new LabelScope(labelScope, labelName, node, labelElement); |
| 12391 } | 12360 } |
| 12392 return outerScope; | 12361 return outerScope; |
| 12393 } | 12362 } |
| 12394 | 12363 |
| 12395 /** | 12364 /** |
| 12396 * Marks the local declarations of the given [Block] hidden in the enclosing s
cope. | 12365 * Marks the local declarations of the given [Block] hidden in the enclosing s
cope. |
| 12397 * According to the scoping rules name is hidden if block defines it, but name
is defined after | 12366 * According to the scoping rules name is hidden if block defines it, but name
is defined after |
| 12398 * its declaration statement. | 12367 * its declaration statement. |
| 12399 */ | 12368 */ |
| 12400 void _hideNamesDefinedInBlock(EnclosedScope scope, Block block) { | 12369 void _hideNamesDefinedInBlock(EnclosedScope scope, Block block) { |
| (...skipping 3005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15406 } | 15375 } |
| 15407 | 15376 |
| 15408 bool isCatchException(LocalVariableElement element) { | 15377 bool isCatchException(LocalVariableElement element) { |
| 15409 return catchExceptionElements.contains(element); | 15378 return catchExceptionElements.contains(element); |
| 15410 } | 15379 } |
| 15411 | 15380 |
| 15412 bool isCatchStackTrace(LocalVariableElement element) { | 15381 bool isCatchStackTrace(LocalVariableElement element) { |
| 15413 return catchStackTraceElements.contains(element); | 15382 return catchStackTraceElements.contains(element); |
| 15414 } | 15383 } |
| 15415 } | 15384 } |
| OLD | NEW |