Bläddra i källkod

Added CeEvalFlags_IgnoreConstEncodeFailure

Brian Fiete 1 år sedan
förälder
incheckning
dfa03f16dd

+ 1 - 1
IDEHelper/Compiler/BfModuleTypeUtils.cpp

@@ -2523,7 +2523,7 @@ void BfModule::HandleCEAttributes(CeEmitContext* ceEmitContext, BfTypeInstance*
 				callSource.mKind = CeCallSource::Kind_TypeDone;
 			}
 
-			result = ceContext->Call(callSource, this, methodInstance, args, CeEvalFlags_ForceReturnThis, NULL);
+			result = ceContext->Call(callSource, this, methodInstance, args, (CeEvalFlags)(CeEvalFlags_ForceReturnThis | CeEvalFlags_IgnoreConstEncodeFailure), NULL);
 		}
 		if (fieldInstance != NULL)
 			mCompiler->mCeMachine->mFieldInstanceSet.Remove(fieldInstance);

+ 15 - 7
IDEHelper/Compiler/CeMachine.cpp

@@ -4801,8 +4801,9 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
 				return instResult;
 			}
 
-			Fail(StrFormat("Span return type '%s' must be received by a sized array", module->TypeToString(typeInst).c_str()));
-			return BfIRValue();
+			if ((mCurEvalFlags & CeEvalFlags_IgnoreConstEncodeFailure) == 0)
+				Fail(StrFormat("Span return type '%s' must be received by a sized array", module->TypeToString(typeInst).c_str()));
+			return irBuilder->CreateConstAggZero(irBuilder->MapType(typeInst));
 		}
 
 		if (typeInst->IsInstanceOf(ceModule->mCompiler->mTypeTypeDef))
@@ -4824,6 +4825,11 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
 			addr_ce typeId = *(int*)(instData);
 
 			BfType* type = GetBfType(typeId);
+			if (type == NULL)
+			{
+				Fail("Unable to locate type");
+				return BfIRValue();
+			}
 
 			if (type->IsInstanceOf(mCeMachine->mCompiler->mStringTypeDef))
 			{
@@ -4860,8 +4866,9 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
 
 		if (typeInst->IsObjectOrInterface())
 		{
-			Fail(StrFormat("Reference type '%s' return value not allowed", module->TypeToString(typeInst).c_str()));
-			return BfIRValue();
+			if ((mCurEvalFlags & CeEvalFlags_IgnoreConstEncodeFailure) == 0)
+				Fail(StrFormat("Reference type '%s' return value not allowed", module->TypeToString(typeInst).c_str()));
+			return irBuilder->CreateConstNull(irBuilder->MapType(typeInst));
 		}
 
 		if (typeInst->mBaseType != NULL)
@@ -4931,8 +4938,9 @@ BfIRValue CeContext::CreateConstant(BfModule* module, uint8* ptr, BfType* bfType
 
 	if (bfType->IsPointer())
 	{
-		Fail(StrFormat("Pointer type '%s' return value not allowed", module->TypeToString(bfType).c_str()));
-		return BfIRValue();
+		if ((mCurEvalFlags & CeEvalFlags_IgnoreConstEncodeFailure) == 0)
+			Fail(StrFormat("Pointer type '%s' return value not allowed", module->TypeToString(bfType).c_str()));
+		return irBuilder->CreateConstNull(irBuilder->MapType(bfType));
 	}
 
 	if ((bfType->IsSizedArray()) && (!bfType->IsUnknownSizedArrayType()))
@@ -7575,7 +7583,7 @@ bool CeContext::Execute(CeFunction* startFunction, uint8* startStackPtr, uint8*
 				auto valueType = GetBfType(objTypeId);
 				if ((ifaceType == NULL) || (valueType == NULL))
 				{
-					_Fail("Invalid type");
+					_Fail("Invalid type in CeOp_DynamicCastCheck");
 					return false;
 				}
 

+ 2 - 1
IDEHelper/Compiler/CeMachine.h

@@ -700,7 +700,8 @@ enum CeEvalFlags
 	CeEvalFlags_DeferIfNotOnlyError = 4,
 	CeEvalFlags_NoRebuild = 8,
 	CeEvalFlags_ForceReturnThis = 0x10,
-	CeEvalFlags_DbgCall = 0x20
+	CeEvalFlags_IgnoreConstEncodeFailure = 0x20,
+	CeEvalFlags_DbgCall = 0x40
 };
 
 #define BF_CE_DEFAULT_STACK_SIZE 4*1024*1024