Procházet zdrojové kódy

Fixed deriving from "valueless" crepr struct

Brian Fiete před 4 měsíci
rodič
revize
eb41a9c1de

+ 9 - 1
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -4615,7 +4615,15 @@ void BfModule::DoPopulateType(BfType* resolvedTypeRef, BfPopulateType populateTy
 			typeInstance->mInstSize = baseTypeInst->mInstSize;
 			typeInstance->mInstAlign = baseTypeInst->mInstAlign;
 			typeInstance->mAlign = baseTypeInst->mAlign;
-			typeInstance->mSize = baseTypeInst->mSize;
+			typeInstance->mSize = baseTypeInst->mSize;	
+
+ 			if (baseTypeInst->IsValuelessCReprType())
+			{
+				typeInstance->mInstSize = 0;
+				if (typeInstance->IsValueType())
+					typeInstance->mSize = 0;
+			}
+
 			typeInstance->mHasPackingHoles = baseTypeInst->mHasPackingHoles;
 			if (baseTypeInst->mIsTypedPrimitive)
 				typeInstance->mIsTypedPrimitive = true;

+ 19 - 0
IDEHelper/Compiler/BfResolvedTypeUtils.cpp

@@ -2861,6 +2861,25 @@ bool BfTypeInstance::IsValuelessType()
 	return false;
 }
 
+bool BfTypeInstance::IsValuelessCReprType()
+{
+	if (!mIsCRepr)
+		return false;
+	if (mInstSize > 1)
+		return false;
+	if ((mBaseType->mIsCRepr) && (!IsValuelessCReprType()))
+		return false;
+
+	BF_ASSERT((mDefineState >= BfTypeDefineState_Defined) || (mTypeFailed));
+	for (auto& fieldInst : mFieldInstances)
+	{
+		if (fieldInst.mDataIdx >= 0)
+			return false;
+	}
+
+	return true;
+}
+
 bool BfTypeInstance::IsIRFuncUsed(BfIRFunction func)
 {
 	for (auto& group : mMethodInstanceGroups)

+ 1 - 0
IDEHelper/Compiler/BfResolvedTypeUtils.h

@@ -2175,6 +2175,7 @@ public:
 	//virtual bool IsValuelessType() override { return (mIsTypedPrimitive) && (mInstSize == 0); }
 	virtual bool CanBeValuelessType() override { return (mTypeDef->mTypeCode == BfTypeCode_Struct) || (mTypeDef->mTypeCode == BfTypeCode_Enum); }
 	virtual bool IsValuelessType() override;
+	virtual bool IsValuelessCReprType();
 	virtual bool HasPackingHoles() override { return mHasPackingHoles; }
 	virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfTypeDef* activeTypeDef) override;
 	virtual bool IsTypeMemberAccessible(BfTypeDef* declaringTypeDef, BfProject* curProject) override;