mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-15 23:04:09 +02:00
Improved generic constraint const conversion handling
This commit is contained in:
parent
c750ed076c
commit
e5c4321440
4 changed files with 35 additions and 3 deletions
|
@ -461,6 +461,18 @@ int BfIRConstHolder::IsZero(BfIRValue value)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BfIRConstHolder::IsConstValue(BfIRValue value)
|
||||||
|
{
|
||||||
|
auto constant = GetConstant(value);
|
||||||
|
if (constant == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (constant->mConstType == BfConstType_GlobalVar)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
int BfIRConstHolder::CheckConstEquality(BfIRValue lhs, BfIRValue rhs)
|
int BfIRConstHolder::CheckConstEquality(BfIRValue lhs, BfIRValue rhs)
|
||||||
{
|
{
|
||||||
auto constLHS = GetConstant(lhs);
|
auto constLHS = GetConstant(lhs);
|
||||||
|
|
|
@ -948,6 +948,7 @@ public:
|
||||||
BfConstant* GetConstant(BfIRValue id);
|
BfConstant* GetConstant(BfIRValue id);
|
||||||
bool TryGetBool(BfIRValue id, bool& boolVal);
|
bool TryGetBool(BfIRValue id, bool& boolVal);
|
||||||
int IsZero(BfIRValue val);
|
int IsZero(BfIRValue val);
|
||||||
|
bool IsConstValue(BfIRValue val);
|
||||||
int CheckConstEquality(BfIRValue lhs, BfIRValue rhs); // -1 = fail, 0 = false, 1 = true
|
int CheckConstEquality(BfIRValue lhs, BfIRValue rhs); // -1 = fail, 0 = false, 1 = true
|
||||||
//void WriteConstant(void* data, BeConstant* constVal);
|
//void WriteConstant(void* data, BeConstant* constVal);
|
||||||
|
|
||||||
|
|
|
@ -13510,12 +13510,20 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
// .. and we can convert the constraint's toType to OUR toType then we're good
|
// .. and we can convert the constraint's toType to OUR toType then we're good
|
||||||
auto opToVal = genericParam->mExternType;
|
auto opToVal = genericParam->mExternType;
|
||||||
if (CanCast(BfTypedValue(BfIRValue::sValueless, opToVal), toType, BfCastFlags_NoConversionOperator))
|
if (CanCast(BfTypedValue(BfIRValue::sValueless, opToVal), toType, BfCastFlags_NoConversionOperator))
|
||||||
|
{
|
||||||
|
if (mBfIRBuilder->IsConstValue(typedVal.mValue))
|
||||||
|
{
|
||||||
|
// Retain constness
|
||||||
|
return mBfIRBuilder->GetUndefConstValue(mBfIRBuilder->MapType(toType));
|
||||||
|
}
|
||||||
|
else
|
||||||
return mBfIRBuilder->GetFakeVal();
|
return mBfIRBuilder->GetFakeVal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check type generic constraints
|
// Check type generic constraints
|
||||||
if ((mCurTypeInstance != NULL) && (mCurTypeInstance->IsGenericTypeInstance()) && (mCurTypeInstance->IsUnspecializedType()))
|
if ((mCurTypeInstance != NULL) && (mCurTypeInstance->IsGenericTypeInstance()) && (mCurTypeInstance->IsUnspecializedType()))
|
||||||
|
@ -13535,6 +13543,13 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
// .. and we can convert the constraint's toType to OUR toType then we're good
|
// .. and we can convert the constraint's toType to OUR toType then we're good
|
||||||
auto opToVal = genericParam->mExternType;
|
auto opToVal = genericParam->mExternType;
|
||||||
if (CanCast(BfTypedValue(BfIRValue::sValueless, opToVal), toType, BfCastFlags_NoConversionOperator))
|
if (CanCast(BfTypedValue(BfIRValue::sValueless, opToVal), toType, BfCastFlags_NoConversionOperator))
|
||||||
|
{
|
||||||
|
if (mBfIRBuilder->IsConstValue(typedVal.mValue))
|
||||||
|
{
|
||||||
|
// Retain constness
|
||||||
|
return mBfIRBuilder->GetUndefConstValue(mBfIRBuilder->MapType(toType));
|
||||||
|
}
|
||||||
|
else
|
||||||
return mBfIRBuilder->GetFakeVal();
|
return mBfIRBuilder->GetFakeVal();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13542,6 +13557,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (isConstraintCheck)
|
else if (isConstraintCheck)
|
||||||
{
|
{
|
||||||
auto result = BfTypedValue(mBfIRBuilder->GetFakeVal(), operatorConstraintReturnType);
|
auto result = BfTypedValue(mBfIRBuilder->GetFakeVal(), operatorConstraintReturnType);
|
||||||
|
|
|
@ -4409,6 +4409,9 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
|
||||||
if (bfType->IsTypedPrimitive())
|
if (bfType->IsTypedPrimitive())
|
||||||
return CreateConstant(module, ptr, bfType->GetUnderlyingType(), outType);
|
return CreateConstant(module, ptr, bfType->GetUnderlyingType(), outType);
|
||||||
|
|
||||||
|
if (bfType->IsGenericParam())
|
||||||
|
return irBuilder->GetUndefConstValue(irBuilder->MapType(bfType));
|
||||||
|
|
||||||
if (bfType->IsTypeInstance())
|
if (bfType->IsTypeInstance())
|
||||||
{
|
{
|
||||||
auto typeInst = bfType->ToTypeInstance();
|
auto typeInst = bfType->ToTypeInstance();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue