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

Method InferGenericArgument

IDEHelper/Compiler/BfExprEvaluator.cpp:302–646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300}
301
302bool BfGenericInferContext::InferGenericArgument(BfMethodInstance* methodInstance, BfType* argType, BfType* wantType, BfIRValue argValue, bool checkCheckedSet)
303{
304 if (argType == NULL)
305 return false;
306
307 if (!wantType->IsUnspecializedType())
308 return true;
309
310 if (checkCheckedSet)
311 {
312 if (!AddToCheckedSet(argType, wantType))
313 return true;
314 }
315
316 if (wantType->IsGenericParam())
317 {
318 auto wantGenericParam = (BfGenericParamType*)wantType;
319
320 BfType* methodGenericTypeConstraint = NULL;
321 auto _SetGeneric = [&]()
322 {
323 if (argType != NULL)
324 {
325 // Disallow illegal types
326 if (argType->IsRef())
327 return;
328 if (argType->IsNull())
329 return;
330 }
331
332 if ((*mCheckMethodGenericArguments)[wantGenericParam->mGenericParamIdx] != argType)
333 {
334 if (methodGenericTypeConstraint != NULL)
335 {
336 if (methodGenericTypeConstraint->IsGenericTypeInstance())
337 {
338 auto wantGenericType = (BfTypeInstance*)methodGenericTypeConstraint;
339
340 auto checkArgType = argType;
341 while (checkArgType != NULL)
342 {
343 if (checkArgType->IsGenericTypeInstance())
344 {
345 auto argGenericType = (BfTypeInstance*)checkArgType;
346 if (argGenericType->mTypeDef->GetLatest() == wantGenericType->mTypeDef->GetLatest())
347 {
348 for (int genericArgIdx = 0; genericArgIdx < (int)argGenericType->mGenericTypeInfo->mTypeGenericArguments.size(); genericArgIdx++)
349 InferGenericArgument(methodInstance, argGenericType->mGenericTypeInfo->mTypeGenericArguments[genericArgIdx], wantGenericType->mGenericTypeInfo->mTypeGenericArguments[genericArgIdx], BfIRValue(), true);
350 }
351 }
352 else if (checkArgType->IsSizedArray())
353 {
354 auto sizedArrayType = (BfSizedArrayType*)checkArgType;
355 if (wantGenericType->IsInstanceOf(mModule->mCompiler->mSizedArrayTypeDef))
356 {
357 InferGenericArgument(methodInstance, sizedArrayType->mElementType, wantGenericType->mGenericTypeInfo->mTypeGenericArguments[0], BfIRValue());
358 auto intType = mModule->GetPrimitiveType(BfTypeCode_IntPtr);
359 BfTypedValue arraySize = BfTypedValue(mModule->mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, (uint64)sizedArrayType->mElementCount), intType);

Callers 2

AddExtensionMethodsMethod · 0.80
CheckMethodMethod · 0.80

Calls 15

BfIRValueClass · 0.85
BfTypedValueClass · 0.85
GetLatestMethod · 0.80
GetFakeTypedValueMethod · 0.80
GetDefinitionMethod · 0.80
GetConstValueMethod · 0.80
GetRawMethodByNameMethod · 0.80
IsUnspecializedTypeMethod · 0.45
IsGenericParamMethod · 0.45
IsRefMethod · 0.45

Tested by

no test coverage detected