| 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 11059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11070 * The object keeping track of which elements have had their types overridden. | 11070 * The object keeping track of which elements have had their types overridden. |
| 11071 */ | 11071 */ |
| 11072 TypeOverrideManager _overrideManager = new TypeOverrideManager(); | 11072 TypeOverrideManager _overrideManager = new TypeOverrideManager(); |
| 11073 | 11073 |
| 11074 /** | 11074 /** |
| 11075 * The object keeping track of which elements have had their types promoted. | 11075 * The object keeping track of which elements have had their types promoted. |
| 11076 */ | 11076 */ |
| 11077 TypePromotionManager _promoteManager = new TypePromotionManager(); | 11077 TypePromotionManager _promoteManager = new TypePromotionManager(); |
| 11078 | 11078 |
| 11079 /** | 11079 /** |
| 11080 * A comment before a function should be resolved in the context of the |
| 11081 * function. But when we incrementally resolve a comment, we don't want to |
| 11082 * resolve the whole function. |
| 11083 * |
| 11084 * So, this flag is set to `true`, when just context of the function should |
| 11085 * be built and the comment resolved. |
| 11086 */ |
| 11087 bool resolveOnlyCommentInFunctionBody = false; |
| 11088 |
| 11089 /** |
| 11080 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 11090 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 11081 * | 11091 * |
| 11082 * @param library the library containing the compilation unit being resolved | 11092 * @param library the library containing the compilation unit being resolved |
| 11083 * @param source the source representing the compilation unit being visited | 11093 * @param source the source representing the compilation unit being visited |
| 11084 * @param typeProvider the object used to access the types from the core libra
ry | 11094 * @param typeProvider the object used to access the types from the core libra
ry |
| 11085 */ | 11095 */ |
| 11086 ResolverVisitor.con1(Library library, Source source, | 11096 ResolverVisitor.con1(Library library, Source source, |
| 11087 TypeProvider typeProvider) | 11097 TypeProvider typeProvider) |
| 11088 : super.con1(library, source, typeProvider) { | 11098 : super.con1(library, source, typeProvider) { |
| 11089 this._inheritanceManager = library.inheritanceManager; | 11099 this._inheritanceManager = library.inheritanceManager; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11499 Object visitCommentReference(CommentReference node) { | 11509 Object visitCommentReference(CommentReference node) { |
| 11500 // | 11510 // |
| 11501 // We do not visit the identifier because it needs to be visited in the | 11511 // We do not visit the identifier because it needs to be visited in the |
| 11502 // context of the reference. | 11512 // context of the reference. |
| 11503 // | 11513 // |
| 11504 node.accept(_elementResolver); | 11514 node.accept(_elementResolver); |
| 11505 node.accept(_typeAnalyzer); | 11515 node.accept(_typeAnalyzer); |
| 11506 return null; | 11516 return null; |
| 11507 } | 11517 } |
| 11508 | 11518 |
| 11519 /** |
| 11520 * Prepares this [ResolverVisitor] to using it for incremental resolution. |
| 11521 */ |
| 11522 void initForIncrementalResolution() { |
| 11523 _overrideManager.enterScope(); |
| 11524 } |
| 11525 |
| 11509 @override | 11526 @override |
| 11510 Object visitCompilationUnit(CompilationUnit node) { | 11527 Object visitCompilationUnit(CompilationUnit node) { |
| 11511 // | 11528 // |
| 11512 // TODO(brianwilkerson) The goal of the code below is to visit the | 11529 // TODO(brianwilkerson) The goal of the code below is to visit the |
| 11513 // declarations in such an order that we can infer type information for | 11530 // declarations in such an order that we can infer type information for |
| 11514 // top-level variables before we visit references to them. This is better | 11531 // top-level variables before we visit references to them. This is better |
| 11515 // than making no effort, but still doesn't completely satisfy that goal | 11532 // than making no effort, but still doesn't completely satisfy that goal |
| 11516 // (consider for example "final var a = b; final var b = 0;"; we'll infer a | 11533 // (consider for example "final var a = b; final var b = 0;"; we'll infer a |
| 11517 // type of 'int' for 'b', but not for 'a' because of the order of the | 11534 // type of 'int' for 'b', but not for 'a' because of the order of the |
| 11518 // visits). Ideally we would create a dependency graph, but that would | 11535 // visits). Ideally we would create a dependency graph, but that would |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11652 _overrideManager.exitScope(); | 11669 _overrideManager.exitScope(); |
| 11653 } | 11670 } |
| 11654 // TODO(brianwilkerson) If the loop can only be exited because the condition | 11671 // TODO(brianwilkerson) If the loop can only be exited because the condition |
| 11655 // is false, then propagateFalseState(node.getCondition()); | 11672 // is false, then propagateFalseState(node.getCondition()); |
| 11656 return null; | 11673 return null; |
| 11657 } | 11674 } |
| 11658 | 11675 |
| 11659 @override | 11676 @override |
| 11660 Object visitEmptyFunctionBody(EmptyFunctionBody node) { | 11677 Object visitEmptyFunctionBody(EmptyFunctionBody node) { |
| 11661 safelyVisit(_commentBeforeFunction); | 11678 safelyVisit(_commentBeforeFunction); |
| 11679 if (resolveOnlyCommentInFunctionBody) { |
| 11680 return null; |
| 11681 } |
| 11662 return super.visitEmptyFunctionBody(node); | 11682 return super.visitEmptyFunctionBody(node); |
| 11663 } | 11683 } |
| 11664 | 11684 |
| 11665 @override | 11685 @override |
| 11666 Object visitEnumDeclaration(EnumDeclaration node) { | 11686 Object visitEnumDeclaration(EnumDeclaration node) { |
| 11667 // | 11687 // |
| 11668 // Resolve the metadata in the library scope. | 11688 // Resolve the metadata in the library scope. |
| 11669 // | 11689 // |
| 11670 if (node.metadata != null) { | 11690 if (node.metadata != null) { |
| 11671 node.metadata.accept(this); | 11691 node.metadata.accept(this); |
| 11672 } | 11692 } |
| 11673 // | 11693 // |
| 11674 // There is nothing else to do because everything else was resolved by the | 11694 // There is nothing else to do because everything else was resolved by the |
| 11675 // element builder. | 11695 // element builder. |
| 11676 // | 11696 // |
| 11677 return null; | 11697 return null; |
| 11678 } | 11698 } |
| 11679 | 11699 |
| 11680 @override | 11700 @override |
| 11681 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { | 11701 Object visitExpressionFunctionBody(ExpressionFunctionBody node) { |
| 11682 safelyVisit(_commentBeforeFunction); | 11702 safelyVisit(_commentBeforeFunction); |
| 11703 if (resolveOnlyCommentInFunctionBody) { |
| 11704 return null; |
| 11705 } |
| 11683 _overrideManager.enterScope(); | 11706 _overrideManager.enterScope(); |
| 11684 try { | 11707 try { |
| 11685 super.visitExpressionFunctionBody(node); | 11708 super.visitExpressionFunctionBody(node); |
| 11686 } finally { | 11709 } finally { |
| 11687 _overrideManager.exitScope(); | 11710 _overrideManager.exitScope(); |
| 11688 } | 11711 } |
| 11689 return null; | 11712 return null; |
| 11690 } | 11713 } |
| 11691 | 11714 |
| 11692 @override | 11715 @override |
| (...skipping 4593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16286 * library. | 16309 * library. |
| 16287 */ | 16310 */ |
| 16288 final HashSet<String> members = new HashSet<String>(); | 16311 final HashSet<String> members = new HashSet<String>(); |
| 16289 | 16312 |
| 16290 /** | 16313 /** |
| 16291 * Names of resolved or unresolved class members that are read in the | 16314 * Names of resolved or unresolved class members that are read in the |
| 16292 * library. | 16315 * library. |
| 16293 */ | 16316 */ |
| 16294 final HashSet<String> readMembers = new HashSet<String>(); | 16317 final HashSet<String> readMembers = new HashSet<String>(); |
| 16295 } | 16318 } |
| OLD | NEW |