1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 12:32:20 +02:00

Fixed 'case' for pointer to enums

This commit is contained in:
Brian Fiete 2020-03-24 15:25:43 -07:00
parent 598765d437
commit 9bd71299d9
2 changed files with 19 additions and 43 deletions

View file

@ -2460,6 +2460,13 @@ void BfExprEvaluator::Visit(BfCaseExpression* caseExpr)
BfTypedValue caseValAddr;
if (caseExpr->mValueExpression != NULL)
caseValAddr = mModule->CreateValueFromExpression(caseExpr->mValueExpression);
if ((caseValAddr.mType != NULL) && (caseValAddr.mType->IsPointer()))
{
caseValAddr = mModule->LoadValue(caseValAddr);
caseValAddr = BfTypedValue(caseValAddr.mValue, caseValAddr.mType->GetUnderlyingType(), true);
}
if (caseValAddr.mType != NULL)
mModule->mBfIRBuilder->PopulateType(caseValAddr.mType);
@ -2563,13 +2570,7 @@ void BfExprEvaluator::Visit(BfCaseExpression* caseExpr)
auto boolType = mModule->GetPrimitiveType(BfTypeCode_Boolean);
mResult = mModule->GetDefaultTypedValue(boolType);
return;
}
if ((caseValAddr.mType != NULL) && (caseValAddr.mType->IsPointer()))
{
caseValAddr = mModule->LoadValue(caseValAddr);
caseValAddr = BfTypedValue(caseValAddr.mValue, caseValAddr.mType->GetUnderlyingType(), true);
}
}
auto boolType = mModule->GetPrimitiveType(BfTypeCode_Boolean);
BfTypedValue caseMatch;

View file

@ -3890,6 +3890,16 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
switchValue = GetDefaultTypedValue(mContext->mBfObjectType);
}
if (switchValue.mType->IsPointer())
{
auto underlyingType = switchValue.mType->GetUnderlyingType();
if (underlyingType->IsEnum())
{
switchValue = LoadValue(switchValue);
switchValue = BfTypedValue(switchValue.mValue, underlyingType, true);
}
}
// We make the switch value conditional, but all other uses of this scope is conditional since it's conditional on cases
newScope.mInnerIsConditional = true;
@ -3988,42 +3998,7 @@ void BfModule::Visit(BfSwitchStatement* switchStmt)
localDef->mIsSplat = false;
}
}
}
// bool firstCaseHandled = false;
// if (!switchStmt->mSwitchCases.IsEmpty())
// {
// auto switchCase = switchStmt->mSwitchCases[0];
// if (switchCase->mCaseExpressions.size() == 0)
// {
// auto caseExpr = switchCase->mCaseExpressions[0];
// if (auto literalExpr = BfNodeDynCast<BfLiteralExpression>(caseExpr))
// {
// if (literalExpr->mValue.mTypeCode == BfTypeCode_NullPtr)
// {
// }
// }
// }
// }
BfIRBlock derefBlock;
BfIRBlock derefContBlock;
BfTypedValue derefSwitchValue;
if (switchValue.mType->IsPointer())
{
auto underlyingType = switchValue.mType->GetUnderlyingType();
if (underlyingType->IsEnum())
{
derefSwitchValue = BfTypedValue(switchValue.mValue, underlyingType, true);
derefBlock = mBfIRBuilder->CreateBlock("switch.deref");
derefContBlock = mBfIRBuilder->CreateBlock("switch.deref");
mBfIRBuilder->AddBlock(derefContBlock);
mBfIRBuilder->SetInsertPoint(derefContBlock);
}
}
}
AddLocalVariableDef(localDef, addDebugInfo, true);