| 15733 | } |
| 15734 | |
| 15735 | BfTypedValue BfModule::ReferenceStaticField(BfFieldInstance* fieldInstance) |
| 15736 | { |
| 15737 | BfIRValue globalValue; |
| 15738 | |
| 15739 | auto fieldDef = fieldInstance->GetFieldDef(); |
| 15740 | |
| 15741 | if ((fieldDef->mIsConst) && (!fieldDef->mIsExtern)) |
| 15742 | { |
| 15743 | if (fieldInstance->mConstIdx != -1) |
| 15744 | { |
| 15745 | auto constant = fieldInstance->mOwner->mConstHolder->GetConstantById(fieldInstance->mConstIdx); |
| 15746 | return BfTypedValue(ConstantToCurrent(constant, fieldInstance->mOwner->mConstHolder, fieldInstance->GetResolvedType()), fieldInstance->GetResolvedType()); |
| 15747 | } |
| 15748 | else |
| 15749 | { |
| 15750 | return GetDefaultTypedValue(fieldInstance->GetResolvedType()); |
| 15751 | } |
| 15752 | } |
| 15753 | |
| 15754 | if ((mIsScratchModule) && (mCompiler->mIsResolveOnly) && (!fieldInstance->mOwner->IsInstanceOf(mCompiler->mCompilerTypeDef))) |
| 15755 | { |
| 15756 | // Just fake it for the extern and unspecialized modules |
| 15757 | // We can't do this for compilation because unreified methods with default params need to get actual global variable refs |
| 15758 | return BfTypedValue(mBfIRBuilder->CreateUndefValue(mBfIRBuilder->GetPrimitiveType(BfTypeCode_NullPtr)), fieldInstance->GetResolvedType(), true); |
| 15759 | } |
| 15760 | |
| 15761 | BfIRValue* globalValuePtr = NULL; |
| 15762 | if (mStaticFieldRefs.TryGetValue(fieldInstance, &globalValuePtr)) |
| 15763 | { |
| 15764 | globalValue = *globalValuePtr; |
| 15765 | BF_ASSERT(globalValue); |
| 15766 | |
| 15767 | auto globalVar = (BfGlobalVar*)mBfIRBuilder->GetConstant(globalValue); |
| 15768 | if ((globalVar->mStreamId == -1) && (!mBfIRBuilder->mIgnoreWrites)) |
| 15769 | { |
| 15770 | mBfIRBuilder->MapType(fieldInstance->mResolvedType); |
| 15771 | mBfIRBuilder->CreateGlobalVariable(globalValue); |
| 15772 | } |
| 15773 | } |
| 15774 | else |
| 15775 | { |
| 15776 | StringT<512> staticVarName; |
| 15777 | BfMangler::Mangle(staticVarName, mCompiler->GetMangleKind(), fieldInstance); |
| 15778 | |
| 15779 | auto typeType = fieldInstance->GetResolvedType(); |
| 15780 | if ((fieldDef->mIsExtern) && (fieldDef->mIsConst) && (typeType->IsPointer())) |
| 15781 | { |
| 15782 | typeType = typeType->GetUnderlyingType(); |
| 15783 | } |
| 15784 | |
| 15785 | if (mIsComptimeModule) |
| 15786 | { |
| 15787 | mCompiler->mCeMachine->QueueStaticField(fieldInstance, staticVarName); |
| 15788 | } |
| 15789 | |
| 15790 | PopulateType(typeType); |
| 15791 | if ((typeType != NULL) && (!typeType->IsValuelessType())) |
| 15792 | { |
no test coverage detected