public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
switch (target_type.BuiltinType) {
case BuiltinTypeSpec.Type.Byte:
if (in_checked_context && Value > Byte.MaxValue)
throw new OverflowException ();
return new ByteConstant (target_type, (byte) Value, Location);
case BuiltinTypeSpec.Type.SByte:
if (in_checked_context && Value > ((ulong) SByte.MaxValue))
throw new OverflowException ();
return new SByteConstant (target_type, (sbyte) Value, Location);
case BuiltinTypeSpec.Type.Short:
if (in_checked_context && Value > ((ulong) Int16.MaxValue))
throw new OverflowException ();
return new ShortConstant (target_type, (short) Value, Location);
case BuiltinTypeSpec.Type.UShort:
if (in_checked_context && Value > UInt16.MaxValue)
throw new OverflowException ();
return new UShortConstant (target_type, (ushort) Value, Location);
case BuiltinTypeSpec.Type.Int:
if (in_checked_context && Value > UInt32.MaxValue)
throw new OverflowException ();
return new IntConstant (target_type, (int) Value, Location);
case BuiltinTypeSpec.Type.UInt:
if (in_checked_context && Value > UInt32.MaxValue)
throw new OverflowException ();
return new UIntConstant (target_type, (uint) Value, Location);
case BuiltinTypeSpec.Type.Long:
if (in_checked_context && Value > Int64.MaxValue)
throw new OverflowException ();
return new LongConstant (target_type, (long) Value, Location);
case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
case BuiltinTypeSpec.Type.Char:
if (in_checked_context && Value > Char.MaxValue)
throw new OverflowException ();
return new CharConstant (target_type, (char) Value, Location);
case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
return null;
}