mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Allow CreateObject for default ctors with append allocs
This commit is contained in:
parent
aba01b2cc8
commit
3338f3c069
5 changed files with 61 additions and 14 deletions
|
@ -121,32 +121,55 @@ namespace System.Reflection
|
|||
return .Err;
|
||||
|
||||
MethodInfo methodInfo = default;
|
||||
MethodInfo calcAppendMethodInfo = default;
|
||||
if (!IsBoxed)
|
||||
{
|
||||
for (int methodId < mMethodDataCount)
|
||||
{
|
||||
let methodData = &mMethodDataPtr[methodId];
|
||||
if ((!methodData.mFlags.HasFlag(.Constructor)) || (methodData.mFlags.HasFlag(.Static)))
|
||||
{
|
||||
if (((Object)methodData.mName == "this$calcAppend") && (methodData.mParamCount == 0))
|
||||
calcAppendMethodInfo = .(this, methodData);
|
||||
continue;
|
||||
if (methodData.mParamCount != 0)
|
||||
continue;
|
||||
|
||||
}
|
||||
if (methodData.mParamCount == 0)
|
||||
{
|
||||
methodInfo = .(this, methodData);
|
||||
break;
|
||||
}
|
||||
else if ((methodData.mParamCount == 1) && (methodData.mParamData[0].mParamFlags.HasFlag(.AppendIdx)))
|
||||
methodInfo = .(this, methodData);
|
||||
}
|
||||
|
||||
if (!methodInfo.IsInitialized)
|
||||
return .Err;
|
||||
if ((methodInfo.[Friend]mMethodData.mParamCount != 0) && (!calcAppendMethodInfo.IsInitialized))
|
||||
return .Err;
|
||||
}
|
||||
Object obj;
|
||||
|
||||
let objType = typeof(Object) as TypeInstance;
|
||||
|
||||
int allocSize = mInstSize;
|
||||
bool hasAppendAlloc = (methodInfo.IsInitialized) && (methodInfo.[Friend]mMethodData.mParamCount != 0);
|
||||
|
||||
if (hasAppendAlloc)
|
||||
{
|
||||
switch (calcAppendMethodInfo.Invoke(null))
|
||||
{
|
||||
case .Err:
|
||||
return .Err;
|
||||
case .Ok(let val):
|
||||
allocSize += val.Get<int>();
|
||||
}
|
||||
}
|
||||
|
||||
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
|
||||
int32 stackCount = Compiler.Options.AllocStackCount;
|
||||
if (mAllocStackCountOverride != 0)
|
||||
stackCount = mAllocStackCountOverride;
|
||||
obj = Internal.Dbg_ObjectAlloc(mTypeClassVData, mInstSize, mInstAlign, stackCount);
|
||||
obj = Internal.Dbg_ObjectAlloc(mTypeClassVData, allocSize, mInstAlign, stackCount);
|
||||
#else
|
||||
void* mem = new [Align(16)] uint8[mInstSize]* (?);
|
||||
obj = Internal.UnsafeCastToObject(mem);
|
||||
|
@ -155,7 +178,13 @@ namespace System.Reflection
|
|||
Internal.MemSet((uint8*)Internal.UnsafeCastToPtr(obj) + objType.mInstSize, 0, mInstSize - objType.mInstSize);
|
||||
if (methodInfo.IsInitialized)
|
||||
{
|
||||
if (methodInfo.Invoke(obj) case .Err)
|
||||
Object[] args = null;
|
||||
if (hasAppendAlloc)
|
||||
args = scope:: .(scope:: box ((int)Internal.UnsafeCastToPtr(obj) + mInstSize));
|
||||
else
|
||||
args = scope:: Object[0];
|
||||
|
||||
if (methodInfo.Invoke(obj, params args) case .Err)
|
||||
{
|
||||
delete obj;
|
||||
return .Err;
|
||||
|
|
|
@ -756,7 +756,8 @@ namespace System.Reflection
|
|||
{
|
||||
None = 0,
|
||||
Splat = 1,
|
||||
Implicit = 2
|
||||
Implicit = 2,
|
||||
AppendIdx = 4
|
||||
}
|
||||
|
||||
[CRepr, AlwaysInclude]
|
||||
|
|
|
@ -6831,11 +6831,11 @@ BfIRValue BfModule::CreateTypeData(BfType* type, Dictionary<int, int>& usedStrin
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue