////////////////////////////////////////////////////////////////////////////////
//
// Precondition:
//
// type - Non-null
//
// This returns a null for reference types and an EXPRZEROINIT for all others.
public Expr CreateZeroInit(CType type)
{
Debug.Assert(type != null);
if (type.isEnumType())
{
// For enum types, we create a constant that has the default value
// as an object pointer.
return(CreateConstant(type, ConstVal.Get(Activator.CreateInstance(type.AssociatedSystemType))));
}
Debug.Assert(type.fundType() > FUNDTYPE.FT_NONE);
Debug.Assert(type.fundType() < FUNDTYPE.FT_COUNT);
switch (type.fundType())
{
case FUNDTYPE.FT_PTR:
{
// Just allocate a new node and fill it in.
return(CreateCast(0, type, CreateNull()));
}
case FUNDTYPE.FT_STRUCT:
if (type.isPredefType(PredefinedType.PT_DECIMAL))
{
goto default;
}
goto case FUNDTYPE.FT_VAR;
case FUNDTYPE.FT_VAR:
return(new ExprZeroInit(type));
default:
return(CreateConstant(type, ConstVal.GetDefaultValue(type.constValKind())));
}
}