| 1604 | } |
| 1605 | |
| 1606 | BfTypedValue BfModule::GetDefaultTypedValue(BfType* type, bool allowRef, BfDefaultValueKind defaultValueKind) |
| 1607 | { |
| 1608 | if (type->IsVar()) |
| 1609 | return BfTypedValue(mBfIRBuilder->GetFakeVal(), type); |
| 1610 | |
| 1611 | PopulateType(type, BfPopulateType_Data); |
| 1612 | mBfIRBuilder->PopulateType(type, type->IsValueType() ? BfIRPopulateType_Full : BfIRPopulateType_Declaration); |
| 1613 | |
| 1614 | if (defaultValueKind == BfDefaultValueKind_Undef) |
| 1615 | { |
| 1616 | return BfTypedValue(mBfIRBuilder->GetUndefConstValue(mBfIRBuilder->MapType(type)), type); |
| 1617 | } |
| 1618 | |
| 1619 | BfTypedValue typedValue; |
| 1620 | if ((defaultValueKind != BfDefaultValueKind_Const) && (!type->IsValuelessType())) |
| 1621 | { |
| 1622 | if (type->IsRef()) |
| 1623 | { |
| 1624 | BfRefType* refType = (BfRefType*)type; |
| 1625 | BfType* underlyingType = refType->GetUnderlyingType(); |
| 1626 | typedValue = BfTypedValue(CreateAlloca(underlyingType), underlyingType, BfTypedValueKind_Addr); |
| 1627 | } |
| 1628 | else |
| 1629 | { |
| 1630 | typedValue = BfTypedValue(CreateAlloca(type), type, BfTypedValueKind_Addr); |
| 1631 | } |
| 1632 | |
| 1633 | if (!mBfIRBuilder->mIgnoreWrites) |
| 1634 | { |
| 1635 | mBfIRBuilder->CreateMemSet(typedValue.mValue, GetConstValue(0, GetPrimitiveType(BfTypeCode_Int8)), |
| 1636 | GetConstValue(type->mSize), type->mAlign); |
| 1637 | } |
| 1638 | |
| 1639 | if ((defaultValueKind == BfDefaultValueKind_Value) && (!type->IsRef())) |
| 1640 | typedValue = LoadValue(typedValue); |
| 1641 | |
| 1642 | return typedValue; |
| 1643 | } |
| 1644 | |
| 1645 | if ((type->IsRef()) && (!allowRef)) |
| 1646 | { |
| 1647 | BfRefType* refType = (BfRefType*)type; |
| 1648 | BfType* underlyingType = refType->GetUnderlyingType(); |
| 1649 | if (underlyingType->IsValuelessType()) |
| 1650 | typedValue = BfTypedValue(mBfIRBuilder->GetFakeVal(), underlyingType, true); |
| 1651 | else |
| 1652 | typedValue = BfTypedValue(mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(type)), underlyingType, true); |
| 1653 | } |
| 1654 | else |
| 1655 | { |
| 1656 | typedValue = BfTypedValue(GetDefaultValue(type), type, (defaultValueKind == BfDefaultValueKind_Addr) ? BfTypedValueKind_Addr : BfTypedValueKind_Value); |
| 1657 | } |
| 1658 | return typedValue; |
| 1659 | } |
| 1660 | |
| 1661 | BfIRValue BfModule::CreateStringCharPtr(const StringImpl& str, int stringId, bool define) |
| 1662 | { |
no test coverage detected