mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Cache ConstExpr ToString, fix const arg int comparison in cast
This commit is contained in:
parent
337a94b8b5
commit
d341104a57
5 changed files with 27 additions and 11 deletions
|
@ -2193,8 +2193,13 @@ void BfContext::UpdateRevisedTypes()
|
|||
}
|
||||
|
||||
// Rebuild all types
|
||||
Array<BfType*> allTypes;
|
||||
for (auto type : mResolvedTypes)
|
||||
allTypes.Add(type);
|
||||
|
||||
for (auto type : allTypes)
|
||||
{
|
||||
if (!type->IsDeleting())
|
||||
RebuildType(type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -466,6 +466,11 @@ void BfIRConstHolder::pv(const BfIRValue& irValue)
|
|||
|
||||
void BfIRConstHolder::FixTypeCode(BfTypeCode& typeCode)
|
||||
{
|
||||
if (typeCode == BfTypeCode_IntUnknown)
|
||||
typeCode = BfTypeCode_Int64;
|
||||
if (typeCode == BfTypeCode_UIntUnknown)
|
||||
typeCode = BfTypeCode_UInt64;
|
||||
|
||||
if (typeCode == BfTypeCode_IntPtr)
|
||||
{
|
||||
if (mModule->mSystem->mPtrSize == 4)
|
||||
|
@ -740,11 +745,6 @@ BfIRType BfIRConstHolder::GetSizedArrayType(BfIRType elementType, int length)
|
|||
|
||||
BfIRValue BfIRConstHolder::CreateConst(BfTypeCode typeCode, uint64 val)
|
||||
{
|
||||
if (typeCode == BfTypeCode_IntUnknown)
|
||||
typeCode = BfTypeCode_Int64;
|
||||
else if (typeCode == BfTypeCode_UIntUnknown)
|
||||
typeCode = BfTypeCode_UInt64;
|
||||
|
||||
FixTypeCode(typeCode);
|
||||
BfConstant* constant = mTempAlloc.Alloc<BfConstant>();
|
||||
constant->mTypeCode = typeCode;
|
||||
|
|
|
@ -12842,6 +12842,13 @@ BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue&
|
|||
case BfTypeCode_Char32:
|
||||
case BfTypeCode_StringId:
|
||||
variant.mTypeCode = constant->mTypeCode;
|
||||
if (((variant.mTypeCode == BfTypeCode_Int64) || (variant.mTypeCode == BfTypeCode_UInt64)) &&
|
||||
(primType->mSize > 0) && (primType->mSize < 8) &&
|
||||
(mBfIRBuilder->IsIntable(primType->GetTypeCode())))
|
||||
{
|
||||
// We may have an 'int unknown' that we need to downsize
|
||||
variant.mTypeCode = primType->GetTypeCode();
|
||||
}
|
||||
variant.mInt64 = constant->mInt64;
|
||||
break;
|
||||
case BfTypeCode_Float:
|
||||
|
|
|
@ -13786,7 +13786,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
auto variantVal = TypedValueToVariant(srcNode, typedVal, true);
|
||||
if ((mBfIRBuilder->IsIntable(variantVal.mTypeCode)) && (mBfIRBuilder->IsIntable(toConstExprValueType->mValue.mTypeCode)))
|
||||
{
|
||||
if (variantVal == toConstExprValueType->mValue)
|
||||
if (variantVal.mUInt64 == toConstExprValueType->mValue.mUInt64)
|
||||
return typedVal.mValue;
|
||||
}
|
||||
else if ((mBfIRBuilder->IsFloat(variantVal.mTypeCode)) && (mBfIRBuilder->IsFloat(toConstExprValueType->mValue.mTypeCode)))
|
||||
|
@ -16210,7 +16210,10 @@ void BfModule::DoTypeToString(StringImpl& str, BfType* resolvedType, BfTypeNameF
|
|||
}
|
||||
}
|
||||
|
||||
VariantToString(str, constExprValueType->mValue, constExprValueType->mType);
|
||||
if (constExprValueType->mValueString.IsEmpty())
|
||||
VariantToString(constExprValueType->mValueString, constExprValueType->mValue, constExprValueType->mType);
|
||||
|
||||
str += constExprValueType->mValueString;
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2611,6 +2611,7 @@ class BfConstExprValueType : public BfDependedType
|
|||
public:
|
||||
BfType* mType;
|
||||
BfVariant mValue;
|
||||
String mValueString;
|
||||
|
||||
public:
|
||||
~BfConstExprValueType();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue