| 24202 | } |
| 24203 | |
| 24204 | bool BfExprEvaluator::PerformBinaryOperation_Numeric(BfAstNode* leftExpression, BfAstNode* rightExpression, BfBinaryOp binaryOp, BfAstNode* opToken, BfBinOpFlags flags, BfTypedValue leftValue, BfTypedValue rightValue) |
| 24205 | { |
| 24206 | switch (binaryOp) |
| 24207 | { |
| 24208 | case BfBinaryOp_Add: |
| 24209 | case BfBinaryOp_Subtract: |
| 24210 | case BfBinaryOp_Multiply: |
| 24211 | case BfBinaryOp_Divide: |
| 24212 | case BfBinaryOp_Modulus: |
| 24213 | break; |
| 24214 | default: |
| 24215 | return false; |
| 24216 | } |
| 24217 | |
| 24218 | auto wantType = mExpectingType; |
| 24219 | if ((wantType == NULL) || |
| 24220 | ((!wantType->IsFloat()) && (!wantType->IsIntegral()))) |
| 24221 | wantType = NULL; |
| 24222 | |
| 24223 | auto leftType = mModule->GetClosestNumericCastType(leftValue, mExpectingType); |
| 24224 | auto rightType = mModule->GetClosestNumericCastType(rightValue, mExpectingType); |
| 24225 | |
| 24226 | if (leftType != NULL) |
| 24227 | { |
| 24228 | if ((rightType == NULL) || (mModule->CanCast(mModule->GetFakeTypedValue(rightType), leftType))) |
| 24229 | wantType = leftType; |
| 24230 | else if ((rightType != NULL) && (mModule->CanCast(mModule->GetFakeTypedValue(leftType), rightType))) |
| 24231 | wantType = rightType; |
| 24232 | } |
| 24233 | else if (rightType != NULL) |
| 24234 | wantType = rightType; |
| 24235 | |
| 24236 | if (wantType == NULL) |
| 24237 | wantType = mModule->GetPrimitiveType(BfTypeCode_IntPtr); |
| 24238 | |
| 24239 | auto convLeftValue = mModule->Cast(opToken, leftValue, wantType, BfCastFlags_SilentFail); |
| 24240 | if (!convLeftValue) |
| 24241 | return false; |
| 24242 | |
| 24243 | auto convRightValue = mModule->Cast(opToken, rightValue, wantType, BfCastFlags_SilentFail); |
| 24244 | if (!convRightValue) |
| 24245 | return false; |
| 24246 | |
| 24247 | mResult = BfTypedValue(); |
| 24248 | |
| 24249 | // Let the error come from here, if any - so we always return 'true' to avoid a second error |
| 24250 | PerformBinaryOperation(leftExpression, rightExpression, binaryOp, opToken, flags, convLeftValue, convRightValue); |
| 24251 | |
| 24252 | return true; |
| 24253 | } |
| 24254 | |
| 24255 | void BfExprEvaluator::PerformBinaryOperation(BfExpression* leftExpression, BfExpression* rightExpression, BfBinaryOp binaryOp, BfTokenNode* opToken, BfBinOpFlags flags) |
| 24256 | { |
nothing calls this directly
no test coverage detected