mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Comptime method fixes
This commit is contained in:
parent
0927656400
commit
ed06ff4dce
5 changed files with 37 additions and 7 deletions
|
@ -4608,7 +4608,8 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
|||
{
|
||||
mModule->CheckStaticAccess(curCheckType);
|
||||
auto retVal = mModule->ReferenceStaticField(fieldInstance);
|
||||
bool isStaticCtor = (mModule->mCurMethodInstance != NULL) && (mModule->mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor) &&
|
||||
bool isStaticCtor = (mModule->mCurMethodInstance != NULL) &&
|
||||
(mModule->mCurMethodInstance->mMethodDef->IsCtorOrInit()) &&
|
||||
(mModule->mCurMethodInstance->mMethodDef->mIsStatic);
|
||||
if ((field->mIsReadOnly) && (!isStaticCtor))
|
||||
{
|
||||
|
@ -4652,7 +4653,7 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
|||
bool isTemporary = target.IsTempAddr();
|
||||
bool wantsLoadValue = false;
|
||||
bool wantsReadOnly = false;
|
||||
if ((field->mIsReadOnly) && (mModule->mCurMethodInstance != NULL) && ((mModule->mCurMethodInstance->mMethodDef->mMethodType != BfMethodType_Ctor) || (!target.IsThis())))
|
||||
if ((field->mIsReadOnly) && (mModule->mCurMethodInstance != NULL) && ((!mModule->mCurMethodInstance->mMethodDef->IsCtorOrInit()) || (!target.IsThis())))
|
||||
wantsReadOnly = true;
|
||||
|
||||
bool isComposite = target.mType->IsComposite();
|
||||
|
|
|
@ -2019,6 +2019,24 @@ BfCEParseContext BfModule::CEEmitParse(BfTypeInstance* typeInstance, const Strin
|
|||
emitTypeDef->mSource = emitParser;
|
||||
emitParser->mRefCount++;
|
||||
emitParser->SetSource(src.c_str(), src.mLength);
|
||||
|
||||
// If we emit only from method attributes then we will already have method instances created
|
||||
auto _FixMethod = [&](BfMethodInstance* methodInstance)
|
||||
{
|
||||
if (methodInstance == NULL)
|
||||
return;
|
||||
methodInstance->mMethodDef = emitTypeDef->mMethods[methodInstance->mMethodDef->mIdx];
|
||||
};
|
||||
|
||||
for (auto& methodInstanceGroup : typeInstance->mMethodInstanceGroups)
|
||||
{
|
||||
_FixMethod(methodInstanceGroup.mDefault);
|
||||
if (methodInstanceGroup.mMethodSpecializationMap != NULL)
|
||||
{
|
||||
for (auto& kv : *methodInstanceGroup.mMethodSpecializationMap)
|
||||
_FixMethod(kv.mValue);
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2830,6 +2848,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
if (!typeDef->mInternalAccessSet.IsEmpty())
|
||||
{
|
||||
BfInternalAccessSet* internalAccessSet;
|
||||
BF_ASSERT(!typeDef->IsEmitted());
|
||||
if (typeInstance->mInternalAccessMap.TryAdd(typeDef, NULL, &internalAccessSet))
|
||||
{
|
||||
for (auto typeRef : typeDef->mInternalAccessSet)
|
||||
|
@ -3973,6 +3992,7 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
|||
mCompiler->mCEMachine->mCurContext->Fail(*mCompiler->mCEMachine->mCurContext->mCurFrame, error);
|
||||
else if (mCompiler->mCEMachine->mCurContext != NULL)
|
||||
mCompiler->mCEMachine->mCurContext->Fail(error);
|
||||
tryCE = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8674,15 +8694,15 @@ BfTypeDef* BfModule::GetActiveTypeDef(BfTypeInstance* typeInstanceOverride, bool
|
|||
if (typeInstance != NULL)
|
||||
useTypeDef = typeInstance->mTypeDef->GetDefinition();
|
||||
if ((mCurMethodState != NULL) && (mCurMethodState->mMixinState != NULL) && (useMixinDecl))
|
||||
useTypeDef = mCurMethodState->mMixinState->mMixinMethodInstance->mMethodDef->mDeclaringType;
|
||||
useTypeDef = mCurMethodState->mMixinState->mMixinMethodInstance->mMethodDef->mDeclaringType->GetDefinition();
|
||||
else if ((mCurMethodInstance != NULL) && (mCurMethodInstance->mMethodDef->mDeclaringType != NULL))
|
||||
useTypeDef = mCurMethodInstance->mMethodDef->mDeclaringType;
|
||||
useTypeDef = mCurMethodInstance->mMethodDef->mDeclaringType->GetDefinition();
|
||||
else if (mContext->mCurTypeState != NULL)
|
||||
{
|
||||
if ((mContext->mCurTypeState->mCurFieldDef != NULL) && (mContext->mCurTypeState->mCurFieldDef->mDeclaringType != NULL))
|
||||
useTypeDef = mContext->mCurTypeState->mCurFieldDef->mDeclaringType;
|
||||
useTypeDef = mContext->mCurTypeState->mCurFieldDef->mDeclaringType->GetDefinition();
|
||||
else if (mContext->mCurTypeState->mCurTypeDef != NULL)
|
||||
useTypeDef = mContext->mCurTypeState->mCurTypeDef;
|
||||
useTypeDef = mContext->mCurTypeState->mCurTypeDef->GetDefinition();
|
||||
}
|
||||
return useTypeDef;
|
||||
}
|
||||
|
|
|
@ -526,6 +526,11 @@ bool BfMethodDef::IsDefaultCtor()
|
|||
return ((mMethodType == BfMethodType_Ctor) || (mMethodType == BfMethodType_CtorNoBody)) && (mParams.IsEmpty());
|
||||
}
|
||||
|
||||
bool BfMethodDef::IsCtorOrInit()
|
||||
{
|
||||
return (mMethodType >= BfMethodType_CtorCalcAppend) && (mMethodType <= BfMethodType_Init);
|
||||
}
|
||||
|
||||
String BfMethodDef::ToString()
|
||||
{
|
||||
String methodText;
|
||||
|
|
|
@ -870,6 +870,7 @@ public:
|
|||
bool HasBody();
|
||||
bool IsEmptyPartial();
|
||||
bool IsDefaultCtor();
|
||||
bool IsCtorOrInit();
|
||||
String ToString();
|
||||
int GetExplicitParamCount();
|
||||
};
|
||||
|
|
|
@ -5276,7 +5276,10 @@ void DbgExprEvaluator::LookupSplatMember(BfAstNode* targetNode, BfAstNode* looku
|
|||
if (!memberType->IsStruct())
|
||||
Fail("Failed to lookup splat member", (lookupNode != NULL) ? lookupNode : targetNode);
|
||||
|
||||
BF_ASSERT((target.mVariable != NULL) || (target.mType->GetByteCount() == 0));
|
||||
if ((target.mVariable == NULL) && (target.mType->GetByteCount() != 0))
|
||||
Fail("Splat variable not found", (lookupNode != NULL) ? lookupNode : targetNode);
|
||||
|
||||
//BF_ASSERT((target.mVariable != NULL) || (target.mType->GetByteCount() == 0));
|
||||
mResult = target;
|
||||
mResult.mType = memberType;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue