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

Fixed const expr creation during box checking

This commit is contained in:
Brian Fiete 2020-09-15 14:06:10 -07:00
parent 7e0c25ef8f
commit 006e738f69
2 changed files with 14 additions and 7 deletions

View file

@ -1647,7 +1647,7 @@ public:
BfUnknownSizedArrayType* CreateUnknownSizedArrayType(BfType* resolvedType, BfType* sizeParam);
BfPointerType* CreatePointerType(BfType* resolvedType);
BfPointerType* CreatePointerType(BfTypeReference* typeRef);
BfConstExprValueType* CreateConstExprValueType(const BfTypedValue& typedValue);
BfConstExprValueType* CreateConstExprValueType(const BfTypedValue& typedValue, bool allowCreate = true);
BfBoxedType* CreateBoxedType(BfType* resolvedTypeRef, bool allowCreate = true);
BfTypeInstance* CreateTupleType(const BfTypeVector& fieldTypes, const Array<String>& fieldNames, bool allowVar = false);
BfTypeInstance* SantizeTupleType(BfTypeInstance* tupleType);

View file

@ -4939,8 +4939,11 @@ BfPointerType* BfModule::CreatePointerType(BfType* resolvedType)
return resolvedPointerType;
}
BfConstExprValueType* BfModule::CreateConstExprValueType(const BfTypedValue& typedValue)
BfConstExprValueType* BfModule::CreateConstExprValueType(const BfTypedValue& typedValue, bool allowCreate)
{
BfPopulateType populateType = allowCreate ? BfPopulateType_Data : BfPopulateType_Identity;
BfResolveTypeRefFlags resolveFlags = allowCreate ? BfResolveTypeRefFlag_None : BfResolveTypeRefFlag_NoCreate;
auto variant = TypedValueToVariant(NULL, typedValue);
if (variant.mTypeCode == BfTypeCode_None)
return NULL;
@ -4950,10 +4953,11 @@ BfConstExprValueType* BfModule::CreateConstExprValueType(const BfTypedValue& typ
constExprValueType->mType = typedValue.mType;
constExprValueType->mValue = variant;
auto resolvedConstExprValueType = (BfConstExprValueType*)ResolveType(constExprValueType);
auto resolvedConstExprValueType = (BfConstExprValueType*)ResolveType(constExprValueType, populateType, resolveFlags);
if (resolvedConstExprValueType != constExprValueType)
mContext->mConstExprValueTypePool.GiveBack(constExprValueType);
if (resolvedConstExprValueType != NULL)
BF_ASSERT(resolvedConstExprValueType->mValue.mInt64 == constExprValueType->mValue.mInt64);
return resolvedConstExprValueType;
@ -5410,7 +5414,10 @@ BfBoxedType* BfModule::CreateBoxedType(BfType* resolvedTypeRef, bool allowCreate
BfTypeVector typeVector;
typeVector.Add(sizedArrayType->mElementType);
auto sizeValue = BfTypedValue(GetConstValue(sizedArrayType->mElementCount), GetPrimitiveType(BfTypeCode_IntPtr));
typeVector.Add(CreateConstExprValueType(sizeValue));
auto sizeValueType = CreateConstExprValueType(sizeValue, allowCreate);
if (sizeValueType == NULL)
return NULL;
typeVector.Add(sizeValueType);
resolvedTypeRef = ResolveTypeDef(mCompiler->mSizedArrayTypeDef, typeVector, populateType, resolveFlags);
if (resolvedTypeRef == NULL)
return NULL;