1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Made operator precedence match everyone else

This commit is contained in:
Brian Fiete 2020-10-06 07:38:56 -07:00
parent 8376355098
commit 1171e6ef64
3 changed files with 33 additions and 11 deletions

View file

@ -1559,20 +1559,23 @@ BfBinaryOp Beefy::BfAssignOpToBinaryOp(BfAssignmentOp assignmentOp)
int Beefy::BfGetBinaryOpPrecendence(BfBinaryOp binOp)
{
switch (binOp)
{
case BfBinaryOp_LeftShift:
case BfBinaryOp_RightShift:
return 10;
{
case BfBinaryOp_Multiply:
case BfBinaryOp_Divide:
case BfBinaryOp_Modulus:
case BfBinaryOp_BitwiseAnd:
return 9;
case BfBinaryOp_Modulus:
return 13;
case BfBinaryOp_Add:
case BfBinaryOp_Subtract:
case BfBinaryOp_Subtract:
return 12;
case BfBinaryOp_LeftShift:
case BfBinaryOp_RightShift:
return 11;
case BfBinaryOp_BitwiseAnd:
return 10;
case BfBinaryOp_ExclusiveOr:
return 9;
case BfBinaryOp_BitwiseOr:
return 8;
return 8;
// "Range" inserted here if we were copying swift
case BfBinaryOp_Is:
case BfBinaryOp_As:

View file

@ -12394,7 +12394,11 @@ void BfExprEvaluator::Visit(BfObjectCreateExpression* objCreateExpr)
continue;
}
auto elemAddr = mModule->CreateIndexedValue(resultType, addr, writeIdx);
BfIRValue elemAddr;
if (!resultType->IsValuelessType())
elemAddr = mModule->CreateIndexedValue(resultType, addr, writeIdx);
else
elemAddr = mModule->mBfIRBuilder->GetFakeVal();
writeIdx++;
dimWriteIdx++;
@ -20508,6 +20512,20 @@ void BfExprEvaluator::Visit(BfBinaryOperatorExpression* binOpExpr)
}
}
if ((binOpExpr->mOp == BfBinaryOp_LeftShift) || (binOpExpr->mOp == BfBinaryOp_RightShift))
{
for (int side = 0; side < 2; side++)
{
if (auto innerBinOpExpr = BfNodeDynCast<BfBinaryOperatorExpression>((side == 0) ? binOpExpr->mLeft : binOpExpr->mRight))
{
if ((innerBinOpExpr->mOp == BfBinaryOp_Add) || (innerBinOpExpr->mOp == BfBinaryOp_Subtract))
{
mModule->Warn(BfWarning_C4554_PossiblePrecedenceError, "Check operator precedence for possible error. Consider using parentheses to clarify precedence", innerBinOpExpr);
}
}
}
}
if (binOpExpr->mRight == NULL)
{
// We visit the children for autocompletion only

View file

@ -1102,7 +1102,8 @@ enum BfWarning
BfWarning_CS1030_PragmaWarning = 1030,
BfWarning_BF4201_Only7Hex = 4201,
BfWarning_BF4202_TooManyHexForInt = 4202,
BfWarning_BF4203_UnnecessaryDynamicCast = 4203
BfWarning_BF4203_UnnecessaryDynamicCast = 4203,
BfWarning_C4554_PossiblePrecedenceError = 4554
};
class BfErrorBase