Sfoglia il codice sorgente

Make initializer expression work with 'in' ref values

Brian Fiete 10 mesi fa
parent
commit
b34a14502d

+ 5 - 2
IDEHelper/Compiler/BfExprEvaluator.cpp

@@ -11625,7 +11625,10 @@ void BfExprEvaluator::Visit(BfInitializerExpression* initExpr)
 		mModule->mBfIRBuilder->SetInsertPoint(initBlock);
 	}
 
-	BfTypedValue initValue = GetResult(true);
+	BfTypedValue origInitValue = GetResult(true);
+	BfTypedValue initValue = origInitValue;
+	if ((initValue) && (initValue.mType->IsRef()))	
+		initValue = mModule->RemoveRef(initValue, false);
 	bool isFirstAdd = true;
 
 	for (auto elementExpr : initExpr->mValues)
@@ -11749,7 +11752,7 @@ void BfExprEvaluator::Visit(BfInitializerExpression* initExpr)
 		mModule->mBfIRBuilder->SetInsertPoint(curBlock);
 	}
 
-	mResult = initValue;
+	mResult = origInitValue;
 }
 
 void BfExprEvaluator::Visit(BfCollectionInitializerExpression* arrayInitExpr)

+ 2 - 2
IDEHelper/Compiler/BfModule.cpp

@@ -12944,7 +12944,7 @@ BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue&
 	return variant;
 }
 
-BfTypedValue BfModule::RemoveRef(BfTypedValue typedValue)
+BfTypedValue BfModule::RemoveRef(BfTypedValue typedValue, bool makeInReadOnly)
 {
 	if ((typedValue.mType != NULL) && (typedValue.mType->IsRef()))
 	{
@@ -12969,7 +12969,7 @@ BfTypedValue BfModule::RemoveRef(BfTypedValue typedValue)
 			BF_ASSERT(typedValue.mValue.IsFake());
 		}
 
-		if (refType->mRefKind == BfRefType::RefKind_In)
+		if ((refType->mRefKind == BfRefType::RefKind_In) && (makeInReadOnly))
 		{
 			if (typedValue.mKind == BfTypedValueKind_Addr)
 				typedValue.mKind = BfTypedValueKind_ReadOnlyAddr;

+ 1 - 1
IDEHelper/Compiler/BfModule.h

@@ -1752,7 +1752,7 @@ public:
 	void EmitDynamicCastCheck(const BfTypedValue& targetValue, BfType* targetType, BfIRBlock trueBlock, BfIRBlock falseBlock, bool nullSucceeds = false);
 	void EmitDynamicCastCheck(BfTypedValue typedVal, BfType* type, bool allowNull);
 	void CheckStaticAccess(BfTypeInstance* typeInstance);
-	BfTypedValue RemoveRef(BfTypedValue typedValue);
+	BfTypedValue RemoveRef(BfTypedValue typedValue, bool makeInReadOnly = true);
 	BfTypedValue SanitizeAddr(BfTypedValue typedValue);
 	BfTypedValue ToRef(BfTypedValue typedValue, BfRefType* refType = NULL);
 	BfTypedValue LoadOrAggregateValue(BfTypedValue typedValue);