1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-13 05:44:11 +02:00

Fix '_' in appended field dtors, fixed implicit-ctor static append

This commit is contained in:
Brian Fiete 2022-07-11 08:16:57 -04:00
parent d695434add
commit 627b0381f8

View file

@ -16896,14 +16896,13 @@ void BfModule::CreateStaticCtor()
{ {
for (auto fieldDef : typeDef->mFields) for (auto fieldDef : typeDef->mFields)
{ {
if ((!fieldDef->mIsConst) && (fieldDef->mIsStatic) && (fieldDef->GetInitializer() != NULL)) if ((!fieldDef->mIsConst) && (fieldDef->mIsStatic))
{ {
// For extensions, only handle these fields in the appropriate extension // For extensions, only handle these fields in the appropriate extension
if ((fieldDef->mDeclaringType->mTypeDeclaration != methodDef->mDeclaringType->mTypeDeclaration)) if ((fieldDef->mDeclaringType->mTypeDeclaration != methodDef->mDeclaringType->mTypeDeclaration))
continue; continue;
UpdateSrcPos(fieldDef->GetInitializer()); auto initializer = fieldDef->GetInitializer();
auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldDef->mIdx]; auto fieldInst = &mCurTypeInstance->mFieldInstances[fieldDef->mIdx];
if (!fieldInst->mFieldIncluded) if (!fieldInst->mFieldIncluded)
continue; continue;
@ -16911,12 +16910,18 @@ void BfModule::CreateStaticCtor()
{ {
continue; continue;
} }
if (fieldInst->IsAppendedObject()) if (fieldInst->IsAppendedObject())
{
AppendedObjectInit(fieldInst); AppendedObjectInit(fieldInst);
else }
else if (initializer != NULL)
{
UpdateSrcPos(initializer);
GetFieldInitializerValue(fieldInst, NULL, NULL, NULL, true); GetFieldInitializerValue(fieldInst, NULL, NULL, NULL, true);
} }
} }
}
auto _CheckInitBlock = [&](BfAstNode* node) auto _CheckInitBlock = [&](BfAstNode* node)
{ {
@ -17106,8 +17111,14 @@ void BfModule::EmitDtorBody()
BfLocalVariable* localDef = new BfLocalVariable(); BfLocalVariable* localDef = new BfLocalVariable();
localDef->mName = "_"; localDef->mName = "_";
localDef->mResolvedType = fieldInst->mResolvedType; localDef->mResolvedType = fieldInst->mResolvedType;
localDef->mAddr = value;
if (fieldInst->IsAppendedObject())
{
localDef->mValue = mBfIRBuilder->CreateBitCast(value, mBfIRBuilder->MapType(fieldInst->mResolvedType));
}
else
{
localDef->mAddr = value;
if ((mBfIRBuilder->DbgHasInfo()) && (!IsTargetingBeefBackend())) if ((mBfIRBuilder->DbgHasInfo()) && (!IsTargetingBeefBackend()))
{ {
// Create another pointer indirection, a ref to the gep // Create another pointer indirection, a ref to the gep
@ -17120,14 +17131,19 @@ void BfModule::EmitDtorBody()
localDef->mResolvedType = refFieldType; localDef->mResolvedType = refFieldType;
localDef->mAddr = allocaInst; localDef->mAddr = allocaInst;
} }
}
mBfIRBuilder->RestoreDebugLocation(); mBfIRBuilder->RestoreDebugLocation();
auto defLocalVar = AddLocalVariableDef(localDef, true); auto defLocalVar = AddLocalVariableDef(localDef, true);
if (!fieldInst->IsAppendedObject())
{
// Put back so we actually modify the correct value*/ // Put back so we actually modify the correct value*/
defLocalVar->mResolvedType = fieldInst->mResolvedType; defLocalVar->mResolvedType = fieldInst->mResolvedType;
defLocalVar->mAddr = value; defLocalVar->mAddr = value;
} }
}
while (fieldDtor != NULL) while (fieldDtor != NULL)
{ {