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

Improved param defaults, allowing for implicit cast operators

This commit is contained in:
Brian Fiete 2020-05-07 13:19:02 -07:00
parent ea072ad77b
commit 5bbffe268b
6 changed files with 98 additions and 32 deletions

View file

@ -264,6 +264,7 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch
}
}
BfTypedValue argValue;
BfAstNode* argExpr = NULL;
if (argIdx < (int)arguments.size())
{
@ -314,28 +315,25 @@ bool BfConstResolver::PrepareMethodArguments(BfAstNode* targetSrc, BfMethodMatch
}
auto foreignDefaultVal = methodInstance->mDefaultValues[argIdx];
auto foreignConst = methodInstance->GetOwner()->mConstHolder->GetConstant(methodInstance->mDefaultValues[argIdx]);
auto constVal = mModule->ConstantToCurrent(foreignConst, methodInstance->GetOwner()->mConstHolder, wantType);
llvmArgs.push_back(constVal);
argIdx++;
paramIdx++;
continue;
auto foreignConst = methodInstance->GetOwner()->mConstHolder->GetConstant(foreignDefaultVal.mValue);
argValue = mModule->GetTypedValueFromConstant(foreignConst, methodInstance->GetOwner()->mConstHolder, foreignDefaultVal.mType);
}
auto argValue = arguments[argIdx].mTypedValue;
auto& arg = arguments[argIdx];
if ((arg.mArgFlags & BfArgFlag_DeferredEval) != 0)
if ((!argValue) && (argIdx < arguments.size()))
{
mExpectingType = arg.mExpectedType;
if (mExpectingType == NULL)
mExpectingType = wantType;
argValue = arguments[argIdx].mTypedValue;
auto& arg = arguments[argIdx];
if ((arg.mArgFlags & BfArgFlag_DeferredEval) != 0)
{
mExpectingType = arg.mExpectedType;
if (mExpectingType == NULL)
mExpectingType = wantType;
if (auto expr = BfNodeDynCast<BfExpression>(argExpr))
argValue = Resolve(expr, mExpectingType);
arg.mArgFlags = BfArgFlag_None;
if (auto expr = BfNodeDynCast<BfExpression>(argExpr))
argValue = Resolve(expr, mExpectingType);
arg.mArgFlags = BfArgFlag_None;
}
}
if (!argValue)
return BfTypedValue();