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

Method GetGenericTypeParamInstance

IDEHelper/Compiler/BfModuleTypeUtils.cpp:9625–9686  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9623}
9624
9625BfGenericParamInstance* BfModule::GetGenericTypeParamInstance(int genericParamIdx, BfFailHandleKind failHandleKind)
9626{
9627 // When we're evaluating a method, make sure the params refer back to that method context
9628 auto curTypeInstance = mCurTypeInstance;
9629 //TODO: This caused MethodToString issues with interface "implementation method not found" errors
9630// if (mCurMethodInstance != NULL)
9631// curTypeInstance = mCurMethodInstance->mMethodInstanceGroup->mOwner;
9632
9633 BfTypeInstance* genericTypeInst = curTypeInstance->ToGenericTypeInstance();
9634
9635 if (genericTypeInst == NULL)
9636 {
9637 FatalError("Invalid mCurTypeInstance for GetGenericTypeParamInstance", failHandleKind);
9638 return NULL;
9639 }
9640
9641 if ((genericTypeInst->IsIncomplete()) && (genericTypeInst->mGenericTypeInfo->mGenericParams.size() == 0))
9642 {
9643 // Set this to NULL so we don't recurse infinitely
9644 SetAndRestoreValue<BfTypeInstance*> prevTypeInst(mCurTypeInstance, NULL);
9645 PopulateType(genericTypeInst, BfPopulateType_Declaration);
9646 }
9647
9648 if (genericParamIdx >= (int)genericTypeInst->mGenericTypeInfo->mTypeGenericArguments.size())
9649 {
9650 if (genericParamIdx >= genericTypeInst->mGenericTypeInfo->mGenericParams.mSize)
9651 FatalError("Invalid GetGenericTypeParamInstance");
9652
9653 // Extern constraints should always be directly used - they don't get extended
9654 return genericTypeInst->mGenericTypeInfo->mGenericParams[genericParamIdx];
9655 }
9656
9657 if (genericTypeInst->mGenericTypeInfo->mGenericExtensionInfo != NULL)
9658 {
9659 bool isAutocomplete = (mCompiler->mResolvePassData != NULL) && (mCompiler->mResolvePassData->mAutoComplete != NULL);
9660
9661 auto activeTypeDef = GetActiveTypeDef(NULL, true);
9662 if ((activeTypeDef->mTypeDeclaration != genericTypeInst->mTypeDef->mTypeDeclaration) && (activeTypeDef->IsExtension()) &&
9663 ((genericTypeInst->mTypeDef->ContainsPartial(activeTypeDef)) || (isAutocomplete)))
9664 {
9665 BfTypeDef* lookupTypeDef = activeTypeDef;
9666 while (lookupTypeDef->mNestDepth > genericTypeInst->mTypeDef->mNestDepth)
9667 lookupTypeDef = lookupTypeDef->mOuterType;
9668
9669 BfGenericExtensionEntry* genericExEntry;
9670 if (genericTypeInst->mGenericTypeInfo->mGenericExtensionInfo->mExtensionMap.TryGetValue(lookupTypeDef, &genericExEntry))
9671 {
9672 return genericExEntry->mGenericParams[genericParamIdx];
9673 }
9674 else
9675 {
9676 if (!isAutocomplete)
9677 {
9678 FatalError("Invalid GetGenericParamInstance with extension");
9679 }
9680 }
9681 }
9682 }

Callers 1

Calls 6

IsExtensionMethod · 0.80
ContainsPartialMethod · 0.80
TryGetValueMethod · 0.80
ToGenericTypeInstanceMethod · 0.45
IsIncompleteMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected