| 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 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 /// internally skipped. These initializers are fully resolved and don't need | 444 /// internally skipped. These initializers are fully resolved and don't need |
| 445 /// to be re-resolved on a sunsequent pass. | 445 /// to be re-resolved on a sunsequent pass. |
| 446 final _visitedInitializers = new Set<VariableDeclaration>(); | 446 final _visitedInitializers = new Set<VariableDeclaration>(); |
| 447 | 447 |
| 448 RestrictedResolverVisitor(Library library, Source source, | 448 RestrictedResolverVisitor(Library library, Source source, |
| 449 TypeProvider typeProvider, ResolverOptions options) | 449 TypeProvider typeProvider, ResolverOptions options) |
| 450 : _typeProvider = typeProvider, | 450 : _typeProvider = typeProvider, |
| 451 super.con1(library, source, typeProvider, | 451 super.con1(library, source, typeProvider, |
| 452 typeAnalyzerFactory: RestrictedStaticTypeAnalyzer.constructor); | 452 typeAnalyzerFactory: RestrictedStaticTypeAnalyzer.constructor); |
| 453 | 453 |
| 454 @override | |
| 455 visitCatchClause(CatchClause node) { | |
| 456 var stack = node.stackTraceParameter; | |
| 457 if (stack != null) { | |
| 458 // TODO(jmesserly): analyzer does not correctly associate StackTrace type. | |
| 459 // It happens too late in TypeResolverVisitor visitCatchClause. | |
| 460 var element = stack.staticElement; | |
| 461 if (element is VariableElementImpl && element.type == null) { | |
| 462 // From the language spec: | |
| 463 // The static type of p1 is T and the static type of p2 is StackTrace. | |
| 464 element.type = _typeProvider.stackTraceType; | |
| 465 } | |
| 466 } | |
| 467 return super.visitCatchClause(node); | |
| 468 } | |
| 469 | |
| 470 reanalyzeInitializer(VariableDeclaration variable) { | 454 reanalyzeInitializer(VariableDeclaration variable) { |
| 471 try { | 455 try { |
| 472 _revisiting = true; | 456 _revisiting = true; |
| 473 _nodeWasSkipped = false; | 457 _nodeWasSkipped = false; |
| 474 var node = variable.parent.parent; | 458 var node = variable.parent.parent; |
| 475 var oldState; | 459 var oldState; |
| 476 var state = _stateAtDeclaration[node]; | 460 var state = _stateAtDeclaration[node]; |
| 477 if (state != null) { | 461 if (state != null) { |
| 478 oldState = new _ResolverState(this); | 462 oldState = new _ResolverState(this); |
| 479 state.restore(this); | 463 state.restore(this); |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 _typeProvider.doubleType, | 685 _typeProvider.doubleType, |
| 702 _typeProvider.boolType, | 686 _typeProvider.boolType, |
| 703 _typeProvider.stringType | 687 _typeProvider.stringType |
| 704 ]; | 688 ]; |
| 705 } | 689 } |
| 706 return _sealedTypes.contains(t); | 690 return _sealedTypes.contains(t); |
| 707 } | 691 } |
| 708 | 692 |
| 709 @override // to propagate types to identifiers | 693 @override // to propagate types to identifiers |
| 710 visitMethodInvocation(MethodInvocation node) { | 694 visitMethodInvocation(MethodInvocation node) { |
| 711 // TODO(sigmund): follow up with analyzer team - why is this needed? | 695 // TODO(jmesserly): we rely on having a staticType propagated to the |
| 696 // methodName identifier. This shouldn't be necessary for method calls, so |
| 697 // analyzer doesn't do it by default. Conceptually what we're doing here |
| 698 // is asking for a tear off. We need this until we can fix #132, and rely |
| 699 // on `node.staticElement == null` instead of `rules.isDynamicCall(node)`. |
| 712 visitSimpleIdentifier(node.methodName); | 700 visitSimpleIdentifier(node.methodName); |
| 701 |
| 713 super.visitMethodInvocation(node); | 702 super.visitMethodInvocation(node); |
| 714 | 703 |
| 715 // Search for Object methods. | 704 // Search for Object methods. |
| 716 var objectMap = _getObjectMemberMap(); | 705 var objectMap = _getObjectMemberMap(); |
| 717 var name = node.methodName.name; | 706 var name = node.methodName.name; |
| 718 if (node.staticType.isDynamic && | 707 if (node.staticType.isDynamic && |
| 719 objectMap.containsKey(name) && | 708 objectMap.containsKey(name) && |
| 720 isDynamicTarget(node.target)) { | 709 isDynamicTarget(node.target)) { |
| 721 var type = objectMap[name]; | 710 var type = objectMap[name]; |
| 722 if (type is FunctionType && node.argumentList.arguments.isEmpty) { | 711 if (type is FunctionType && node.argumentList.arguments.isEmpty) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 } | 791 } |
| 803 } | 792 } |
| 804 | 793 |
| 805 // Review note: no longer need to override visitFunctionExpression, this is | 794 // Review note: no longer need to override visitFunctionExpression, this is |
| 806 // handled by the analyzer internally. | 795 // handled by the analyzer internally. |
| 807 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 796 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
| 808 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 797 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
| 809 // type in a (...) => expr or just the written type? | 798 // type in a (...) => expr or just the written type? |
| 810 | 799 |
| 811 } | 800 } |
| OLD | NEW |