Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /** | 5 /** |
| 6 * This library is capable of producing linked summaries from unlinked | 6 * This library is capable of producing linked summaries from unlinked |
| 7 * ones (or prelinked ones). It functions by building a miniature | 7 * ones (or prelinked ones). It functions by building a miniature |
| 8 * element model to represent the contents of the summaries, and then | 8 * element model to represent the contents of the summaries, and then |
| 9 * scanning the element model to gather linked information and adding | 9 * scanning the element model to gather linked information and adding |
| 10 * it to the summary data structures. | 10 * it to the summary data structures. |
| (...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2175 | 2175 |
| 2176 void _computeBinaryExpressionType(TokenType operator) { | 2176 void _computeBinaryExpressionType(TokenType operator) { |
| 2177 DartType right = stack.removeLast(); | 2177 DartType right = stack.removeLast(); |
| 2178 DartType left = stack.removeLast(); | 2178 DartType left = stack.removeLast(); |
| 2179 _pushBinaryOperatorType(left, operator, right); | 2179 _pushBinaryOperatorType(left, operator, right); |
| 2180 } | 2180 } |
| 2181 | 2181 |
| 2182 void _computePrefixExpressionType(String operatorName) { | 2182 void _computePrefixExpressionType(String operatorName) { |
| 2183 DartType operand = stack.removeLast(); | 2183 DartType operand = stack.removeLast(); |
| 2184 if (operand is InterfaceType) { | 2184 if (operand is InterfaceType) { |
| 2185 MethodElement method = operand.lookUpMethod(operatorName, library); | 2185 MethodElement method = operand.lookUpInheritedMethod(operatorName, |
| 2186 library: library, thisType: true); | |
|
scheglov
2016/05/25 20:21:21
"thisType" is already true by default.
Paul Berry
2016/05/25 20:28:12
Thanks. Fixed.
| |
| 2186 if (method != null) { | 2187 if (method != null) { |
| 2187 DartType type = method.returnType; | 2188 DartType type = method.returnType; |
| 2188 stack.add(type); | 2189 stack.add(type); |
| 2189 return; | 2190 return; |
| 2190 } | 2191 } |
| 2191 } | 2192 } |
| 2192 stack.add(DynamicTypeImpl.instance); | 2193 stack.add(DynamicTypeImpl.instance); |
| 2193 } | 2194 } |
| 2194 | 2195 |
| 2195 void _doAssignToIndex() { | 2196 void _doAssignToIndex() { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2261 DartType type = _leastUpperBound(thenType, elseType); | 2262 DartType type = _leastUpperBound(thenType, elseType); |
| 2262 type = _dynamicIfNull(type); | 2263 type = _dynamicIfNull(type); |
| 2263 stack.add(type); | 2264 stack.add(type); |
| 2264 } | 2265 } |
| 2265 | 2266 |
| 2266 void _doExtractIndex() { | 2267 void _doExtractIndex() { |
| 2267 stack.removeLast(); // index | 2268 stack.removeLast(); // index |
| 2268 DartType target = stack.removeLast(); | 2269 DartType target = stack.removeLast(); |
| 2269 stack.add(() { | 2270 stack.add(() { |
| 2270 if (target is InterfaceType) { | 2271 if (target is InterfaceType) { |
| 2271 MethodElement method = target.lookUpMethod('[]', library); | 2272 MethodElement method = target.lookUpInheritedMethod('[]', |
| 2273 library: library, thisType: true); | |
| 2272 if (method != null) { | 2274 if (method != null) { |
| 2273 return method.returnType; | 2275 return method.returnType; |
| 2274 } | 2276 } |
| 2275 } | 2277 } |
| 2276 return DynamicTypeImpl.instance; | 2278 return DynamicTypeImpl.instance; |
| 2277 }()); | 2279 }()); |
| 2278 } | 2280 } |
| 2279 | 2281 |
| 2280 void _doExtractProperty() { | 2282 void _doExtractProperty() { |
| 2281 DartType target = stack.removeLast(); | 2283 DartType target = stack.removeLast(); |
| 2282 String propertyName = _getNextString(); | 2284 String propertyName = _getNextString(); |
| 2283 stack.add(() { | 2285 stack.add(() { |
| 2284 if (target is InterfaceType) { | 2286 if (target is InterfaceType) { |
| 2285 PropertyAccessorElement getter = | 2287 ExecutableElement element = target |
| 2286 target.lookUpGetter(propertyName, library); | 2288 .lookUpInheritedGetterOrMethod(propertyName, library: library); |
| 2287 if (getter != null) { | 2289 if (element != null) { |
| 2288 return getter.returnType; | 2290 if (element is PropertyAccessorElement) { |
| 2289 } | 2291 return element.returnType; |
| 2290 MethodElement method = target.lookUpMethod(propertyName, library); | 2292 } else { |
| 2291 if (method != null) { | 2293 // Method tear-off |
| 2292 return method.type; | 2294 return element.type; |
| 2295 } | |
| 2293 } | 2296 } |
| 2294 } | 2297 } |
| 2295 return DynamicTypeImpl.instance; | 2298 return DynamicTypeImpl.instance; |
| 2296 }()); | 2299 }()); |
| 2297 } | 2300 } |
| 2298 | 2301 |
| 2299 void _doInvokeConstructor() { | 2302 void _doInvokeConstructor() { |
| 2300 int numNamed = _getNextInt(); | 2303 int numNamed = _getNextInt(); |
| 2301 int numPositional = _getNextInt(); | 2304 int numPositional = _getNextInt(); |
| 2302 // TODO(paulberry): don't just pop the args; use their types | 2305 // TODO(paulberry): don't just pop the args; use their types |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2327 int numPositional = unlinkedConst.ints[intPtr++]; | 2330 int numPositional = unlinkedConst.ints[intPtr++]; |
| 2328 List<String> namedArgNames = _getNextStrings(numNamed); | 2331 List<String> namedArgNames = _getNextStrings(numNamed); |
| 2329 List<DartType> namedArgTypeList = _popList(numNamed); | 2332 List<DartType> namedArgTypeList = _popList(numNamed); |
| 2330 List<DartType> positionalArgTypes = _popList(numPositional); | 2333 List<DartType> positionalArgTypes = _popList(numPositional); |
| 2331 // TODO(scheglov) if we pushed target and method name first, we might be | 2334 // TODO(scheglov) if we pushed target and method name first, we might be |
| 2332 // able to move work with arguments in _inferExecutableType() | 2335 // able to move work with arguments in _inferExecutableType() |
| 2333 String methodName = _getNextString(); | 2336 String methodName = _getNextString(); |
| 2334 DartType target = stack.removeLast(); | 2337 DartType target = stack.removeLast(); |
| 2335 stack.add(() { | 2338 stack.add(() { |
| 2336 if (target is InterfaceType) { | 2339 if (target is InterfaceType) { |
| 2337 MethodElement method = target.lookUpMethod(methodName, library); | 2340 MethodElement method = target.lookUpInheritedMethod(methodName, |
| 2341 library: library, thisType: true); | |
| 2338 FunctionType rawType = method?.type; | 2342 FunctionType rawType = method?.type; |
| 2339 FunctionType inferredType = _inferExecutableType(rawType, numNamed, | 2343 FunctionType inferredType = _inferExecutableType(rawType, numNamed, |
| 2340 numPositional, namedArgNames, namedArgTypeList, positionalArgTypes); | 2344 numPositional, namedArgNames, namedArgTypeList, positionalArgTypes); |
| 2341 if (inferredType != null) { | 2345 if (inferredType != null) { |
| 2342 return inferredType.returnType; | 2346 return inferredType.returnType; |
| 2343 } | 2347 } |
| 2344 } | 2348 } |
| 2345 return DynamicTypeImpl.instance; | 2349 return DynamicTypeImpl.instance; |
| 2346 }()); | 2350 }()); |
| 2347 } | 2351 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2447 return unit.resolveTypeRef(ref, variable._typeParameterContext); | 2451 return unit.resolveTypeRef(ref, variable._typeParameterContext); |
| 2448 } | 2452 } |
| 2449 | 2453 |
| 2450 /** | 2454 /** |
| 2451 * Return the type of the property with the given [propertyName] in the | 2455 * Return the type of the property with the given [propertyName] in the |
| 2452 * given [targetType]. May return `dynamic` if the property cannot be | 2456 * given [targetType]. May return `dynamic` if the property cannot be |
| 2453 * resolved. | 2457 * resolved. |
| 2454 */ | 2458 */ |
| 2455 DartType _getPropertyType(DartType targetType, String propertyName) { | 2459 DartType _getPropertyType(DartType targetType, String propertyName) { |
| 2456 return targetType is InterfaceType | 2460 return targetType is InterfaceType |
| 2457 ? targetType.lookUpGetter(propertyName, library)?.returnType | 2461 ? targetType |
| 2462 .lookUpInheritedGetter(propertyName, | |
| 2463 library: library, thisType: true) | |
| 2464 ?.returnType | |
| 2458 : DynamicTypeImpl.instance; | 2465 : DynamicTypeImpl.instance; |
| 2459 } | 2466 } |
| 2460 | 2467 |
| 2461 FunctionType _inferExecutableType( | 2468 FunctionType _inferExecutableType( |
| 2462 FunctionType rawMethodType, | 2469 FunctionType rawMethodType, |
| 2463 int numNamed, | 2470 int numNamed, |
| 2464 int numPositional, | 2471 int numPositional, |
| 2465 List<String> namedArgNames, | 2472 List<String> namedArgNames, |
| 2466 List<DartType> namedArgTypeList, | 2473 List<DartType> namedArgTypeList, |
| 2467 List<DartType> positionalArgTypes) { | 2474 List<DartType> positionalArgTypes) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2511 | 2518 |
| 2512 List<DartType> _popList(int n) { | 2519 List<DartType> _popList(int n) { |
| 2513 List<DartType> result = stack.sublist(stack.length - n, stack.length); | 2520 List<DartType> result = stack.sublist(stack.length - n, stack.length); |
| 2514 stack.length -= n; | 2521 stack.length -= n; |
| 2515 return result; | 2522 return result; |
| 2516 } | 2523 } |
| 2517 | 2524 |
| 2518 void _pushBinaryOperatorType( | 2525 void _pushBinaryOperatorType( |
| 2519 DartType left, TokenType operator, DartType right) { | 2526 DartType left, TokenType operator, DartType right) { |
| 2520 if (left is InterfaceType) { | 2527 if (left is InterfaceType) { |
| 2521 MethodElement method = left.lookUpMethod(operator.lexeme, library); | 2528 MethodElement method = left.lookUpInheritedMethod(operator.lexeme, |
| 2529 library: library, thisType: true); | |
| 2522 if (method != null) { | 2530 if (method != null) { |
| 2523 DartType type = method.returnType; | 2531 DartType type = method.returnType; |
| 2524 type = linker.typeSystem.refineBinaryExpressionType( | 2532 type = linker.typeSystem.refineBinaryExpressionType( |
| 2525 typeProvider, left, operator, right, type); | 2533 typeProvider, left, operator, right, type); |
| 2526 stack.add(type); | 2534 stack.add(type); |
| 2527 return; | 2535 return; |
| 2528 } | 2536 } |
| 2529 } | 2537 } |
| 2530 stack.add(DynamicTypeImpl.instance); | 2538 stack.add(DynamicTypeImpl.instance); |
| 2531 } | 2539 } |
| (...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3601 NonstaticMemberElementForLink(this._library, this._target, this._name); | 3609 NonstaticMemberElementForLink(this._library, this._target, this._name); |
| 3602 | 3610 |
| 3603 @override | 3611 @override |
| 3604 ConstVariableNode get asConstVariable => _target.asConstVariable; | 3612 ConstVariableNode get asConstVariable => _target.asConstVariable; |
| 3605 | 3613 |
| 3606 @override | 3614 @override |
| 3607 DartType get asStaticType { | 3615 DartType get asStaticType { |
| 3608 if (_library._linker.strongMode) { | 3616 if (_library._linker.strongMode) { |
| 3609 DartType targetType = _target.asStaticType; | 3617 DartType targetType = _target.asStaticType; |
| 3610 if (targetType is InterfaceType) { | 3618 if (targetType is InterfaceType) { |
| 3611 PropertyAccessorElement getter = | 3619 ExecutableElement element = |
| 3612 targetType.lookUpGetter(_name, _library); | 3620 targetType.lookUpInheritedGetterOrMethod(_name, library: _library); |
| 3613 if (getter != null) { | 3621 if (element != null) { |
| 3614 return getter.returnType; | 3622 if (element is PropertyAccessorElement) { |
| 3615 } | 3623 return element.returnType; |
| 3616 MethodElement method = targetType.lookUpMethod(_name, _library); | 3624 } else { |
| 3617 if (method != null) { | 3625 // Method tear-off |
| 3618 return method.type; | 3626 return element.type; |
| 3627 } | |
| 3619 } | 3628 } |
| 3620 } | 3629 } |
| 3621 // TODO(paulberry): handle .call on function types and .toString or | 3630 // TODO(paulberry): handle .call on function types and .toString or |
| 3622 // .hashCode on all types. | 3631 // .hashCode on all types. |
| 3623 } | 3632 } |
| 3624 // TODO(paulberry, scheglov): implement for propagated types | 3633 // TODO(paulberry, scheglov): implement for propagated types |
| 3625 return DynamicTypeImpl.instance; | 3634 return DynamicTypeImpl.instance; |
| 3626 } | 3635 } |
| 3627 | 3636 |
| 3628 @override | 3637 @override |
| (...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4703 * there are no type parameters in scope. | 4712 * there are no type parameters in scope. |
| 4704 */ | 4713 */ |
| 4705 TypeParameterizedElementMixin get _typeParameterContext; | 4714 TypeParameterizedElementMixin get _typeParameterContext; |
| 4706 | 4715 |
| 4707 @override | 4716 @override |
| 4708 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 4717 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 4709 | 4718 |
| 4710 @override | 4719 @override |
| 4711 String toString() => '$enclosingElement.$name'; | 4720 String toString() => '$enclosingElement.$name'; |
| 4712 } | 4721 } |
| OLD | NEW |