mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Allow IOnTypeInit for method declarations
This commit is contained in:
parent
35584ef288
commit
3b412719fe
4 changed files with 78 additions and 25 deletions
|
@ -22146,6 +22146,14 @@ void BfModule::GetMethodCustomAttributes(BfMethodInstance* methodInstance)
|
|||
{
|
||||
if (methodInstance->GetMethodInfoEx()->mMethodCustomAttributes == NULL)
|
||||
methodInstance->mMethodInfoEx->mMethodCustomAttributes = new BfMethodCustomAttributes();
|
||||
|
||||
if ((methodInstance == methodInstance->mMethodInstanceGroup->mDefault) && (methodInstance->mMethodInstanceGroup->mDefaultCustomAttributes != NULL))
|
||||
{
|
||||
// Take over prevoiusly-generated custom attributes
|
||||
methodInstance->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes = methodInstance->mMethodInstanceGroup->mDefaultCustomAttributes;
|
||||
methodInstance->mMethodInstanceGroup->mDefaultCustomAttributes = NULL;
|
||||
}
|
||||
else
|
||||
methodInstance->mMethodInfoEx->mMethodCustomAttributes->mCustomAttributes = GetCustomAttributes(attributeDirective, attrTarget);
|
||||
}
|
||||
|
||||
|
|
|
@ -2424,6 +2424,45 @@ void BfModule::ExecuteCEOnCompile(CeEmitContext* ceEmitContext, BfTypeInstance*
|
|||
if (fieldInstance.mCustomAttributes != NULL)
|
||||
HandleCEAttributes(ceEmitContext, typeInstance, &fieldInstance, fieldInstance.mCustomAttributes, prevAttrInstances, underlyingTypeDeferred);
|
||||
}
|
||||
|
||||
for (auto methodDef : typeInstance->mTypeDef->mMethods)
|
||||
{
|
||||
auto methodDeclaration = methodDef->GetMethodDeclaration();
|
||||
auto propertyMethodDeclaration = methodDef->GetPropertyMethodDeclaration();
|
||||
BfAttributeTargets attrTarget = ((methodDef->mMethodType == BfMethodType_Ctor) || (methodDef->mMethodType == BfMethodType_CtorCalcAppend)) ? BfAttributeTargets_Constructor : BfAttributeTargets_Method;
|
||||
BfAttributeDirective* attributeDirective = NULL;
|
||||
if (methodDeclaration != NULL)
|
||||
attributeDirective = methodDeclaration->mAttributes;
|
||||
else if (propertyMethodDeclaration != NULL)
|
||||
{
|
||||
attributeDirective = propertyMethodDeclaration->mAttributes;
|
||||
if (auto exprBody = BfNodeDynCast<BfPropertyBodyExpression>(propertyMethodDeclaration->mPropertyDeclaration->mDefinitionBlock))
|
||||
{
|
||||
attributeDirective = propertyMethodDeclaration->mPropertyDeclaration->mAttributes;
|
||||
attrTarget = (BfAttributeTargets)(BfAttributeTargets_Property | BfAttributeTargets_Method);
|
||||
}
|
||||
}
|
||||
if (attributeDirective == NULL)
|
||||
continue;
|
||||
|
||||
// Corlib will never need to process
|
||||
if (methodDef->mDeclaringType->mProject == mContext->mBfObjectType->mTypeDef->mProject)
|
||||
continue;
|
||||
|
||||
if (!typeInstance->IsTypeMemberIncluded(methodDef->mDeclaringType, mCurTypeInstance->mTypeDef, this))
|
||||
continue;
|
||||
|
||||
auto& methodInstanceGroup = typeInstance->mMethodInstanceGroups[methodDef->mIdx];
|
||||
if (methodInstanceGroup.mDefaultCustomAttributes == NULL)
|
||||
{
|
||||
BfTypeState typeState;
|
||||
typeState.mPrevState = mContext->mCurTypeState;
|
||||
typeState.mForceActiveTypeDef = methodDef->mDeclaringType;
|
||||
SetAndRestoreValue<BfTypeState*> prevTypeState(mContext->mCurTypeState, &typeState);
|
||||
methodInstanceGroup.mDefaultCustomAttributes = GetCustomAttributes(attributeDirective, attrTarget);
|
||||
}
|
||||
HandleCEAttributes(ceEmitContext, typeInstance, NULL, methodInstanceGroup.mDefaultCustomAttributes, prevAttrInstances, underlyingTypeDeferred);
|
||||
}
|
||||
}
|
||||
|
||||
int methodCount = (int)typeInstance->mTypeDef->mMethods.size();
|
||||
|
|
|
@ -1569,6 +1569,29 @@ BfMethodRefType::~BfMethodRefType()
|
|||
BF_ASSERT(mMethodRef == NULL);
|
||||
}
|
||||
|
||||
BfMethodInstanceGroup::BfMethodInstanceGroup(BfMethodInstanceGroup&& prev) noexcept
|
||||
{
|
||||
mOwner = prev.mOwner;
|
||||
mDefault = prev.mDefault;
|
||||
mMethodSpecializationMap = prev.mMethodSpecializationMap;
|
||||
mMethodIdx = prev.mMethodIdx;
|
||||
mRefCount = prev.mRefCount;
|
||||
mOnDemandKind = prev.mOnDemandKind;
|
||||
if (mDefault != NULL)
|
||||
mDefault->mMethodInstanceGroup = this;
|
||||
if (mMethodSpecializationMap != NULL)
|
||||
{
|
||||
for (auto& pair : *mMethodSpecializationMap)
|
||||
pair.mValue->mMethodInstanceGroup = this;
|
||||
}
|
||||
mDefaultCustomAttributes = prev.mDefaultCustomAttributes;
|
||||
prev.mDefaultCustomAttributes = NULL;
|
||||
|
||||
prev.mRefCount = 0;
|
||||
prev.mDefault = NULL;
|
||||
prev.mMethodSpecializationMap = NULL;
|
||||
}
|
||||
|
||||
BfMethodInstanceGroup::~BfMethodInstanceGroup()
|
||||
{
|
||||
if (mRefCount != 0)
|
||||
|
@ -1582,6 +1605,7 @@ BfMethodInstanceGroup::~BfMethodInstanceGroup()
|
|||
delete kv.mValue;
|
||||
delete mMethodSpecializationMap;
|
||||
}
|
||||
delete mDefaultCustomAttributes;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -1314,6 +1314,7 @@ public:
|
|||
BfMethodInstance* mDefault;
|
||||
typedef Dictionary<BfTypeVector, BfMethodInstance*> MapType;
|
||||
MapType* mMethodSpecializationMap;
|
||||
BfCustomAttributes* mDefaultCustomAttributes;
|
||||
int mMethodIdx;
|
||||
int mRefCount; // External references from BfMethodRefType
|
||||
BfMethodOnDemandKind mOnDemandKind;
|
||||
|
@ -1326,6 +1327,7 @@ public:
|
|||
mOwner = NULL;
|
||||
mDefault = NULL;
|
||||
mMethodSpecializationMap = NULL;
|
||||
mDefaultCustomAttributes = NULL;
|
||||
mMethodIdx = -1;
|
||||
mOnDemandKind = BfMethodOnDemandKind_NotSet;
|
||||
mRefCount = 0;
|
||||
|
@ -1333,29 +1335,9 @@ public:
|
|||
mHasEmittedReference = false;
|
||||
}
|
||||
|
||||
BfMethodInstanceGroup(BfMethodInstanceGroup&& prev) noexcept;
|
||||
~BfMethodInstanceGroup();
|
||||
|
||||
BfMethodInstanceGroup(BfMethodInstanceGroup&& prev) noexcept
|
||||
{
|
||||
mOwner = prev.mOwner;
|
||||
mDefault = prev.mDefault;
|
||||
mMethodSpecializationMap = prev.mMethodSpecializationMap;
|
||||
mMethodIdx = prev.mMethodIdx;
|
||||
mRefCount = prev.mRefCount;
|
||||
mOnDemandKind = prev.mOnDemandKind;
|
||||
if (mDefault != NULL)
|
||||
mDefault->mMethodInstanceGroup = this;
|
||||
if (mMethodSpecializationMap != NULL)
|
||||
{
|
||||
for (auto& pair : *mMethodSpecializationMap)
|
||||
pair.mValue->mMethodInstanceGroup = this;
|
||||
}
|
||||
|
||||
prev.mRefCount = 0;
|
||||
prev.mDefault = NULL;
|
||||
prev.mMethodSpecializationMap = NULL;
|
||||
}
|
||||
|
||||
bool IsImplemented()
|
||||
{
|
||||
return (mOnDemandKind == BfMethodOnDemandKind_AlwaysInclude) ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue