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

Allow CreateObject for default ctors with append allocs

This commit is contained in:
Brian Fiete 2022-01-29 09:57:43 -05:00
parent aba01b2cc8
commit 3338f3c069
5 changed files with 61 additions and 14 deletions

View file

@ -6830,14 +6830,14 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
includeMethod = true;
if ((methodDef->mIsStatic) && ((methodReflectKind & BfReflectKind_StaticMethods) != 0))
includeMethod = true;
if (methodDef->mMethodType == BfMethodType_Ctor)
if ((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_CtorCalcAppend))
{
if ((methodReflectKind & BfReflectKind_Constructors) != 0)
includeMethod = true;
if ((methodDef->mParams.IsEmpty()) && ((methodReflectKind & BfReflectKind_DefaultConstructor) != 0))
if ((methodDef->IsDefaultCtor()) && ((methodReflectKind & BfReflectKind_DefaultConstructor) != 0))
includeMethod = true;
}
}
if ((!includeMethod) && (typeOptions != NULL))
includeMethod = ApplyTypeOptionMethodFilters(includeMethod, methodDef, typeOptions);
@ -6906,6 +6906,7 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
ParamFlag_None = 0,
ParamFlag_Splat = 1,
ParamFlag_Implicit = 2,
ParamFlag_AppendIdx = 4
};
SizedArray<BfIRValue, 8> paramVals;
@ -6917,6 +6918,8 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
ParamFlags paramFlags = ParamFlag_None;
if (defaultMethod->GetParamIsSplat(paramIdx))
paramFlags = (ParamFlags)(paramFlags | ParamFlag_Splat);
if (defaultMethod->GetParamKind(paramIdx) == BfParamKind_AppendIdx)
paramFlags = (ParamFlags)(paramFlags | ParamFlag_Implicit | ParamFlag_AppendIdx);
BfIRValue paramNameConst = GetStringObjectValue(paramName, !mIsComptimeModule);
@ -10109,6 +10112,12 @@ BfTypedValue BfModule::BoxValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
if ((!typedVal.mType->IsPointer()) || (toTypeInstance == mContext->mBfObjectType))
fromStructTypeInstance = GetWrappedStructType(typedVal.mType);
else
{
auto checkStructTypeInstance = GetWrappedStructType(typedVal.mType);
if (checkStructTypeInstance == toType->GetUnderlyingType())
fromStructTypeInstance = checkStructTypeInstance;
}
if (isStructPtr)
{

View file

@ -5536,9 +5536,10 @@ void BfModule::DoTypeInstanceMethodProcessing(BfTypeInstance* typeInstance)
}
if (typeInstance->IncludeAllMethods())
implRequired = true;
// "AssumeInstantiated" also forces default ctor
if (((typeInstance->mAlwaysIncludeFlags & BfAlwaysIncludeFlag_AssumeInstantiated) != 0) &&
(methodDef->mMethodType == BfMethodType_Ctor) && (methodDef->mParams.IsEmpty()))
(methodDef->IsDefaultCtor()))
implRequired = true;
if ((typeOptionsIncludeAll) && (ApplyTypeOptionMethodFilters(true, methodDef, typeOptions)))

View file

@ -550,7 +550,14 @@ bool BfMethodDef::IsEmptyPartial()
bool BfMethodDef::IsDefaultCtor()
{
return ((mMethodType == BfMethodType_Ctor) || (mMethodType == BfMethodType_CtorNoBody)) && (mParams.IsEmpty());
if ((mMethodType == BfMethodType_Ctor) || (mMethodType == BfMethodType_CtorNoBody))
{
return ((mParams.IsEmpty()) ||
((mParams.mSize == 1) && (mParams[0]->mParamKind == BfParamKind_AppendIdx)));
}
else if (mMethodType == BfMethodType_CtorCalcAppend)
return mParams.IsEmpty();
return false;
}
bool BfMethodDef::IsCtorOrInit()