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 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 var extractor = new _VarExtractor(); | 323 var extractor = new _VarExtractor(); |
324 initializer.accept(extractor); | 324 initializer.accept(extractor); |
325 return extractor.elements; | 325 return extractor.elements; |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 /// Overrides the default [ResolverVisitor] to support type inference in | 329 /// Overrides the default [ResolverVisitor] to support type inference in |
330 /// [LibraryResolverWithInference] above. | 330 /// [LibraryResolverWithInference] above. |
331 /// | 331 /// |
332 /// Before inference, this visitor is used to resolve top-levels, classes, and | 332 /// Before inference, this visitor is used to resolve top-levels, classes, and |
333 /// fields, but nothing withihn method bodies. After inference, this visitor is | 333 /// fields, but nothing within method bodies. After inference, this visitor is |
334 /// used again to step into method bodies and complete resolution as a second | 334 /// used again to step into method bodies and complete resolution as a second |
335 /// phase. | 335 /// phase. |
336 class RestrictedResolverVisitor extends ResolverVisitor { | 336 class RestrictedResolverVisitor extends ResolverVisitor { |
337 final TypeProvider _typeProvider; | 337 final TypeProvider _typeProvider; |
338 | 338 |
339 /// Whether to skip resolution within method bodies. | 339 /// Whether to skip resolution within method bodies. |
340 bool skipMethodBodies = true; | 340 bool skipMethodBodies = true; |
341 | 341 |
342 /// State of the resolver at the point a field or variable was declared. | 342 /// State of the resolver at the point a field or variable was declared. |
343 final _stateAtDeclaration = <AstNode, _ResolverState>{}; | 343 final _stateAtDeclaration = <AstNode, _ResolverState>{}; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
446 @override | 446 @override |
447 Object visitConstructorDeclaration(ConstructorDeclaration node) { | 447 Object visitConstructorDeclaration(ConstructorDeclaration node) { |
448 if (skipMethodBodies) { | 448 if (skipMethodBodies) { |
449 node.accept(elementResolver); | 449 node.accept(elementResolver); |
450 node.accept(typeAnalyzer); | 450 node.accept(typeAnalyzer); |
451 return null; | 451 return null; |
452 } else { | 452 } else { |
453 return super.visitConstructorDeclaration(node); | 453 return super.visitConstructorDeclaration(node); |
454 } | 454 } |
455 } | 455 } |
456 | |
457 @override | |
458 visitFieldFormalParameter(FieldFormalParameter node) { | |
459 // Ensure the field formal parameter's type is updated after inference. | |
460 // Normally this happens during TypeResolver, but that's before we've done | |
461 // inference on the field type. | |
Jennifer Messerly
2015/06/10 18:22:19
Is this running at the right time?
In theory, not
Siggi Cherem (dart-lang)
2015/06/10 18:28:30
sgtm. not sure when analyzer does it, but if eleme
| |
462 var element = node.element; | |
463 if (element is FieldFormalParameterElement) { | |
464 if (element.type.isDynamic) { | |
465 element.type = element.field.type; | |
466 } | |
467 } | |
468 super.visitFieldFormalParameter(node); | |
469 } | |
456 } | 470 } |
457 | 471 |
458 /// Internal state of the resolver, stored so we can reanalyze portions of the | 472 /// Internal state of the resolver, stored so we can reanalyze portions of the |
459 /// AST quickly, without recomputing everything from the top. | 473 /// AST quickly, without recomputing everything from the top. |
460 class _ResolverState { | 474 class _ResolverState { |
461 final TypePromotionManager_TypePromoteScope promotionScope; | 475 final TypePromotionManager_TypePromoteScope promotionScope; |
462 final TypeOverrideManager_TypeOverrideScope overrideScope; | 476 final TypeOverrideManager_TypeOverrideScope overrideScope; |
463 final Scope nameScope; | 477 final Scope nameScope; |
464 | 478 |
465 _ResolverState(ResolverVisitor visitor) | 479 _ResolverState(ResolverVisitor visitor) |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 } | 686 } |
673 } | 687 } |
674 | 688 |
675 // Review note: no longer need to override visitFunctionExpression, this is | 689 // Review note: no longer need to override visitFunctionExpression, this is |
676 // handled by the analyzer internally. | 690 // handled by the analyzer internally. |
677 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? | 691 // TODO(vsm): in visitbinaryExpression: check computeStaticReturnType result? |
678 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression | 692 // TODO(vsm): in visitFunctionDeclaration: Should we ever use the expression |
679 // type in a (...) => expr or just the written type? | 693 // type in a (...) => expr or just the written type? |
680 | 694 |
681 } | 695 } |
OLD | NEW |