MCPcopy Create free account
hub / github.com/beefytech/Beef / CastToFunction

Method CastToFunction

IDEHelper/Compiler/BfModuleTypeUtils.cpp:13321–13438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13319}
13320
13321BfIRValue BfModule::CastToFunction(BfAstNode* srcNode, const BfTypedValue& targetValue, BfMethodInstance* methodInstance, BfType* toType, BfCastFlags castFlags, BfIRValue irFunc)
13322{
13323 auto invokeMethodInstance = GetDelegateInvokeMethod(toType->ToTypeInstance());
13324
13325 bool methodsThisMatch = true;
13326 if (invokeMethodInstance->mMethodDef->mIsStatic != methodInstance->mMethodDef->mIsStatic)
13327 methodsThisMatch = false;
13328 else
13329 {
13330 if (!methodInstance->mMethodDef->mIsStatic)
13331 {
13332 BfType* thisType = methodInstance->GetThisType();
13333 if (thisType->IsPointer())
13334 thisType = thisType->GetUnderlyingType();
13335 BfType* invokeThisType = invokeMethodInstance->GetThisType();
13336 if (invokeThisType->IsPointer())
13337 invokeThisType = invokeThisType->GetUnderlyingType();
13338 if (!TypeIsSubTypeOf(thisType->ToTypeInstance(), invokeThisType->ToTypeInstance()))
13339 methodsThisMatch = false;
13340 }
13341 }
13342
13343 bool methodMatches = methodsThisMatch;
13344 if (methodMatches)
13345 methodMatches = invokeMethodInstance->IsExactMatch(methodInstance, false, false);
13346
13347 if (methodMatches)
13348 {
13349 if (methodInstance->GetOwner()->IsFunction())
13350 {
13351 BF_ASSERT(targetValue);
13352 return targetValue.mValue;
13353 }
13354
13355 BfIRFunction bindFuncVal = irFunc;
13356 if (!bindFuncVal)
13357 {
13358 BfModuleMethodInstance methodRefMethod;
13359 if (methodInstance->mDeclModule == this)
13360 methodRefMethod = methodInstance;
13361 else
13362 methodRefMethod = ReferenceExternalMethodInstance(methodInstance);
13363 auto dataType = GetPrimitiveType(BfTypeCode_IntPtr);
13364 if (!methodRefMethod.mFunc)
13365 {
13366 if ((!methodInstance->mIsUnspecialized) && (HasCompiledOutput()))
13367 AssertErrorState();
13368 return GetDefaultTypedValue(dataType, false, BfDefaultValueKind_Value).mValue;
13369 }
13370 bindFuncVal = methodRefMethod.mFunc;
13371 }
13372 if ((mCompiler->mOptions.mAllowHotSwapping) && (!mIsComptimeModule))
13373 bindFuncVal = mBfIRBuilder->RemapBindFunction(bindFuncVal);
13374 return mBfIRBuilder->CreatePtrToInt(bindFuncVal, BfTypeCode_IntPtr);
13375 }
13376
13377 if ((castFlags & BfCastFlags_SilentFail) == 0)
13378 {

Callers 1

VisitMethod · 0.80

Calls 15

FailFunction · 0.85
TypeToStringFunction · 0.85
BfIRValueClass · 0.85
IsExactMatchMethod · 0.80
RemapBindFunctionMethod · 0.80
CreatePtrToIntMethod · 0.80
HasExplicitThisMethod · 0.80
ToTypeInstanceMethod · 0.45
GetThisTypeMethod · 0.45
IsPointerMethod · 0.45
GetUnderlyingTypeMethod · 0.45
IsFunctionMethod · 0.45

Tested by

no test coverage detected