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

Method GetDefaultTypedValue

IDEHelper/Compiler/BfModule.cpp:1606–1659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1604}
1605
1606BfTypedValue 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
1661BfIRValue BfModule::CreateStringCharPtr(const StringImpl& str, int stringId, bool define)
1662{

Callers 15

DoObjectCreateMethod · 0.45
ResolveMethod · 0.45
VisitMethod · 0.45
DoCaseExpressionMethod · 0.45
LoadLocalMethod · 0.45
LookupIdentifierMethod · 0.45
LoadFieldMethod · 0.45
LookupFieldMethod · 0.45
CreateCallMethod · 0.45
PushArgMethod · 0.45
ResolveArgValueMethod · 0.45
CheckEnumCreationMethod · 0.45

Calls 12

BfTypedValueClass · 0.85
GetFakeValMethod · 0.80
GetUndefConstValueMethod · 0.80
MapTypeMethod · 0.80
CreateConstNullMethod · 0.80
IsVarMethod · 0.45
PopulateTypeMethod · 0.45
IsValueTypeMethod · 0.45
IsValuelessTypeMethod · 0.45
IsRefMethod · 0.45
GetUnderlyingTypeMethod · 0.45
CreateMemSetMethod · 0.45

Tested by

no test coverage detected