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

Method GetDefaultValue

IDEHelper/Compiler/BfModule.cpp:1566–1593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1564}
1565
1566BfIRValue BfModule::GetDefaultValue(BfType* type)
1567{
1568 PopulateType(type, BfPopulateType_Data);
1569 mBfIRBuilder->PopulateType(type, BfIRPopulateType_Declaration);
1570
1571 if (type->IsTypedPrimitive())
1572 {
1573 auto underlyingType = type->GetUnderlyingType();
1574 if (underlyingType == NULL)
1575 return mBfIRBuilder->CreateConst(BfTypeCode_Int64, 0);
1576 return GetDefaultValue(type->GetUnderlyingType());
1577 }
1578
1579 if (type->IsPointer() || type->IsObjectOrInterface() || type->IsGenericParam() || type->IsVar() || type->IsRef() || type->IsNull() ||
1580 type->IsModifiedTypeType() || type->IsConcreteInterfaceType())
1581 return mBfIRBuilder->CreateConstNull(mBfIRBuilder->MapType(type));
1582 if ((type->IsIntegral()) || (type->IsBoolean()))
1583 {
1584 auto primType = (BfPrimitiveType*)type;
1585 return mBfIRBuilder->CreateConst(primType->mTypeDef->mTypeCode, (uint64)0);
1586 }
1587 if (type->IsFloat())
1588 {
1589 auto primType = (BfPrimitiveType*)type;
1590 return mBfIRBuilder->CreateConst(primType->mTypeDef->mTypeCode, 0.0);
1591 }
1592 return mBfIRBuilder->CreateConstAggZero(mBfIRBuilder->MapType(type));
1593}
1594
1595BfTypedValue BfModule::GetFakeTypedValue(BfType* type)
1596{

Callers 11

CreateVDataMethod · 0.80
VisitMethod · 0.80
LoadFieldMethod · 0.80
LookupFieldMethod · 0.80
MatchMethodMethod · 0.80
LookupQualifiedNameMethod · 0.80
SetupNullConditionalMethod · 0.80

Calls 15

CreateConstNullMethod · 0.80
MapTypeMethod · 0.80
CreateConstAggZeroMethod · 0.80
PopulateTypeMethod · 0.45
IsTypedPrimitiveMethod · 0.45
GetUnderlyingTypeMethod · 0.45
CreateConstMethod · 0.45
IsPointerMethod · 0.45
IsObjectOrInterfaceMethod · 0.45
IsGenericParamMethod · 0.45
IsVarMethod · 0.45
IsRefMethod · 0.45

Tested by

no test coverage detected