MCPcopy Create free account
hub / github.com/beefytech/Beef / PerformBinaryOperation_Numeric

Method PerformBinaryOperation_Numeric

IDEHelper/Compiler/BfExprEvaluator.cpp:24204–24253  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24202}
24203
24204bool 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
24255void BfExprEvaluator::PerformBinaryOperation(BfExpression* leftExpression, BfExpression* rightExpression, BfBinaryOp binaryOp, BfTokenNode* opToken, BfBinOpFlags flags)
24256{

Callers

nothing calls this directly

Calls 8

BfTypedValueClass · 0.85
GetFakeTypedValueMethod · 0.80
IsFloatMethod · 0.45
IsIntegralMethod · 0.45
CanCastMethod · 0.45
GetPrimitiveTypeMethod · 0.45
CastMethod · 0.45

Tested by

no test coverage detected