| 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 2328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2339 stack.length -= n; | 2339 stack.length -= n; |
| 2340 return result; | 2340 return result; |
| 2341 } | 2341 } |
| 2342 | 2342 |
| 2343 void _pushBinaryOperatorType( | 2343 void _pushBinaryOperatorType( |
| 2344 DartType left, TokenType operator, DartType right) { | 2344 DartType left, TokenType operator, DartType right) { |
| 2345 if (left is InterfaceType) { | 2345 if (left is InterfaceType) { |
| 2346 MethodElement method = left.lookUpMethod(operator.lexeme, library); | 2346 MethodElement method = left.lookUpMethod(operator.lexeme, library); |
| 2347 if (method != null) { | 2347 if (method != null) { |
| 2348 DartType type = method.returnType; | 2348 DartType type = method.returnType; |
| 2349 type = _refineBinaryExpressionType(operator, type, left, right); | 2349 type = linker.typeSystem.refineBinaryExpressionType( |
| 2350 typeProvider, left, operator, right, type); |
| 2350 stack.add(type); | 2351 stack.add(type); |
| 2351 return; | 2352 return; |
| 2352 } | 2353 } |
| 2353 } | 2354 } |
| 2354 stack.add(DynamicTypeImpl.instance); | 2355 stack.add(DynamicTypeImpl.instance); |
| 2355 } | 2356 } |
| 2356 | 2357 |
| 2357 /** | 2358 /** |
| 2358 * Extract the property with the given [propertyName], apply the operator | 2359 * Extract the property with the given [propertyName], apply the operator |
| 2359 * with the given [operandType], push the type of applying operand of the | 2360 * with the given [operandType], push the type of applying operand of the |
| 2360 * given [operandType]. | 2361 * given [operandType]. |
| 2361 */ | 2362 */ |
| 2362 void _pushPropertyBinaryExpression(DartType targetType, String propertyName, | 2363 void _pushPropertyBinaryExpression(DartType targetType, String propertyName, |
| 2363 TokenType operator, DartType operandType) { | 2364 TokenType operator, DartType operandType) { |
| 2364 DartType propertyType = _getPropertyType(targetType, propertyName); | 2365 DartType propertyType = _getPropertyType(targetType, propertyName); |
| 2365 _pushBinaryOperatorType(propertyType, operator, operandType); | 2366 _pushBinaryOperatorType(propertyType, operator, operandType); |
| 2366 } | 2367 } |
| 2367 | 2368 |
| 2368 DartType _refineBinaryExpressionType(TokenType operator, DartType currentType, | |
| 2369 DartType leftType, DartType rightType) { | |
| 2370 DartType intType = typeProvider.intType; | |
| 2371 if (leftType == intType) { | |
| 2372 // int op double | |
| 2373 if (operator == TokenType.MINUS || | |
| 2374 operator == TokenType.PERCENT || | |
| 2375 operator == TokenType.PLUS || | |
| 2376 operator == TokenType.STAR) { | |
| 2377 DartType doubleType = typeProvider.doubleType; | |
| 2378 if (rightType == doubleType) { | |
| 2379 return doubleType; | |
| 2380 } | |
| 2381 } | |
| 2382 // int op int | |
| 2383 if (operator == TokenType.MINUS || | |
| 2384 operator == TokenType.PERCENT || | |
| 2385 operator == TokenType.PLUS || | |
| 2386 operator == TokenType.STAR || | |
| 2387 operator == TokenType.TILDE_SLASH) { | |
| 2388 if (rightType == intType) { | |
| 2389 return intType; | |
| 2390 } | |
| 2391 } | |
| 2392 } | |
| 2393 // default | |
| 2394 return currentType; | |
| 2395 } | |
| 2396 | |
| 2397 static TokenType _convertAssignOperatorToTokenType( | 2369 static TokenType _convertAssignOperatorToTokenType( |
| 2398 UnlinkedExprAssignOperator o) { | 2370 UnlinkedExprAssignOperator o) { |
| 2399 switch (o) { | 2371 switch (o) { |
| 2400 case UnlinkedExprAssignOperator.assign: | 2372 case UnlinkedExprAssignOperator.assign: |
| 2401 return null; | 2373 return null; |
| 2402 case UnlinkedExprAssignOperator.ifNull: | 2374 case UnlinkedExprAssignOperator.ifNull: |
| 2403 return TokenType.QUESTION_QUESTION; | 2375 return TokenType.QUESTION_QUESTION; |
| 2404 case UnlinkedExprAssignOperator.multiply: | 2376 case UnlinkedExprAssignOperator.multiply: |
| 2405 return TokenType.STAR; | 2377 return TokenType.STAR; |
| 2406 case UnlinkedExprAssignOperator.divide: | 2378 case UnlinkedExprAssignOperator.divide: |
| (...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4414 * there are no type parameters in scope. | 4386 * there are no type parameters in scope. |
| 4415 */ | 4387 */ |
| 4416 TypeParameterizedElementForLink get _typeParameterContext; | 4388 TypeParameterizedElementForLink get _typeParameterContext; |
| 4417 | 4389 |
| 4418 @override | 4390 @override |
| 4419 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 4391 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| 4420 | 4392 |
| 4421 @override | 4393 @override |
| 4422 String toString() => '$enclosingElement.$name'; | 4394 String toString() => '$enclosingElement.$name'; |
| 4423 } | 4395 } |
| OLD | NEW |