mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Fixed enum underlying resolution with extension, ToString of void enum
This commit is contained in:
parent
28783a6b5a
commit
237b507745
2 changed files with 35 additions and 22 deletions
|
@ -18839,7 +18839,9 @@ void BfModule::EmitEnumToStringBody()
|
||||||
paramTypes.Add(stringType);
|
paramTypes.Add(stringType);
|
||||||
auto appendModuleMethodInstance = GetMethodByName(stringType->ToTypeInstance(), "Append", paramTypes);
|
auto appendModuleMethodInstance = GetMethodByName(stringType->ToTypeInstance(), "Append", paramTypes);
|
||||||
|
|
||||||
auto switchVal = mBfIRBuilder->CreateSwitch(enumVal, noMatchBlock, (int)mCurTypeInstance->mFieldInstances.size());
|
BfIRValue switchVal;
|
||||||
|
if (!mCurTypeInstance->IsValuelessType())
|
||||||
|
switchVal = mBfIRBuilder->CreateSwitch(enumVal, noMatchBlock, (int)mCurTypeInstance->mFieldInstances.size());
|
||||||
|
|
||||||
HashSet<int64> handledCases;
|
HashSet<int64> handledCases;
|
||||||
for (auto& fieldInstance : mCurTypeInstance->mFieldInstances)
|
for (auto& fieldInstance : mCurTypeInstance->mFieldInstances)
|
||||||
|
@ -18847,13 +18849,13 @@ void BfModule::EmitEnumToStringBody()
|
||||||
if (fieldInstance.mIsEnumPayloadCase)
|
if (fieldInstance.mIsEnumPayloadCase)
|
||||||
{
|
{
|
||||||
int tagId = -fieldInstance.mDataIdx - 1;
|
int tagId = -fieldInstance.mDataIdx - 1;
|
||||||
|
|
||||||
BfIRBlock caseBlock = mBfIRBuilder->CreateBlock("case");
|
BfIRBlock caseBlock = mBfIRBuilder->CreateBlock("case");
|
||||||
mBfIRBuilder->AddBlock(caseBlock);
|
mBfIRBuilder->AddBlock(caseBlock);
|
||||||
mBfIRBuilder->SetInsertPoint(caseBlock);
|
mBfIRBuilder->SetInsertPoint(caseBlock);
|
||||||
|
|
||||||
BF_ASSERT(discriminatorType->IsPrimitiveType());
|
BF_ASSERT(discriminatorType->IsPrimitiveType());
|
||||||
auto constVal = mBfIRBuilder->CreateConst(((BfPrimitiveType*)discriminatorType)->mTypeDef->mTypeCode, tagId);
|
auto constVal = mBfIRBuilder->CreateConst(((BfPrimitiveType*)discriminatorType)->mTypeDef->mTypeCode, tagId);
|
||||||
mBfIRBuilder->AddSwitchCase(switchVal, constVal, caseBlock);
|
mBfIRBuilder->AddSwitchCase(switchVal, constVal, caseBlock);
|
||||||
|
|
||||||
auto caseStr = GetStringObjectValue(fieldInstance.GetFieldDef()->mName);
|
auto caseStr = GetStringObjectValue(fieldInstance.GetFieldDef()->mName);
|
||||||
|
|
||||||
|
@ -18882,7 +18884,7 @@ void BfModule::EmitEnumToStringBody()
|
||||||
irArgs.Add(stringDestVal.mValue);
|
irArgs.Add(stringDestVal.mValue);
|
||||||
exprEvaluator.CreateCall(NULL, toStringMethod.mMethodInstance, toStringMethod.mFunc, true, irArgs);
|
exprEvaluator.CreateCall(NULL, toStringMethod.mMethodInstance, toStringMethod.mFunc, true, irArgs);
|
||||||
}
|
}
|
||||||
|
|
||||||
mBfIRBuilder->CreateBr(endBlock);
|
mBfIRBuilder->CreateBr(endBlock);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -18903,12 +18905,15 @@ void BfModule::EmitEnumToStringBody()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BfIRBlock caseBlock = mBfIRBuilder->CreateBlock("case");
|
if (switchVal)
|
||||||
mBfIRBuilder->AddBlock(caseBlock);
|
{
|
||||||
mBfIRBuilder->SetInsertPoint(caseBlock);
|
BfIRBlock caseBlock = mBfIRBuilder->CreateBlock("case");
|
||||||
|
mBfIRBuilder->AddBlock(caseBlock);
|
||||||
|
mBfIRBuilder->SetInsertPoint(caseBlock);
|
||||||
|
|
||||||
BfIRValue constVal = ConstantToCurrent(constant, mCurTypeInstance->mConstHolder, mCurTypeInstance);
|
BfIRValue constVal = ConstantToCurrent(constant, mCurTypeInstance->mConstHolder, mCurTypeInstance);
|
||||||
mBfIRBuilder->AddSwitchCase(switchVal, constVal, caseBlock);
|
mBfIRBuilder->AddSwitchCase(switchVal, constVal, caseBlock);
|
||||||
|
}
|
||||||
|
|
||||||
auto caseStr = GetStringObjectValue(fieldInstance.GetFieldDef()->mName);
|
auto caseStr = GetStringObjectValue(fieldInstance.GetFieldDef()->mName);
|
||||||
mBfIRBuilder->CreateStore(caseStr, strVal);
|
mBfIRBuilder->CreateStore(caseStr, strVal);
|
||||||
|
@ -18923,21 +18928,25 @@ void BfModule::EmitEnumToStringBody()
|
||||||
args.Add(stringDestVal.mValue);
|
args.Add(stringDestVal.mValue);
|
||||||
args.Add(mBfIRBuilder->CreateLoad(strVal));
|
args.Add(mBfIRBuilder->CreateLoad(strVal));
|
||||||
exprEvaluator.CreateCall(NULL, appendModuleMethodInstance.mMethodInstance, appendModuleMethodInstance.mFunc, false, args);
|
exprEvaluator.CreateCall(NULL, appendModuleMethodInstance.mMethodInstance, appendModuleMethodInstance.mFunc, false, args);
|
||||||
mBfIRBuilder->CreateBr(endBlock);
|
|
||||||
|
|
||||||
mBfIRBuilder->AddBlock(noMatchBlock);
|
if (switchVal)
|
||||||
mBfIRBuilder->SetInsertPoint(noMatchBlock);
|
{
|
||||||
auto int64Val = mBfIRBuilder->CreateNumericCast(enumVal, false, BfTypeCode_Int64);
|
mBfIRBuilder->CreateBr(endBlock);
|
||||||
auto toStringModuleMethodInstance = GetMethodByName(int64StructType, "ToString", 1);
|
|
||||||
args.clear();
|
|
||||||
args.Add(int64Val);
|
|
||||||
stringDestVal = LoadValue(stringDestAddr);
|
|
||||||
args.Add(stringDestVal.mValue);
|
|
||||||
exprEvaluator.CreateCall(NULL, toStringModuleMethodInstance.mMethodInstance, toStringModuleMethodInstance.mFunc, false, args);
|
|
||||||
mBfIRBuilder->CreateBr(endBlock);
|
|
||||||
|
|
||||||
mBfIRBuilder->AddBlock(endBlock);
|
mBfIRBuilder->AddBlock(noMatchBlock);
|
||||||
mBfIRBuilder->SetInsertPoint(endBlock);
|
mBfIRBuilder->SetInsertPoint(noMatchBlock);
|
||||||
|
auto int64Val = mBfIRBuilder->CreateNumericCast(enumVal, false, BfTypeCode_Int64);
|
||||||
|
auto toStringModuleMethodInstance = GetMethodByName(int64StructType, "ToString", 1);
|
||||||
|
args.clear();
|
||||||
|
args.Add(int64Val);
|
||||||
|
stringDestVal = LoadValue(stringDestAddr);
|
||||||
|
args.Add(stringDestVal.mValue);
|
||||||
|
exprEvaluator.CreateCall(NULL, toStringModuleMethodInstance.mMethodInstance, toStringModuleMethodInstance.mFunc, false, args);
|
||||||
|
mBfIRBuilder->CreateBr(endBlock);
|
||||||
|
|
||||||
|
mBfIRBuilder->AddBlock(endBlock);
|
||||||
|
mBfIRBuilder->SetInsertPoint(endBlock);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BfModule::EmitTupleToStringBody()
|
void BfModule::EmitTupleToStringBody()
|
||||||
|
|
|
@ -3955,6 +3955,10 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
|
||||||
|
|
||||||
for (auto baseTypeRef : typeDef->mBaseTypes)
|
for (auto baseTypeRef : typeDef->mBaseTypes)
|
||||||
{
|
{
|
||||||
|
auto declTypeDef = typeDef;
|
||||||
|
if (typeDef->mIsCombinedPartial)
|
||||||
|
declTypeDef = typeDef->mPartials.front();
|
||||||
|
SetAndRestoreValue<BfTypeDef*> prevTypeDef(mContext->mCurTypeState->mCurTypeDef, declTypeDef);
|
||||||
SetAndRestoreValue<BfTypeReference*> prevTypeRef(mContext->mCurTypeState->mCurBaseTypeRef, baseTypeRef);
|
SetAndRestoreValue<BfTypeReference*> prevTypeRef(mContext->mCurTypeState->mCurBaseTypeRef, baseTypeRef);
|
||||||
SetAndRestoreValue<BfTypeDefineState> prevDefineState(typeInstance->mDefineState, BfTypeDefineState_ResolvingBaseType);
|
SetAndRestoreValue<BfTypeDefineState> prevDefineState(typeInstance->mDefineState, BfTypeDefineState_ResolvingBaseType);
|
||||||
SetAndRestoreValue<bool> prevIgnoreError(mIgnoreErrors, true);
|
SetAndRestoreValue<bool> prevIgnoreError(mIgnoreErrors, true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue