//
// Author:
// Miguel de Icaza (miguel@ximian.com)
-// Marek Safar (marek.safar@seznam.cz)
+// Marek Safar (marek.safar@gmail.com)
//
// Copyright 2001-2003 Ximian, Inc.
// Copyright 2003-2008 Novell, Inc.
+// Copyright 2011-2013 Xamarin Inc
//
using System;
}
#endif
- public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl)
+ public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl)
{
if (!expl && IsLiteral &&
- BuildinTypeSpec.IsPrimitiveTypeOrDecimal (target) &&
- BuildinTypeSpec.IsPrimitiveTypeOrDecimal (type)) {
+ BuiltinTypeSpec.IsPrimitiveTypeOrDecimal (target) &&
+ BuiltinTypeSpec.IsPrimitiveTypeOrDecimal (type)) {
ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'",
- GetValueAsLiteral (), TypeManager.CSharpName (target));
+ GetValueAsLiteral (), target.GetSignatureForError ());
} else {
- base.Error_ValueCannotBeConverted (ec, loc, target, expl);
+ base.Error_ValueCannotBeConverted (ec, target, expl);
}
}
{
Constant c = ConvertImplicitly (type);
if (c == null)
- Error_ValueCannotBeConverted (ec, loc, type, false);
+ Error_ValueCannotBeConverted (ec, type, false);
return c;
}
+ public override bool ContainsEmitWithAwait ()
+ {
+ return false;
+ }
+
public virtual Constant ConvertImplicitly (TypeSpec type)
{
if (this.type == type)
return this;
- if (Convert.ImplicitNumericConversion (this, type) == null)
+ if (!Convert.ImplicitNumericConversionExists (this.type, type))
return null;
bool fail;
// reached, by calling Convert.ImplicitStandardConversionExists
//
throw new InternalErrorException ("Missing constant conversion between `{0}' and `{1}'",
- TypeManager.CSharpName (Type), TypeManager.CSharpName (type));
+ Type.GetSignatureForError (), type.GetSignatureForError ());
}
- return CreateConstant (type, constant_value, loc);
+ return CreateConstantFromValue (type, constant_value, loc);
}
//
// Returns a constant instance based on Type
//
- public static Constant CreateConstant (TypeSpec t, object v, Location loc)
- {
- return CreateConstantFromValue (t, v, loc);
- }
-
public static Constant CreateConstantFromValue (TypeSpec t, object v, Location loc)
{
- switch (t.BuildinType) {
- case BuildinTypeSpec.Type.Int:
+ switch (t.BuiltinType) {
+ case BuiltinTypeSpec.Type.Int:
return new IntConstant (t, (int) v, loc);
- case BuildinTypeSpec.Type.String:
+ case BuiltinTypeSpec.Type.String:
return new StringConstant (t, (string) v, loc);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
return new UIntConstant (t, (uint) v, loc);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return new LongConstant (t, (long) v, loc);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
return new ULongConstant (t, (ulong) v, loc);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (t, (float) v, loc);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (t, (double) v, loc);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
return new ShortConstant (t, (short) v, loc);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
return new UShortConstant (t, (ushort) v, loc);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
return new SByteConstant (t, (sbyte) v, loc);
- case BuildinTypeSpec.Type.Byte:
+ case BuiltinTypeSpec.Type.Byte:
return new ByteConstant (t, (byte) v, loc);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
return new CharConstant (t, (char) v, loc);
- case BuildinTypeSpec.Type.Bool:
+ case BuiltinTypeSpec.Type.Bool:
return new BoolConstant (t, (bool) v, loc);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (t, (decimal) v, loc);
}
}
if (v == null) {
- if (TypeManager.IsNullableType (t))
+ if (t.IsNullableType)
return Nullable.LiftedNull.Create (t, loc);
- if (TypeManager.IsReferenceType (t))
+ if (TypeSpec.IsReferenceType (t))
return new NullConstant (t, loc);
}
- throw new InternalErrorException ("Constant value `{0}' has unexpected underlying type `{1}'",
- v, TypeManager.CSharpName (t));
+#if STATIC
+ throw new InternalErrorException ("Constant value `{0}' has unexpected underlying type `{1}'", v, t.GetSignatureForError ());
+#else
+ return null;
+#endif
}
public override Expression CreateExpressionTree (ResolveContext ec)
{
Arguments args = new Arguments (2);
args.Add (new Argument (this));
- args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc)));
+ args.Add (new Argument (new TypeOf (type, loc)));
return CreateExpressionFactoryCall (ec, "Constant", args);
}
//
error = false;
try {
- switch (targetType.BuildinType) {
- case BuildinTypeSpec.Type.Bool:
+ switch (targetType.BuiltinType) {
+ case BuiltinTypeSpec.Type.Bool:
return convert_value.ToBoolean (nfi);
- case BuildinTypeSpec.Type.Byte:
+ case BuiltinTypeSpec.Type.Byte:
return convert_value.ToByte (nfi);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
return convert_value.ToChar (nfi);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
return convert_value.ToInt16 (nfi);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
return convert_value.ToInt32 (nfi);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return convert_value.ToInt64 (nfi);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
return convert_value.ToSByte (nfi);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
if (convert_value.GetType () == typeof (char))
return (decimal) convert_value.ToInt32 (nfi);
return convert_value.ToDecimal (nfi);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
if (convert_value.GetType () == typeof (char))
return (double) convert_value.ToInt32 (nfi);
return convert_value.ToDouble (nfi);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
if (convert_value.GetType () == typeof (char))
return (float) convert_value.ToInt32 (nfi);
return convert_value.ToSingle (nfi);
- case BuildinTypeSpec.Type.String:
+ case BuiltinTypeSpec.Type.String:
return convert_value.ToString (nfi);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
return convert_value.ToUInt16 (nfi);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
return convert_value.ToUInt32 (nfi);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
return convert_value.ToUInt64 (nfi);
- case BuildinTypeSpec.Type.Object:
+ case BuiltinTypeSpec.Type.Object:
return value;
}
} catch {
return this;
}
- /// <summary>
- /// Attempts to do a compile-time folding of a constant cast.
- /// </summary>
- public Constant TryReduce (ResolveContext ec, TypeSpec target_type, Location loc)
+ //
+ // Attempts to do a compile-time folding of a constant cast and handles
+ // error reporting for constant overlows only, on normal conversion
+ // errors returns null
+ //
+ public Constant Reduce (ResolveContext ec, TypeSpec target_type)
{
try {
- return TryReduce (ec, target_type);
- }
- catch (OverflowException) {
- if (ec.ConstantCheckState && Type.BuildinType != BuildinTypeSpec.Type.Decimal) {
+ return TryReduceConstant (ec, target_type);
+ } catch (OverflowException) {
+ if (ec.ConstantCheckState && Type.BuiltinType != BuiltinTypeSpec.Type.Decimal) {
ec.Report.Error (221, loc,
"Constant value `{0}' cannot be converted to a `{1}' (use `unchecked' syntax to override)",
GetValueAsLiteral (), target_type.GetSignatureForError ());
} else {
- Error_ValueCannotBeConverted (ec, loc, target_type, false);
+ Error_ValueCannotBeConverted (ec, target_type, false);
}
return New.Constantify (target_type, loc);
}
}
- Constant TryReduce (ResolveContext ec, TypeSpec target_type)
+ public Constant TryReduce (ResolveContext rc, TypeSpec targetType)
{
- if (Type == target_type)
+ try {
+ return TryReduceConstant (rc, targetType);
+ } catch (OverflowException) {
+ return null;
+ }
+ }
+
+ Constant TryReduceConstant (ResolveContext ec, TypeSpec target_type)
+ {
+ if (Type == target_type) {
+ //
+ // Reducing literal value produces a new constant. Syntactically 10 is not same as (int)10
+ //
+ if (IsLiteral)
+ return CreateConstantFromValue (target_type, GetValue (), loc);
+
return this;
+ }
Constant c;
- if (TypeManager.IsEnumType (target_type)) {
- c = TryReduce (ec, EnumSpec.GetUnderlyingType (target_type));
+ if (target_type.IsEnum) {
+ c = TryReduceConstant (ec, EnumSpec.GetUnderlyingType (target_type));
if (c == null)
return null;
public virtual bool IsOneInteger {
get { return false; }
- }
+ }
+
+ public override bool IsSideEffectFree {
+ get {
+ return true;
+ }
+ }
//
// Returns true iff 1) the stack type of this is one of Object,
eclass = ExprClass.Value;
}
- public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl)
+ public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec target, bool expl)
{
try {
ConvertExplicitly (true, target);
- base.Error_ValueCannotBeConverted (ec, loc, target, expl);
+ base.Error_ValueCannotBeConverted (ec, target, expl);
}
catch
{
ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'",
- GetValue ().ToString (), TypeManager.CSharpName (target));
+ GetValue ().ToString (), target.GetSignatureForError ());
}
}
public class BoolConstant : Constant {
public readonly bool Value;
- public BoolConstant (BuildinTypes types, bool val, Location loc)
+ public BoolConstant (BuiltinTypes types, bool val, Location loc)
: this (types.Bool, val, loc)
{
}
public override void Emit (EmitContext ec)
{
if (Value)
- ec.Emit (OpCodes.Ldc_I4_1);
+ ec.EmitInt (1);
else
- ec.Emit (OpCodes.Ldc_I4_0);
+ ec.EmitInt (0);
}
public override bool IsDefaultValue {
{
public readonly byte Value;
- public ByteConstant (BuildinTypes types, byte v, Location loc)
+ public ByteConstant (BuiltinTypes types, byte v, Location loc)
: this (types.Byte, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.SByte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context){
if (Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
return new UShortConstant (target_type, (ushort) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
public class CharConstant : Constant {
public readonly char Value;
- public CharConstant (BuildinTypes types, char v, Location loc)
+ public CharConstant (BuiltinTypes types, char v, Location loc)
: this (types.Char, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.Byte:
if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant (target_type, (byte) Value, Location);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context) {
if (Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
if (in_checked_context) {
if (Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
{
public readonly sbyte Value;
- public SByteConstant (BuildinTypes types, sbyte v, Location loc)
+ public SByteConstant (BuiltinTypes types, sbyte v, Location loc)
: this (types.SByte, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.Byte:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ByteConstant (target_type, (byte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new UShortConstant (target_type, (ushort) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
public class ShortConstant : IntegralConstant {
public readonly short Value;
- public ShortConstant (BuildinTypes types, short v, Location loc)
+ public ShortConstant (BuiltinTypes types, short v, Location loc)
: this (types.Short, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.Byte:
if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant (target_type, (byte) Value, Location);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context) {
if (Value < SByte.MinValue || Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new UShortConstant (target_type, (ushort) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
if (in_checked_context) {
if (Value < Char.MinValue)
throw new OverflowException ();
}
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
{
public readonly ushort Value;
- public UShortConstant (BuildinTypes types, ushort v, Location loc)
+ public UShortConstant (BuiltinTypes types, ushort v, Location loc)
: this (types.UShort, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.Byte:
if (in_checked_context) {
if (Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant (target_type, (byte) Value, Location);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context) {
if (Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
if (in_checked_context) {
if (Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
if (in_checked_context) {
if (Value > Char.MaxValue)
throw new OverflowException ();
}
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
{
public readonly int Value;
- public IntConstant (BuildinTypes types, int v, Location loc)
+ public IntConstant (BuiltinTypes types, int v, Location loc)
: this (types.Int, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.Byte:
if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant (target_type, (byte) Value, Location);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context) {
if (Value < SByte.MinValue || Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
if (in_checked_context) {
if (Value < Int16.MinValue || Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
if (in_checked_context) {
if (Value < UInt16.MinValue || Value > UInt16.MaxValue)
throw new OverflowException ();
}
return new UShortConstant (target_type, (ushort) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
if (in_checked_context) {
if (Value < UInt32.MinValue)
throw new OverflowException ();
}
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
if (in_checked_context) {
if (Value < Char.MinValue || Value > Char.MaxValue)
throw new OverflowException ();
}
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
/// </summary>
Constant TryImplicitIntConversion (TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.SByte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.SByte:
if (Value >= SByte.MinValue && Value <= SByte.MaxValue)
return new SByteConstant (target_type, (sbyte) Value, loc);
break;
- case BuildinTypeSpec.Type.Byte:
+ case BuiltinTypeSpec.Type.Byte:
if (Value >= Byte.MinValue && Value <= Byte.MaxValue)
return new ByteConstant (target_type, (byte) Value, loc);
break;
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
if (Value >= Int16.MinValue && Value <= Int16.MaxValue)
return new ShortConstant (target_type, (short) Value, loc);
break;
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
if (Value >= UInt16.MinValue && Value <= UInt16.MaxValue)
return new UShortConstant (target_type, (ushort) Value, loc);
break;
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
if (Value >= 0)
return new UIntConstant (target_type, (uint) Value, loc);
break;
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
//
// we can optimize this case: a positive int32
// always fits on a uint64. But we need an opcode
if (Value >= 0)
return new ULongConstant (target_type, (ulong) Value, loc);
break;
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, loc);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, loc);
}
public class UIntConstant : IntegralConstant {
public readonly uint Value;
- public UIntConstant (BuildinTypes types, uint v, Location loc)
+ public UIntConstant (BuiltinTypes types, uint v, Location loc)
: this (types.UInt, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.Byte:
if (in_checked_context) {
if (Value < 0 || Value > byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant (target_type, (byte) Value, Location);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context) {
if (Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
if (in_checked_context) {
if (Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
if (in_checked_context) {
if (Value < UInt16.MinValue || Value > UInt16.MaxValue)
throw new OverflowException ();
}
return new UShortConstant (target_type, (ushort) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
if (in_checked_context) {
if (Value > Int32.MaxValue)
throw new OverflowException ();
}
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
if (in_checked_context) {
if (Value < Char.MinValue || Value > Char.MaxValue)
throw new OverflowException ();
}
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
public class LongConstant : IntegralConstant {
public readonly long Value;
- public LongConstant (BuildinTypes types, long v, Location loc)
+ public LongConstant (BuiltinTypes types, long v, Location loc)
: this (types.Long, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.Byte:
if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant (target_type, (byte) Value, Location);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context) {
if (Value < SByte.MinValue || Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
if (in_checked_context) {
if (Value < Int16.MinValue || Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
if (in_checked_context) {
if (Value < UInt16.MinValue || Value > UInt16.MaxValue)
throw new OverflowException ();
}
return new UShortConstant (target_type, (ushort) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
if (in_checked_context) {
if (Value < Int32.MinValue || Value > Int32.MaxValue)
throw new OverflowException ();
}
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
if (in_checked_context) {
if (Value < UInt32.MinValue || Value > UInt32.MaxValue)
throw new OverflowException ();
}
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
if (in_checked_context) {
if (Value < Char.MinValue || Value > Char.MaxValue)
throw new OverflowException ();
}
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
public override Constant ConvertImplicitly (TypeSpec type)
{
- if (Value >= 0 && type.BuildinType == BuildinTypeSpec.Type.ULong) {
+ if (Value >= 0 && type.BuiltinType == BuiltinTypeSpec.Type.ULong) {
return new ULongConstant (type, (ulong) Value, loc);
}
public class ULongConstant : IntegralConstant {
public readonly ulong Value;
- public ULongConstant (BuildinTypes types, ulong v, Location loc)
+ public ULongConstant (BuiltinTypes types, ulong v, Location loc)
: this (types.ULong, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ 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 BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context && Value > ((ulong) SByte.MaxValue))
throw new OverflowException ();
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
if (in_checked_context && Value > ((ulong) Int16.MaxValue))
throw new OverflowException ();
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
if (in_checked_context && Value > UInt16.MaxValue)
throw new OverflowException ();
return new UShortConstant (target_type, (ushort) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
if (in_checked_context && Value > UInt32.MaxValue)
throw new OverflowException ();
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
if (in_checked_context && Value > UInt32.MaxValue)
throw new OverflowException ();
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
if (in_checked_context && Value > Int64.MaxValue)
throw new OverflowException ();
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
if (in_checked_context && Value > Char.MaxValue)
throw new OverflowException ();
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
public class FloatConstant : Constant {
public readonly float Value;
- public FloatConstant (BuildinTypes types, float v, Location loc)
+ public FloatConstant (BuiltinTypes types, float v, Location loc)
: this (types.Float, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.Byte:
if (in_checked_context) {
if (Value < byte.MinValue || Value > byte.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new ByteConstant (target_type, (byte) Value, Location);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context) {
if (Value < sbyte.MinValue || Value > sbyte.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
if (in_checked_context) {
if (Value < short.MinValue || Value > short.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
if (in_checked_context) {
if (Value < ushort.MinValue || Value > ushort.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new UShortConstant (target_type, (ushort) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
if (in_checked_context) {
if (Value < int.MinValue || Value > int.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
if (in_checked_context) {
if (Value < uint.MinValue || Value > uint.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
if (in_checked_context) {
if (Value < long.MinValue || Value > long.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
if (in_checked_context) {
if (Value < ulong.MinValue || Value > ulong.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
if (in_checked_context) {
if (Value < (float) char.MinValue || Value > (float) char.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
{
public readonly double Value;
- public DoubleConstant (BuildinTypes types, double v, Location loc)
+ public DoubleConstant (BuiltinTypes types, double v, Location loc)
: this (types.Double, v, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.Byte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.Byte:
if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new ByteConstant (target_type, (byte) Value, Location);
- case BuildinTypeSpec.Type.SByte:
+ case BuiltinTypeSpec.Type.SByte:
if (in_checked_context) {
if (Value < SByte.MinValue || Value > SByte.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new SByteConstant (target_type, (sbyte) Value, Location);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
if (in_checked_context) {
if (Value < short.MinValue || Value > short.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new ShortConstant (target_type, (short) Value, Location);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
if (in_checked_context) {
if (Value < ushort.MinValue || Value > ushort.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new UShortConstant (target_type, (ushort) Value, Location);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
if (in_checked_context) {
if (Value < int.MinValue || Value > int.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new IntConstant (target_type, (int) Value, Location);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
if (in_checked_context) {
if (Value < uint.MinValue || Value > uint.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new UIntConstant (target_type, (uint) Value, Location);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
if (in_checked_context) {
if (Value < long.MinValue || Value > long.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new LongConstant (target_type, (long) Value, Location);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
if (in_checked_context) {
if (Value < ulong.MinValue || Value > ulong.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new ULongConstant (target_type, (ulong) Value, Location);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, Location);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
if (in_checked_context) {
if (Value < (double) char.MinValue || Value > (double) char.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new CharConstant (target_type, (char) Value, Location);
- case BuildinTypeSpec.Type.Decimal:
+ case BuiltinTypeSpec.Type.Decimal:
return new DecimalConstant (target_type, (decimal) Value, Location);
}
public class DecimalConstant : Constant {
public readonly decimal Value;
- public DecimalConstant (BuildinTypes types, decimal d, Location loc)
+ public DecimalConstant (BuiltinTypes types, decimal d, Location loc)
: this (types.Decimal, d, loc)
{
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- switch (target_type.BuildinType) {
- case BuildinTypeSpec.Type.SByte:
+ switch (target_type.BuiltinType) {
+ case BuiltinTypeSpec.Type.SByte:
return new SByteConstant (target_type, (sbyte) Value, loc);
- case BuildinTypeSpec.Type.Byte:
+ case BuiltinTypeSpec.Type.Byte:
return new ByteConstant (target_type, (byte) Value, loc);
- case BuildinTypeSpec.Type.Short:
+ case BuiltinTypeSpec.Type.Short:
return new ShortConstant (target_type, (short) Value, loc);
- case BuildinTypeSpec.Type.UShort:
+ case BuiltinTypeSpec.Type.UShort:
return new UShortConstant (target_type, (ushort) Value, loc);
- case BuildinTypeSpec.Type.Int:
+ case BuiltinTypeSpec.Type.Int:
return new IntConstant (target_type, (int) Value, loc);
- case BuildinTypeSpec.Type.UInt:
+ case BuiltinTypeSpec.Type.UInt:
return new UIntConstant (target_type, (uint) Value, loc);
- case BuildinTypeSpec.Type.Long:
+ case BuiltinTypeSpec.Type.Long:
return new LongConstant (target_type, (long) Value, loc);
- case BuildinTypeSpec.Type.ULong:
+ case BuiltinTypeSpec.Type.ULong:
return new ULongConstant (target_type, (ulong) Value, loc);
- case BuildinTypeSpec.Type.Char:
+ case BuiltinTypeSpec.Type.Char:
return new CharConstant (target_type, (char) Value, loc);
- case BuildinTypeSpec.Type.Float:
+ case BuiltinTypeSpec.Type.Float:
return new FloatConstant (target_type, (float) Value, loc);
- case BuildinTypeSpec.Type.Double:
+ case BuiltinTypeSpec.Type.Double:
return new DoubleConstant (target_type, (double) Value, loc);
}
public class StringConstant : Constant {
public readonly string Value;
- public StringConstant (BuildinTypes types, string s, Location loc)
+ public StringConstant (BuiltinTypes types, string s, Location loc)
: this (types.String, s, loc)
{
}
public override void Emit (EmitContext ec)
{
if (Value == null) {
- ec.Emit (OpCodes.Ldnull);
+ ec.EmitNull ();
return;
}
// it's not allowed at language level
//
if (Value.Length == 0 && ec.Module.Compiler.Settings.Optimize) {
- var string_type = ec.BuildinTypes.String;
+ var string_type = ec.BuiltinTypes.String;
if (ec.CurrentType != string_type) {
var m = ec.Module.PredefinedMembers.StringEmpty.Get ();
if (m != null) {
public override Expression CreateExpressionTree (ResolveContext ec)
{
- if (type == InternalType.NullLiteral || type.BuildinType == BuildinTypeSpec.Type.Object) {
+ if (type == InternalType.NullLiteral || type.BuiltinType == BuiltinTypeSpec.Type.Object) {
// Optimized version, also avoids referencing literal internal type
Arguments args = new Arguments (1);
args.Add (new Argument (this));
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- // Type it as string cast
- if (targetType.BuildinType == BuildinTypeSpec.Type.Object)
- enc.Encode (rc.Module.Compiler.BuildinTypes.String);
-
- var ac = targetType as ArrayContainer;
- if (ac != null) {
- if (ac.Rank != 1 || ac.Element.IsArray)
- base.EncodeAttributeValue (rc, enc, targetType);
- else
- enc.Encode (uint.MaxValue);
- } else {
+ switch (targetType.BuiltinType) {
+ case BuiltinTypeSpec.Type.Object:
+ // Type it as string cast
+ enc.Encode (rc.Module.Compiler.BuiltinTypes.String);
+ goto case BuiltinTypeSpec.Type.String;
+ case BuiltinTypeSpec.Type.String:
+ case BuiltinTypeSpec.Type.Type:
enc.Encode (byte.MaxValue);
+ return;
+ default:
+ var ac = targetType as ArrayContainer;
+ if (ac != null && ac.Rank == 1 && !ac.Element.IsArray) {
+ enc.Encode (uint.MaxValue);
+ return;
+ }
+
+ break;
}
+
+ base.EncodeAttributeValue (rc, enc, targetType);
}
public override void Emit (EmitContext ec)
{
- ec.Emit (OpCodes.Ldnull);
+ ec.EmitNull ();
// Only to make verifier happy
- if (TypeManager.IsGenericParameter (type))
+ if (type.IsGenericParameter)
ec.Emit (OpCodes.Unbox_Any, type);
}
{
if (targetType.IsPointer) {
if (IsLiteral || this is NullPointer)
- return new EmptyConstantCast (new NullPointer (loc), targetType);
+ return new NullPointer (targetType, loc);
return null;
}
// Exlude internal compiler types
- if (targetType.Kind == MemberKind.InternalCompilerType && targetType.BuildinType != BuildinTypeSpec.Type.Dynamic)
+ if (targetType.Kind == MemberKind.InternalCompilerType && targetType.BuiltinType != BuiltinTypeSpec.Type.Dynamic)
return null;
if (!IsLiteral && !Convert.ImplicitStandardConversionExists (this, targetType))
return null;
- if (TypeManager.IsReferenceType (targetType))
+ if (TypeSpec.IsReferenceType (targetType))
return new NullConstant (targetType, loc);
- if (TypeManager.IsNullableType (targetType))
+ if (targetType.IsNullableType)
return Nullable.LiftedNull.Create (targetType, loc);
return null;
}
}
+
+ //
+ // A null constant in a pointer context
+ //
+ class NullPointer : NullConstant
+ {
+ public NullPointer (TypeSpec type, Location loc)
+ : base (type, loc)
+ {
+ }
+
+ public override Expression CreateExpressionTree (ResolveContext ec)
+ {
+ Error_PointerInsideExpressionTree (ec);
+ return base.CreateExpressionTree (ec);
+ }
+
+ public override void Emit (EmitContext ec)
+ {
+ //
+ // Emits null pointer
+ //
+ ec.EmitInt (0);
+ ec.Emit (OpCodes.Conv_U);
+ }
+ }
+
/// <summary>
/// The value is constant, but when emitted has a side effect. This is
/// used by BitwiseAnd to ensure that the second expression is invoked
/// regardless of the value of the left side.
/// </summary>
- public class SideEffectConstant : Constant {
+ public class SideEffectConstant : Constant
+ {
public readonly Constant value;
Expression side_effect;
this.side_effect = side_effect;
}
+ public override bool IsSideEffectFree {
+ get {
+ return false;
+ }
+ }
+
public override object GetValue ()
{
return value.GetValue ();