mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 06:44:10 +02:00
Support for non-static ++ and -- operator overloads
This commit is contained in:
parent
5924d4819b
commit
66d5f67528
3 changed files with 58 additions and 19 deletions
|
@ -520,6 +520,8 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!methodDef->mIsStatic)
|
if (!methodDef->mIsStatic)
|
||||||
|
{
|
||||||
|
if ((operatorDecl->mUnaryOp != BfUnaryOp_Increment) && (operatorDecl->mUnaryOp != BfUnaryOp_Decrement))
|
||||||
{
|
{
|
||||||
if (!declError.empty())
|
if (!declError.empty())
|
||||||
declError += " and ";
|
declError += " and ";
|
||||||
|
@ -527,6 +529,7 @@ BfMethodDef* BfDefBuilder::CreateMethodDef(BfMethodDeclaration* methodDeclaratio
|
||||||
methodDef->mIsStatic = true; // Fix it
|
methodDef->mIsStatic = true; // Fix it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (!declError.empty())
|
if (!declError.empty())
|
||||||
{
|
{
|
||||||
Fail(StrFormat("Operator must be declared %s", declError.c_str()), operatorDecl->mOperatorToken);
|
Fail(StrFormat("Operator must be declared %s", declError.c_str()), operatorDecl->mOperatorToken);
|
||||||
|
|
|
@ -17721,8 +17721,16 @@ BfTypedValue BfExprEvaluator::PerformUnaryOperation_TryOperator(const BfTypedVal
|
||||||
{
|
{
|
||||||
if (!methodMatcher.IsMemberAccessible(checkType, operatorDef->mDeclaringType))
|
if (!methodMatcher.IsMemberAccessible(checkType, operatorDef->mDeclaringType))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
int prevArgSize = (int)args.mSize;
|
||||||
|
if (!operatorDef->mIsStatic)
|
||||||
|
{
|
||||||
|
// Try without arg
|
||||||
|
args.mSize = 0;
|
||||||
|
}
|
||||||
if (methodMatcher.CheckMethod(NULL, checkType, operatorDef, false))
|
if (methodMatcher.CheckMethod(NULL, checkType, operatorDef, false))
|
||||||
methodMatcher.mSelfType = entry.mSrcType;
|
methodMatcher.mSelfType = entry.mSrcType;
|
||||||
|
args.mSize = prevArgSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17786,13 +17794,26 @@ BfTypedValue BfExprEvaluator::PerformUnaryOperation_TryOperator(const BfTypedVal
|
||||||
SizedArray<BfExpression*, 2> argSrcs;
|
SizedArray<BfExpression*, 2> argSrcs;
|
||||||
argSrcs.push_back(unaryOpExpr);
|
argSrcs.push_back(unaryOpExpr);
|
||||||
|
|
||||||
|
BfTypedValue targetVal = args[0].mTypedValue;
|
||||||
BfTypedValue postOpVal;
|
BfTypedValue postOpVal;
|
||||||
if (isPostOp)
|
if (isPostOp)
|
||||||
postOpVal = mModule->LoadValue(args[0].mTypedValue);
|
postOpVal = mModule->LoadValue(targetVal);
|
||||||
|
|
||||||
auto result = CreateCall(&methodMatcher, BfTypedValue());
|
BfTypedValue callTarget;
|
||||||
|
if (!methodMatcher.mBestMethodDef->mIsStatic)
|
||||||
|
{
|
||||||
|
callTarget = targetVal;
|
||||||
|
args.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
if ((result.mType != NULL) && (methodMatcher.mSelfType != NULL) && (result.mType->IsSelf()))
|
auto result = CreateCall(&methodMatcher, callTarget);
|
||||||
|
|
||||||
|
if (!methodMatcher.mBestMethodDef->mIsStatic)
|
||||||
|
{
|
||||||
|
if (!isPostOp)
|
||||||
|
result = mModule->LoadValue(targetVal);
|
||||||
|
}
|
||||||
|
else if ((result.mType != NULL) && (methodMatcher.mSelfType != NULL) && (result.mType->IsSelf()))
|
||||||
{
|
{
|
||||||
BF_ASSERT(mModule->IsInGeneric());
|
BF_ASSERT(mModule->IsInGeneric());
|
||||||
result = mModule->GetDefaultTypedValue(methodMatcher.mSelfType);
|
result = mModule->GetDefaultTypedValue(methodMatcher.mSelfType);
|
||||||
|
|
|
@ -17001,6 +17001,8 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
||||||
TypeToString(wantType).c_str()), operatorDef->mOperatorDeclaration->mReturnType);
|
TypeToString(wantType).c_str()), operatorDef->mOperatorDeclaration->mReturnType);
|
||||||
}
|
}
|
||||||
else if (operatorDef->mOperatorDeclaration->mUnaryOp != BfUnaryOp_None)
|
else if (operatorDef->mOperatorDeclaration->mUnaryOp != BfUnaryOp_None)
|
||||||
|
{
|
||||||
|
if (methodDef->mIsStatic)
|
||||||
{
|
{
|
||||||
if (methodDef->mParams.size() != 1)
|
if (methodDef->mParams.size() != 1)
|
||||||
{
|
{
|
||||||
|
@ -17018,6 +17020,19 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
|
||||||
Fail("The return type for the '++' or '--' operator must match the parameter type or be derived from the parameter type", operatorDef->mOperatorDeclaration->mReturnType);
|
Fail("The return type for the '++' or '--' operator must match the parameter type or be derived from the parameter type", operatorDef->mOperatorDeclaration->mReturnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (methodDef->mParams.size() != 0)
|
||||||
|
{
|
||||||
|
Fail("Non-static unary operators not declare any parameters", paramErrorRefNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mCurMethodInstance->mReturnType->IsVoid())
|
||||||
|
{
|
||||||
|
Fail("The return type for non-static operator must be 'void'", operatorDef->mOperatorDeclaration->mReturnType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
else if (operatorDef->mOperatorDeclaration->mAssignOp != BfAssignmentOp_None)
|
else if (operatorDef->mOperatorDeclaration->mAssignOp != BfAssignmentOp_None)
|
||||||
{
|
{
|
||||||
if (methodDef->mParams.size() != 1)
|
if (methodDef->mParams.size() != 1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue