| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 /// Encapsulates how to invoke the analyzer resolver and overrides how it | 5 /// Encapsulates how to invoke the analyzer resolver and overrides how it |
| 6 /// computes types on expressions to use our restricted set of types. | 6 /// computes types on expressions to use our restricted set of types. |
| 7 library dev_compiler.src.checker.resolver; | 7 library dev_compiler.src.checker.resolver; |
| 8 | 8 |
| 9 import 'package:analyzer/analyzer.dart'; | 9 import 'package:analyzer/analyzer.dart'; |
| 10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
| (...skipping 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 return null; | 523 return null; |
| 524 } | 524 } |
| 525 if (_visitedInitializers.contains(node)) return null; | 525 if (_visitedInitializers.contains(node)) return null; |
| 526 assert(node is! Statement || !skipMethodBodies); | 526 assert(node is! Statement || !skipMethodBodies); |
| 527 return super.visitNode(node); | 527 return super.visitNode(node); |
| 528 } | 528 } |
| 529 | 529 |
| 530 @override | 530 @override |
| 531 Object visitMethodDeclaration(MethodDeclaration node) { | 531 Object visitMethodDeclaration(MethodDeclaration node) { |
| 532 if (skipMethodBodies) { | 532 if (skipMethodBodies) { |
| 533 node.accept(elementResolver_J2DAccessor); | 533 node.accept(elementResolver); |
| 534 node.accept(typeAnalyzer_J2DAccessor); | 534 node.accept(typeAnalyzer); |
| 535 return null; | 535 return null; |
| 536 } else { | 536 } else { |
| 537 return super.visitMethodDeclaration(node); | 537 return super.visitMethodDeclaration(node); |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 | 540 |
| 541 @override | 541 @override |
| 542 Object visitFunctionDeclaration(FunctionDeclaration node) { | 542 Object visitFunctionDeclaration(FunctionDeclaration node) { |
| 543 if (skipMethodBodies) { | 543 if (skipMethodBodies) { |
| 544 node.accept(elementResolver_J2DAccessor); | 544 node.accept(elementResolver); |
| 545 node.accept(typeAnalyzer_J2DAccessor); | 545 node.accept(typeAnalyzer); |
| 546 return null; | 546 return null; |
| 547 } else { | 547 } else { |
| 548 return super.visitFunctionDeclaration(node); | 548 return super.visitFunctionDeclaration(node); |
| 549 } | 549 } |
| 550 } | 550 } |
| 551 | 551 |
| 552 @override | 552 @override |
| 553 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 553 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
| 554 if (skipMethodBodies) { | 554 if (skipMethodBodies) { |
| 555 node.accept(elementResolver_J2DAccessor); | 555 node.accept(elementResolver); |
| 556 node.accept(typeAnalyzer_J2DAccessor); | 556 node.accept(typeAnalyzer); |
| 557 return null; | 557 return null; |
| 558 } else { | 558 } else { |
| 559 return super.visitConstructorDeclaration(node); | 559 return super.visitConstructorDeclaration(node); |
| 560 } | 560 } |
| 561 } | 561 } |
| 562 } | 562 } |
| 563 | 563 |
| 564 /// Internal state of the resolver, stored so we can reanalyze portions of the | 564 /// Internal state of the resolver, stored so we can reanalyze portions of the |
| 565 /// AST quickly, without recomputing everything from the top. | 565 /// AST quickly, without recomputing everything from the top. |
| 566 class _ResolverState { | 566 class _ResolverState { |
| 567 final TypePromotionManager_TypePromoteScope promotionScope; | 567 final TypePromotionManager_TypePromoteScope promotionScope; |
| 568 final TypeOverrideManager_TypeOverrideScope overrideScope; | 568 final TypeOverrideManager_TypeOverrideScope overrideScope; |
| 569 final Scope nameScope; | 569 final Scope nameScope; |
| 570 | 570 |
| 571 _ResolverState(ResolverVisitor visitor) | 571 _ResolverState(ResolverVisitor visitor) |
| 572 : promotionScope = visitor.promoteManager.currentScope, | 572 : promotionScope = visitor.promoteManager.currentScope, |
| 573 overrideScope = visitor.overrideManager.currentScope, | 573 overrideScope = visitor.overrideManager.currentScope, |
| 574 nameScope = visitor.nameScope; | 574 nameScope = visitor.nameScope; |
| 575 | 575 |
| 576 void restore(ResolverVisitor visitor) { | 576 void restore(ResolverVisitor visitor) { |
| 577 visitor.promoteManager.currentScope = promotionScope; | 577 visitor.promoteManager.currentScope = promotionScope; |
| 578 visitor.overrideManager.currentScope = overrideScope; | 578 visitor.overrideManager.currentScope = overrideScope; |
| 579 visitor.nameScope_J2DAccessor = nameScope; | 579 visitor.nameScope = nameScope; |
| 580 } | 580 } |
| 581 } | 581 } |
| 582 | 582 |
| 583 /// Overrides the default [StaticTypeAnalyzer] to adjust rules that are stricter | 583 /// Overrides the default [StaticTypeAnalyzer] to adjust rules that are stricter |
| 584 /// in the restricted type system and to infer types for untyped local | 584 /// in the restricted type system and to infer types for untyped local |
| 585 /// variables. | 585 /// variables. |
| 586 class RestrictedStaticTypeAnalyzer extends StaticTypeAnalyzer { | 586 class RestrictedStaticTypeAnalyzer extends StaticTypeAnalyzer { |
| 587 final TypeProvider _typeProvider; | 587 final TypeProvider _typeProvider; |
| 588 | 588 |
| 589 RestrictedStaticTypeAnalyzer(ResolverVisitor r) | 589 RestrictedStaticTypeAnalyzer(ResolverVisitor r) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 | 711 |
| 712 // Review note: no longer need to override visitFunctionExpression, this is | 712 // Review note: no longer need to override visitFunctionExpression, this is |
| 713 // handled by the analyzer internally. | 713 // handled by the analyzer internally. |
| 714 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 714 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
| 715 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 715 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
| 716 // type in a (...) => expr or just the written type? | 716 // type in a (...) => expr or just the written type? |
| 717 | 717 |
| 718 } | 718 } |
| OLD | NEW |