| 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.element_resolver; | 5 library engine.resolver.element_resolver; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import 'ast.dart'; | 9 import 'ast.dart'; |
| 10 import 'element.dart'; | 10 import 'element.dart'; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 * The element for the library containing the compilation unit being visited. | 74 * The element for the library containing the compilation unit being visited. |
| 75 */ | 75 */ |
| 76 LibraryElement _definingLibrary; | 76 LibraryElement _definingLibrary; |
| 77 | 77 |
| 78 /** | 78 /** |
| 79 * A flag indicating whether we should generate hints. | 79 * A flag indicating whether we should generate hints. |
| 80 */ | 80 */ |
| 81 bool _enableHints = false; | 81 bool _enableHints = false; |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * A flag indicating whether we should strictly follow the specification when |
| 85 * generating warnings on "call" methods (fixes dartbug.com/21938). |
| 86 */ |
| 87 bool _enableStrictCallChecks = false; |
| 88 |
| 89 /** |
| 84 * The type representing the type 'dynamic'. | 90 * The type representing the type 'dynamic'. |
| 85 */ | 91 */ |
| 86 DartType _dynamicType; | 92 DartType _dynamicType; |
| 87 | 93 |
| 88 /** | 94 /** |
| 89 * The type representing the type 'type'. | 95 * The type representing the type 'type'. |
| 90 */ | 96 */ |
| 91 DartType _typeType; | 97 DartType _typeType; |
| 92 | 98 |
| 93 /** | 99 /** |
| 94 * A utility class for the resolver to answer the question of "what are my sub
types?". | 100 * A utility class for the resolver to answer the question of "what are my sub
types?". |
| 95 */ | 101 */ |
| 96 SubtypeManager _subtypeManager; | 102 SubtypeManager _subtypeManager; |
| 97 | 103 |
| 98 /** | 104 /** |
| 99 * The object keeping track of which elements have had their types promoted. | 105 * The object keeping track of which elements have had their types promoted. |
| 100 */ | 106 */ |
| 101 TypePromotionManager _promoteManager; | 107 TypePromotionManager _promoteManager; |
| 102 | 108 |
| 103 /** | 109 /** |
| 104 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. | 110 * Initialize a newly created visitor to resolve the nodes in a compilation un
it. |
| 105 * | 111 * |
| 106 * @param resolver the resolver driving this participant | 112 * @param resolver the resolver driving this participant |
| 107 */ | 113 */ |
| 108 ElementResolver(this._resolver) { | 114 ElementResolver(this._resolver) { |
| 109 this._definingLibrary = _resolver.definingLibrary; | 115 this._definingLibrary = _resolver.definingLibrary; |
| 110 AnalysisOptions options = _definingLibrary.context.analysisOptions; | 116 AnalysisOptions options = _definingLibrary.context.analysisOptions; |
| 111 _enableHints = options.hint; | 117 _enableHints = options.hint; |
| 118 _enableStrictCallChecks = options.enableStrictCallChecks; |
| 112 _dynamicType = _resolver.typeProvider.dynamicType; | 119 _dynamicType = _resolver.typeProvider.dynamicType; |
| 113 _typeType = _resolver.typeProvider.typeType; | 120 _typeType = _resolver.typeProvider.typeType; |
| 114 _subtypeManager = new SubtypeManager(); | 121 _subtypeManager = new SubtypeManager(); |
| 115 _promoteManager = _resolver.promoteManager; | 122 _promoteManager = _resolver.promoteManager; |
| 116 } | 123 } |
| 117 | 124 |
| 118 /** | 125 /** |
| 119 * @return `true` iff current enclosing function is constant constructor decla
ration. | 126 * @return `true` iff current enclosing function is constant constructor decla
ration. |
| 120 */ | 127 */ |
| 121 bool get isInConstConstructor { | 128 bool get isInConstConstructor { |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 DartType targetType = null; | 695 DartType targetType = null; |
| 689 if (!generatedWithTypePropagation) { | 696 if (!generatedWithTypePropagation) { |
| 690 targetType = _getStaticType(target); | 697 targetType = _getStaticType(target); |
| 691 } else { | 698 } else { |
| 692 // choose the best type | 699 // choose the best type |
| 693 targetType = _getPropagatedType(target); | 700 targetType = _getPropagatedType(target); |
| 694 if (targetType == null) { | 701 if (targetType == null) { |
| 695 targetType = _getStaticType(target); | 702 targetType = _getStaticType(target); |
| 696 } | 703 } |
| 697 } | 704 } |
| 698 if (targetType != null && | 705 if (!_enableStrictCallChecks && |
| 706 targetType != null && |
| 699 targetType.isDartCoreFunction && | 707 targetType.isDartCoreFunction && |
| 700 methodName.name == FunctionElement.CALL_METHOD_NAME) { | 708 methodName.name == FunctionElement.CALL_METHOD_NAME) { |
| 701 // TODO(brianwilkerson) Can we ever resolve the function being | 709 // TODO(brianwilkerson) Can we ever resolve the function being |
| 702 // invoked? | 710 // invoked? |
| 703 // resolveArgumentsToParameters(node.getArgumentList(), invokedFunction
); | 711 // resolveArgumentsToParameters(node.getArgumentList(), invokedFunction
); |
| 704 return null; | 712 return null; |
| 705 } | 713 } |
| 706 targetTypeName = targetType == null ? null : targetType.displayName; | 714 targetTypeName = targetType == null ? null : targetType.displayName; |
| 707 ErrorCode proxyErrorCode = (generatedWithTypePropagation | 715 ErrorCode proxyErrorCode = (generatedWithTypePropagation |
| 708 ? HintCode.UNDEFINED_METHOD | 716 ? HintCode.UNDEFINED_METHOD |
| (...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1465 } | 1473 } |
| 1466 | 1474 |
| 1467 /** | 1475 /** |
| 1468 * Return `true` if the given type represents an object that could be invoked
using the call | 1476 * Return `true` if the given type represents an object that could be invoked
using the call |
| 1469 * operator '()'. | 1477 * operator '()'. |
| 1470 * | 1478 * |
| 1471 * @param type the type being tested | 1479 * @param type the type being tested |
| 1472 * @return `true` if the given type represents an object that could be invoked | 1480 * @return `true` if the given type represents an object that could be invoked |
| 1473 */ | 1481 */ |
| 1474 bool _isExecutableType(DartType type) { | 1482 bool _isExecutableType(DartType type) { |
| 1475 if (type.isDynamic || | 1483 if (type.isDynamic || type is FunctionType) { |
| 1476 (type is FunctionType) || | 1484 return true; |
| 1477 type.isDartCoreFunction || | 1485 } else if (!_enableStrictCallChecks && |
| 1478 type.isObject) { | 1486 (type.isDartCoreFunction || type.isObject)) { |
| 1479 return true; | 1487 return true; |
| 1480 } else if (type is InterfaceType) { | 1488 } else if (type is InterfaceType) { |
| 1481 ClassElement classElement = type.element; | 1489 ClassElement classElement = type.element; |
| 1482 // 16078 from Gilad: If the type is a Functor with the @proxy annotation, | 1490 // 16078 from Gilad: If the type is a Functor with the @proxy annotation, |
| 1483 // treat it as an executable type. | 1491 // treat it as an executable type. |
| 1484 // example code: NonErrorResolverTest. | 1492 // example code: NonErrorResolverTest. |
| 1485 // test_invocationOfNonFunction_proxyOnFunctionClass() | 1493 // test_invocationOfNonFunction_proxyOnFunctionClass() |
| 1486 if (classElement.isProxy && | 1494 if (classElement.isProxy && |
| 1487 type.isSubtypeOf(_resolver.typeProvider.functionType)) { | 1495 type.isSubtypeOf(_resolver.typeProvider.functionType)) { |
| 1488 return true; | 1496 return true; |
| (...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2572 bool isStaticProperty = _isStatic(staticOrPropagatedEnclosingElt); | 2580 bool isStaticProperty = _isStatic(staticOrPropagatedEnclosingElt); |
| 2573 DartType displayType = staticOrPropagatedType != null | 2581 DartType displayType = staticOrPropagatedType != null |
| 2574 ? staticOrPropagatedType | 2582 ? staticOrPropagatedType |
| 2575 : propagatedType != null ? propagatedType : staticType; | 2583 : propagatedType != null ? propagatedType : staticType; |
| 2576 // Special getter cases. | 2584 // Special getter cases. |
| 2577 if (propertyName.inGetterContext()) { | 2585 if (propertyName.inGetterContext()) { |
| 2578 if (!isStaticProperty && | 2586 if (!isStaticProperty && |
| 2579 staticOrPropagatedEnclosingElt is ClassElement) { | 2587 staticOrPropagatedEnclosingElt is ClassElement) { |
| 2580 ClassElement classElement = staticOrPropagatedEnclosingElt; | 2588 ClassElement classElement = staticOrPropagatedEnclosingElt; |
| 2581 InterfaceType targetType = classElement.type; | 2589 InterfaceType targetType = classElement.type; |
| 2582 if (targetType != null && | 2590 if (!_enableStrictCallChecks && |
| 2591 targetType != null && |
| 2583 targetType.isDartCoreFunction && | 2592 targetType.isDartCoreFunction && |
| 2584 propertyName.name == FunctionElement.CALL_METHOD_NAME) { | 2593 propertyName.name == FunctionElement.CALL_METHOD_NAME) { |
| 2585 // TODO(brianwilkerson) Can we ever resolve the function being | 2594 // TODO(brianwilkerson) Can we ever resolve the function being |
| 2586 // invoked? | 2595 // invoked? |
| 2587 // resolveArgumentsToParameters(node.getArgumentList(), invokedFuncti
on); | 2596 // resolveArgumentsToParameters(node.getArgumentList(), invokedFuncti
on); |
| 2588 return; | 2597 return; |
| 2589 } else if (classElement.isEnum && propertyName.name == "_name") { | 2598 } else if (classElement.isEnum && propertyName.name == "_name") { |
| 2590 _resolver.reportErrorForNode( | 2599 _resolver.reportErrorForNode( |
| 2591 CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD, propertyName, [ | 2600 CompileTimeErrorCode.ACCESS_PRIVATE_ENUM_FIELD, propertyName, [ |
| 2592 propertyName.name | 2601 propertyName.name |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3013 | 3022 |
| 3014 @override | 3023 @override |
| 3015 Element get staticElement => null; | 3024 Element get staticElement => null; |
| 3016 | 3025 |
| 3017 @override | 3026 @override |
| 3018 accept(AstVisitor visitor) => null; | 3027 accept(AstVisitor visitor) => null; |
| 3019 | 3028 |
| 3020 @override | 3029 @override |
| 3021 void visitChildren(AstVisitor visitor) {} | 3030 void visitChildren(AstVisitor visitor) {} |
| 3022 } | 3031 } |
| OLD | NEW |