mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Now calls implicit cast for binary operators
This commit is contained in:
parent
df76b17c49
commit
12de9cea4b
1 changed files with 59 additions and 13 deletions
|
@ -17305,6 +17305,25 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((leftValue.mType->IsPointer()) &&
|
||||||
|
(rightValue.mType->IsPointer()))
|
||||||
|
{
|
||||||
|
BfPointerType* leftPointerType = (BfPointerType*)leftValue.mType;
|
||||||
|
BfPointerType* rightPointerType = (BfPointerType*)rightValue.mType;
|
||||||
|
|
||||||
|
// If one is a pointer to a sized array then use the other type
|
||||||
|
if (leftPointerType->mElementType->IsSizedArray())
|
||||||
|
{
|
||||||
|
resultType = rightPointerType;
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
else if (rightPointerType->mElementType->IsSizedArray())
|
||||||
|
{
|
||||||
|
resultType = leftPointerType;
|
||||||
|
handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!handled)
|
if (!handled)
|
||||||
{
|
{
|
||||||
if ((resultType->IsNull()) ||
|
if ((resultType->IsNull()) ||
|
||||||
|
@ -17708,10 +17727,10 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
{
|
{
|
||||||
//TODO: Allow all pointer comparisons, but only allow SUBTRACTION between equal pointer types
|
//TODO: Allow all pointer comparisons, but only allow SUBTRACTION between equal pointer types
|
||||||
if (binaryOp == BfBinaryOp_Subtract)
|
if (binaryOp == BfBinaryOp_Subtract)
|
||||||
{
|
{
|
||||||
if (resultType != otherType)
|
if (!mModule->CanCast(*otherTypedValue, resultType))
|
||||||
{
|
{
|
||||||
mModule->Fail(StrFormat("Operands must be the same type, '%s' doesn't match '%s'",
|
mModule->Fail(StrFormat("Operands '%s' and '%s' are not comparable types.",
|
||||||
mModule->TypeToString(leftValue.mType).c_str(), mModule->TypeToString(rightValue.mType).c_str()),
|
mModule->TypeToString(leftValue.mType).c_str(), mModule->TypeToString(rightValue.mType).c_str()),
|
||||||
opToken);
|
opToken);
|
||||||
return;
|
return;
|
||||||
|
@ -17928,8 +17947,10 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (((leftValue.mType->IsComposite()) || (leftValue.mType->IsObject())))
|
//if (((leftValue.mType->IsComposite()) || (leftValue.mType->IsObject())))
|
||||||
|
|
||||||
|
if (((resultType->IsComposite()) || (resultType->IsObject())))
|
||||||
{
|
{
|
||||||
bool areEquivalentTuples = false;
|
bool areEquivalentTuples = false;
|
||||||
if ((leftValue.mType->IsTuple()) && (rightValue.mType->IsTuple()))
|
if ((leftValue.mType->IsTuple()) && (rightValue.mType->IsTuple()))
|
||||||
|
@ -17945,7 +17966,7 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
else if (mModule->CanCast(leftValue, rightValue.mType))
|
else if (mModule->CanCast(leftValue, rightValue.mType))
|
||||||
leftValue = mModule->Cast(opToken, leftValue, rightValue.mType, BfCastFlags_Explicit);
|
leftValue = mModule->Cast(opToken, leftValue, rightValue.mType, BfCastFlags_Explicit);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leftValue.mType == rightValue.mType)
|
if (leftValue.mType == rightValue.mType)
|
||||||
{
|
{
|
||||||
if ((binaryOp == BfBinaryOp_Equality) || (binaryOp == BfBinaryOp_InEquality))
|
if ((binaryOp == BfBinaryOp_Equality) || (binaryOp == BfBinaryOp_InEquality))
|
||||||
|
@ -17971,16 +17992,41 @@ void BfExprEvaluator::PerformBinaryOperation(BfAstNode* leftExpression, BfAstNod
|
||||||
mModule->Fail(StrFormat("Operator '%s' cannot be applied to operands of type '%s'",
|
mModule->Fail(StrFormat("Operator '%s' cannot be applied to operands of type '%s'",
|
||||||
BfGetOpName(binaryOp),
|
BfGetOpName(binaryOp),
|
||||||
mModule->TypeToString(leftValue.mType).c_str()), opToken);
|
mModule->TypeToString(leftValue.mType).c_str()), opToken);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mModule->Fail(StrFormat("Operator '%s' cannot be applied to operands of type '%s' and '%s'",
|
bool handled = false;
|
||||||
BfGetOpName(binaryOp),
|
|
||||||
mModule->TypeToString(leftValue.mType).c_str(),
|
for (int pass = 0; pass < 2; pass++)
|
||||||
mModule->TypeToString(rightValue.mType).c_str()), opToken);
|
{
|
||||||
}
|
BfTypedValue& fromValue = (pass == 0) ? leftValue : rightValue;
|
||||||
return;
|
BfType* toType = (pass == 0) ? rightValue.mType : leftValue.mType;
|
||||||
|
|
||||||
|
if (mModule->CanCast(fromValue, toType))
|
||||||
|
{
|
||||||
|
auto result = mModule->Cast(opToken, fromValue, toType);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
resultType = toType;
|
||||||
|
fromValue = result;
|
||||||
|
handled = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!handled)
|
||||||
|
{
|
||||||
|
mModule->Fail(StrFormat("Operator '%s' cannot be applied to operands of type '%s' and '%s'",
|
||||||
|
BfGetOpName(binaryOp),
|
||||||
|
mModule->TypeToString(leftValue.mType).c_str(),
|
||||||
|
mModule->TypeToString(rightValue.mType).c_str()), opToken);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resultType->IsMethodRef() && otherType->IsMethodRef())
|
if (resultType->IsMethodRef() && otherType->IsMethodRef())
|
||||||
{
|
{
|
||||||
if ((binaryOp == BfBinaryOp_Equality) || (binaryOp == BfBinaryOp_InEquality))
|
if ((binaryOp == BfBinaryOp_Equality) || (binaryOp == BfBinaryOp_InEquality))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue