| 545 | } |
| 546 | |
| 547 | bool BfCompiler::IsTypeUsed(BfType* checkType, BfProject* curProject) |
| 548 | { |
| 549 | if (mOptions.mCompileOnDemandKind == BfCompileOnDemandKind_AlwaysInclude) |
| 550 | return IsTypeAccessible(checkType, curProject); |
| 551 | |
| 552 | BfTypeInstance* typeInst = checkType->ToTypeInstance(); |
| 553 | if (typeInst != NULL) |
| 554 | { |
| 555 | //TODO: Why was this here? |
| 556 | // if ((typeInst->mTypeDef->mProject != NULL) && (typeInst->mTypeDef->mProject != curProject)) |
| 557 | // { |
| 558 | // if (typeInst->mTypeDef->mProject->mTargetType == BfTargetType_BeefDynLib) |
| 559 | // return false; |
| 560 | // } |
| 561 | |
| 562 | if (checkType->IsInterface()) |
| 563 | return typeInst->mIsReified; |
| 564 | |
| 565 | //TODO: We could check to see if this project has any reified specialized instances... |
| 566 | if (checkType->IsUnspecializedType()) |
| 567 | return typeInst->mIsReified; |
| 568 | |
| 569 | if (checkType->IsTuple()) |
| 570 | { |
| 571 | for (auto&& fieldInst : typeInst->mFieldInstances) |
| 572 | { |
| 573 | if (!IsTypeUsed(fieldInst.mResolvedType, curProject)) |
| 574 | return false; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | auto genericTypeInst = typeInst->ToGenericTypeInstance(); |
| 579 | if (genericTypeInst != NULL) |
| 580 | { |
| 581 | for (auto genericArg : genericTypeInst->mGenericTypeInfo->mTypeGenericArguments) |
| 582 | if (!IsTypeUsed(genericArg, curProject)) |
| 583 | return false; |
| 584 | } |
| 585 | |
| 586 | if (checkType->IsFunction()) |
| 587 | { |
| 588 | // These don't get their own modules so just assume "always used" at this point |
| 589 | return true; |
| 590 | } |
| 591 | |
| 592 | auto module = typeInst->GetModule(); |
| 593 | if (module == NULL) |
| 594 | return true; |
| 595 | |
| 596 | return curProject->mUsedModules.Contains(module); |
| 597 | } |
| 598 | |
| 599 | if (checkType->IsPointer()) |
| 600 | return IsTypeUsed(((BfPointerType*)checkType)->mElementType, curProject); |
| 601 | if (checkType->IsRef()) |
| 602 | return IsTypeUsed(((BfRefType*)checkType)->mElementType, curProject); |
| 603 | |
| 604 | return true; |
nothing calls this directly
no test coverage detected