//
using System;
+
+#if STATIC
+using IKVM.Reflection.Emit;
+#else
using System.Reflection.Emit;
+#endif
namespace Mono.CSharp {
this.loc = loc;
}
- /// <remarks>
- /// This is different from ToString in that ToString
- /// is supposed to be there for debugging purposes,
- /// and is not guaranteed to be useful for anything else,
- /// AsString() will provide something that can be used
- /// for round-tripping C# code. Maybe it can be used
- /// for IL assembly as well.
- /// </remarks>
- public abstract string AsString ();
-
override public string ToString ()
{
- return this.GetType ().Name + " (" + AsString () + ")";
+ return this.GetType ().Name + " (" + GetValueAsLiteral () + ")";
}
/// <summary>
/// </summary>
public abstract object GetValue ();
+ public abstract long GetValueAsLong ();
+
+ public abstract string GetValueAsLiteral ();
+
+#if !STATIC
+ //
+ // Returns an object value which is typed to contant type
+ //
public virtual object GetTypedValue ()
{
return GetValue ();
}
+#endif
public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl)
{
(TypeManager.IsPrimitiveType (target) || type == TypeManager.decimal_type) &&
(TypeManager.IsPrimitiveType (type) || type == TypeManager.decimal_type)) {
ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'",
- AsString (), TypeManager.CSharpName (target));
+ GetValueAsLiteral (), TypeManager.CSharpName (target));
} else {
base.Error_ValueCannotBeConverted (ec, loc, target, expl);
}
public static Constant CreateConstantFromValue (TypeSpec t, object v, Location loc)
{
- if (t == TypeManager.int32_type)
- return new IntConstant ((int) v, loc);
- if (t == TypeManager.string_type)
- return new StringConstant ((string) v, loc);
- if (t == TypeManager.uint32_type)
- return new UIntConstant ((uint) v, loc);
- if (t == TypeManager.int64_type)
- return new LongConstant ((long) v, loc);
- if (t == TypeManager.uint64_type)
- return new ULongConstant ((ulong) v, loc);
- if (t == TypeManager.float_type)
- return new FloatConstant ((float) v, loc);
- if (t == TypeManager.double_type)
- return new DoubleConstant ((double) v, loc);
- if (t == TypeManager.short_type)
- return new ShortConstant ((short)v, loc);
- if (t == TypeManager.ushort_type)
- return new UShortConstant ((ushort)v, loc);
- if (t == TypeManager.sbyte_type)
- return new SByteConstant ((sbyte)v, loc);
- if (t == TypeManager.byte_type)
- return new ByteConstant ((byte)v, loc);
- if (t == TypeManager.char_type)
- return new CharConstant ((char)v, loc);
- if (t == TypeManager.bool_type)
- return new BoolConstant ((bool) v, loc);
- if (t == TypeManager.decimal_type)
- return new DecimalConstant ((decimal) v, loc);
- if (TypeManager.IsEnumType (t)) {
+ if (t.BuildinType > 0) {
+ switch (t.BuildinType) {
+ case BuildinTypeSpec.Type.Int:
+ return new IntConstant ((int) v, loc);
+ case BuildinTypeSpec.Type.String:
+ return new StringConstant ((string) v, loc);
+ case BuildinTypeSpec.Type.UInt:
+ return new UIntConstant ((uint) v, loc);
+ case BuildinTypeSpec.Type.Long:
+ return new LongConstant ((long) v, loc);
+ case BuildinTypeSpec.Type.ULong:
+ return new ULongConstant ((ulong) v, loc);
+ case BuildinTypeSpec.Type.Float:
+ return new FloatConstant ((float) v, loc);
+ case BuildinTypeSpec.Type.Double:
+ return new DoubleConstant ((double) v, loc);
+ case BuildinTypeSpec.Type.Short:
+ return new ShortConstant ((short) v, loc);
+ case BuildinTypeSpec.Type.UShort:
+ return new UShortConstant ((ushort) v, loc);
+ case BuildinTypeSpec.Type.SByte:
+ return new SByteConstant ((sbyte) v, loc);
+ case BuildinTypeSpec.Type.Byte:
+ return new ByteConstant ((byte) v, loc);
+ case BuildinTypeSpec.Type.Char:
+ return new CharConstant ((char) v, loc);
+ case BuildinTypeSpec.Type.Bool:
+ return new BoolConstant ((bool) v, loc);
+ case BuildinTypeSpec.Type.Decimal:
+ return new DecimalConstant ((decimal) v, loc);
+ }
+ }
+
+ if (t.IsEnum) {
var real_type = EnumSpec.GetUnderlyingType (t);
return new EnumConstant (CreateConstantFromValue (real_type, v, loc).Resolve (null), t);
}
+
if (v == null) {
if (TypeManager.IsNullableType (t))
return Nullable.LiftedNull.Create (t, loc);
return TryReduce (ec, target_type);
}
catch (OverflowException) {
- if (ec.ConstantCheckState) {
- ec.Report.Error (221, loc, "Constant value `{0}' cannot be converted to a `{1}' (use `unchecked' syntax to override)",
- GetValue ().ToString (), TypeManager.CSharpName (target_type));
+ if (ec.ConstantCheckState && Type.BuildinType != BuildinTypeSpec.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);
}
- return New.Constantify (target_type).Resolve (ec);
+ return New.Constantify (target_type, loc).Resolve (ec);
}
}
// do nothing
}
+ public sealed override Expression Clone (CloneContext clonectx)
+ {
+ // No cloning is not needed for constants
+ return this;
+ }
+
protected override void CloneTo (CloneContext clonectx, Expression target)
{
- // CloneTo: Nothing, we do not keep any state on this expression
+ throw new NotSupportedException ("should not be reached");
}
public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
{
+#if STATIC
+ return base.MakeExpression (ctx);
+#else
return System.Linq.Expressions.Expression.Constant (GetTypedValue (), type.GetMetaInfo ());
+#endif
}
public new Constant Resolve (ResolveContext rc)
}
}
- public abstract class IntegralConstant : Constant {
+ public abstract class IntegralConstant : Constant
+ {
protected IntegralConstant (Location loc) :
base (loc)
{
GetValue ().ToString (), TypeManager.CSharpName (target));
}
}
+
+ public override string GetValueAsLiteral ()
+ {
+ return GetValue ().ToString ();
+ }
public abstract Constant Increment ();
}
Value = val;
}
- override public string AsString ()
- {
- return Value ? "true" : "false";
- }
-
protected override Expression DoResolve (ResolveContext ec)
{
type = TypeManager.bool_type;
return (object) Value;
}
+ public override string GetValueAsLiteral ()
+ {
+ return Value ? "true" : "false";
+ }
+
+ public override long GetValueAsLong ()
+ {
+ return Value ? 1 : 0;
+ }
+
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
}
- public class ByteConstant : IntegralConstant {
+ public class ByteConstant : IntegralConstant
+ {
public readonly byte Value;
public ByteConstant (byte v, Location loc):
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.EmitInt (Value);
}
- public override string AsString ()
- {
- return Value.ToString ();
- }
-
protected override Expression DoResolve (ResolveContext ec)
{
type = TypeManager.byte_type;
return Value;
}
+ public override long GetValueAsLong ()
+ {
+ return Value;
+ }
+
public override Constant Increment ()
{
return new ByteConstant (checked ((byte)(Value + 1)), loc);
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.sbyte_type) {
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.SByte:
if (in_checked_context){
if (Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.short_type)
+ case BuildinTypeSpec.Type.Short:
return new ShortConstant ((short) Value, Location);
- if (target_type == TypeManager.ushort_type)
+ case BuildinTypeSpec.Type.UShort:
return new UShortConstant ((ushort) Value, Location);
- if (target_type == TypeManager.int32_type)
+ case BuildinTypeSpec.Type.Int:
return new IntConstant ((int) Value, Location);
- if (target_type == TypeManager.uint32_type)
+ case BuildinTypeSpec.Type.UInt:
return new UIntConstant ((uint) Value, Location);
- if (target_type == TypeManager.int64_type)
+ case BuildinTypeSpec.Type.Long:
return new LongConstant ((long) Value, Location);
- if (target_type == TypeManager.uint64_type)
+ case BuildinTypeSpec.Type.ULong:
return new ULongConstant ((ulong) Value, Location);
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.char_type)
+ case BuildinTypeSpec.Type.Char:
return new CharConstant ((char) Value, Location);
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write ((ushort) Value);
+ enc.Encode ((ushort) Value);
}
public override void Emit (EmitContext ec)
return c.ToString ();
}
- public override string AsString ()
+ public override object GetValue ()
{
- return "\"" + descape (Value) + "\"";
+ return Value;
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
return Value;
}
+ public override string GetValueAsLiteral ()
+ {
+ return "\"" + descape (Value) + "\"";
+ }
+
public override bool IsDefaultValue {
get {
return Value == 0;
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
- if (in_checked_context){
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
+ if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.sbyte_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.SByte:
+ if (in_checked_context) {
if (Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.short_type) {
- if (in_checked_context){
+
+ case BuildinTypeSpec.Type.Short:
+ if (in_checked_context) {
if (Value > Int16.MaxValue)
throw new OverflowException ();
- }
+ }
return new ShortConstant ((short) Value, Location);
- }
- if (target_type == TypeManager.int32_type)
+ case BuildinTypeSpec.Type.Int:
return new IntConstant ((int) Value, Location);
- if (target_type == TypeManager.uint32_type)
+ case BuildinTypeSpec.Type.UInt:
return new UIntConstant ((uint) Value, Location);
- if (target_type == TypeManager.int64_type)
+ case BuildinTypeSpec.Type.Long:
return new LongConstant ((long) Value, Location);
- if (target_type == TypeManager.uint64_type)
+ case BuildinTypeSpec.Type.ULong:
return new ULongConstant ((ulong) Value, Location);
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.EmitInt (Value);
}
- public override string AsString ()
+ public override object GetValue ()
{
- return Value.ToString ();
+ return Value;
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
return Value;
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.short_type)
+ case BuildinTypeSpec.Type.Short:
return new ShortConstant ((short) Value, Location);
- if (target_type == TypeManager.ushort_type) {
+ case BuildinTypeSpec.Type.UShort:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new UShortConstant ((ushort) Value, Location);
- } if (target_type == TypeManager.int32_type)
- return new IntConstant ((int) Value, Location);
- if (target_type == TypeManager.uint32_type) {
+ case BuildinTypeSpec.Type.Int:
+ return new IntConstant ((int) Value, Location);
+ case BuildinTypeSpec.Type.UInt:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new UIntConstant ((uint) Value, Location);
- } if (target_type == TypeManager.int64_type)
- return new LongConstant ((long) Value, Location);
- if (target_type == TypeManager.uint64_type) {
+ case BuildinTypeSpec.Type.Long:
+ return new LongConstant ((long) Value, Location);
+ case BuildinTypeSpec.Type.ULong:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ULongConstant ((ulong) Value, Location);
- }
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.char_type) {
+ case BuildinTypeSpec.Type.Char:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new CharConstant ((char) Value, Location);
- }
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.EmitInt (Value);
}
- public override string AsString ()
+ public override object GetValue ()
{
- return Value.ToString ();
+ return Value;
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
return Value;
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
- if (in_checked_context){
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
+ if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.sbyte_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.SByte:
+ if (in_checked_context) {
if (Value < SByte.MinValue || Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.ushort_type) {
+ case BuildinTypeSpec.Type.UShort:
if (in_checked_context && Value < 0)
throw new OverflowException ();
-
+
return new UShortConstant ((ushort) Value, Location);
- }
- if (target_type == TypeManager.int32_type)
+ case BuildinTypeSpec.Type.Int:
return new IntConstant ((int) Value, Location);
- if (target_type == TypeManager.uint32_type) {
+ case BuildinTypeSpec.Type.UInt:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new UIntConstant ((uint) Value, Location);
- }
- if (target_type == TypeManager.int64_type)
+ case BuildinTypeSpec.Type.Long:
return new LongConstant ((long) Value, Location);
- if (target_type == TypeManager.uint64_type) {
+ case BuildinTypeSpec.Type.ULong:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ULongConstant ((ulong) Value, Location);
- }
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.char_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Char:
+ if (in_checked_context) {
if (Value < Char.MinValue)
throw new OverflowException ();
}
return new CharConstant ((char) Value, Location);
- }
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
}
- public class UShortConstant : IntegralConstant {
+ public class UShortConstant : IntegralConstant
+ {
public readonly ushort Value;
public UShortConstant (ushort v, Location loc):
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.EmitInt (Value);
}
- public override string AsString ()
+ public override object GetValue ()
{
- return Value.ToString ();
+ return Value;
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
return Value;
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
- if (in_checked_context){
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
+ if (in_checked_context) {
if (Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.sbyte_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.SByte:
+ if (in_checked_context) {
if (Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.short_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Short:
+ if (in_checked_context) {
if (Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant ((short) Value, Location);
- }
- if (target_type == TypeManager.int32_type)
+ case BuildinTypeSpec.Type.Int:
return new IntConstant ((int) Value, Location);
- if (target_type == TypeManager.uint32_type)
+ case BuildinTypeSpec.Type.UInt:
return new UIntConstant ((uint) Value, Location);
- if (target_type == TypeManager.int64_type)
+ case BuildinTypeSpec.Type.Long:
return new LongConstant ((long) Value, Location);
- if (target_type == TypeManager.uint64_type)
+ case BuildinTypeSpec.Type.ULong:
return new ULongConstant ((ulong) Value, Location);
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.char_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Char:
+ if (in_checked_context) {
if (Value > Char.MaxValue)
throw new OverflowException ();
}
return new CharConstant ((char) Value, Location);
- }
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.EmitInt (Value);
}
- public override string AsString ()
+ public override object GetValue ()
{
- return Value.ToString ();
+ return Value;
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
return Value;
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
- if (in_checked_context){
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
+ if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.sbyte_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.SByte:
+ if (in_checked_context) {
if (Value < SByte.MinValue || Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.short_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Short:
+ if (in_checked_context) {
if (Value < Int16.MinValue || Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant ((short) Value, Location);
- }
- if (target_type == TypeManager.ushort_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.UShort:
+ if (in_checked_context) {
if (Value < UInt16.MinValue || Value > UInt16.MaxValue)
throw new OverflowException ();
}
return new UShortConstant ((ushort) Value, Location);
- }
- if (target_type == TypeManager.uint32_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.UInt:
+ if (in_checked_context) {
if (Value < UInt32.MinValue)
throw new OverflowException ();
}
return new UIntConstant ((uint) Value, Location);
- }
- if (target_type == TypeManager.int64_type)
+ case BuildinTypeSpec.Type.Long:
return new LongConstant ((long) Value, Location);
- if (target_type == TypeManager.uint64_type) {
+ case BuildinTypeSpec.Type.ULong:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ULongConstant ((ulong) Value, Location);
- }
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.char_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Char:
+ if (in_checked_context) {
if (Value < Char.MinValue || Value > Char.MaxValue)
throw new OverflowException ();
}
return new CharConstant ((char) Value, Location);
- }
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
/// </summary>
Constant TryImplicitIntConversion (TypeSpec target_type)
{
- if (target_type == TypeManager.sbyte_type) {
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.SByte:
if (Value >= SByte.MinValue && Value <= SByte.MaxValue)
return new SByteConstant ((sbyte) Value, loc);
- }
- else if (target_type == TypeManager.byte_type) {
+ break;
+ case BuildinTypeSpec.Type.Byte:
if (Value >= Byte.MinValue && Value <= Byte.MaxValue)
return new ByteConstant ((byte) Value, loc);
- }
- else if (target_type == TypeManager.short_type) {
+ break;
+ case BuildinTypeSpec.Type.Short:
if (Value >= Int16.MinValue && Value <= Int16.MaxValue)
return new ShortConstant ((short) Value, loc);
- }
- else if (target_type == TypeManager.ushort_type) {
+ break;
+ case BuildinTypeSpec.Type.UShort:
if (Value >= UInt16.MinValue && Value <= UInt16.MaxValue)
return new UShortConstant ((ushort) Value, loc);
- }
- else if (target_type == TypeManager.uint32_type) {
+ break;
+ case BuildinTypeSpec.Type.UInt:
if (Value >= 0)
return new UIntConstant ((uint) Value, loc);
- }
- else if (target_type == TypeManager.uint64_type) {
+ break;
+ case BuildinTypeSpec.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 ((ulong) Value, loc);
- }
- else if (target_type == TypeManager.double_type)
+ break;
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, loc);
- else if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, loc);
+ }
return null;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.EmitInt (unchecked ((int) Value));
}
- public override string AsString ()
+ public override object GetValue ()
{
- return Value.ToString ();
+ return Value;
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
return Value;
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
- if (in_checked_context){
- if (Value < Char.MinValue || Value > Char.MaxValue)
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
+ if (in_checked_context) {
+ if (Value < 0 || Value > byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.sbyte_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.SByte:
+ if (in_checked_context) {
if (Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.short_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Short:
+ if (in_checked_context) {
if (Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant ((short) Value, Location);
- }
- if (target_type == TypeManager.ushort_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.UShort:
+ if (in_checked_context) {
if (Value < UInt16.MinValue || Value > UInt16.MaxValue)
throw new OverflowException ();
}
return new UShortConstant ((ushort) Value, Location);
- }
- if (target_type == TypeManager.int32_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Int:
+ if (in_checked_context) {
if (Value > Int32.MaxValue)
throw new OverflowException ();
}
return new IntConstant ((int) Value, Location);
- }
- if (target_type == TypeManager.int64_type)
+ case BuildinTypeSpec.Type.Long:
return new LongConstant ((long) Value, Location);
- if (target_type == TypeManager.uint64_type)
+ case BuildinTypeSpec.Type.ULong:
return new ULongConstant ((ulong) Value, Location);
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.char_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Char:
+ if (in_checked_context) {
if (Value < Char.MinValue || Value > Char.MaxValue)
throw new OverflowException ();
}
return new CharConstant ((char) Value, Location);
- }
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.EmitLong (Value);
}
- public override string AsString ()
+ public override object GetValue ()
{
- return Value.ToString ();
+ return Value;
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
return Value;
}
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
- if (in_checked_context){
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
+ if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.sbyte_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.SByte:
+ if (in_checked_context) {
if (Value < SByte.MinValue || Value > SByte.MaxValue)
throw new OverflowException ();
}
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.short_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Short:
+ if (in_checked_context) {
if (Value < Int16.MinValue || Value > Int16.MaxValue)
throw new OverflowException ();
}
return new ShortConstant ((short) Value, Location);
- }
- if (target_type == TypeManager.ushort_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.UShort:
+ if (in_checked_context) {
if (Value < UInt16.MinValue || Value > UInt16.MaxValue)
throw new OverflowException ();
}
return new UShortConstant ((ushort) Value, Location);
- }
- if (target_type == TypeManager.int32_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Int:
+ if (in_checked_context) {
if (Value < Int32.MinValue || Value > Int32.MaxValue)
throw new OverflowException ();
}
return new IntConstant ((int) Value, Location);
- }
- if (target_type == TypeManager.uint32_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.UInt:
+ if (in_checked_context) {
if (Value < UInt32.MinValue || Value > UInt32.MaxValue)
throw new OverflowException ();
}
return new UIntConstant ((uint) Value, Location);
- }
- if (target_type == TypeManager.uint64_type) {
+ case BuildinTypeSpec.Type.ULong:
if (in_checked_context && Value < 0)
throw new OverflowException ();
return new ULongConstant ((ulong) Value, Location);
- }
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.char_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Char:
+ if (in_checked_context) {
if (Value < Char.MinValue || Value > Char.MaxValue)
throw new OverflowException ();
}
return new CharConstant ((char) Value, Location);
- }
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.EmitLong (unchecked ((long) Value));
}
- public override string AsString ()
+ public override object GetValue ()
{
- return Value.ToString ();
+ return Value;
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
- return Value;
+ return (long) Value;
}
public override Constant Increment ()
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
if (in_checked_context && Value > Byte.MaxValue)
throw new OverflowException ();
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.sbyte_type) {
+ case BuildinTypeSpec.Type.SByte:
if (in_checked_context && Value > ((ulong) SByte.MaxValue))
throw new OverflowException ();
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.short_type) {
+ case BuildinTypeSpec.Type.Short:
if (in_checked_context && Value > ((ulong) Int16.MaxValue))
throw new OverflowException ();
return new ShortConstant ((short) Value, Location);
- }
- if (target_type == TypeManager.ushort_type) {
+ case BuildinTypeSpec.Type.UShort:
if (in_checked_context && Value > UInt16.MaxValue)
throw new OverflowException ();
return new UShortConstant ((ushort) Value, Location);
- }
- if (target_type == TypeManager.int32_type) {
+ case BuildinTypeSpec.Type.Int:
if (in_checked_context && Value > UInt32.MaxValue)
throw new OverflowException ();
return new IntConstant ((int) Value, Location);
- }
- if (target_type == TypeManager.uint32_type) {
- if (in_checked_context && Value > UInt32.MaxValue)
+ case BuildinTypeSpec.Type.UInt:
+ if (in_checked_context && Value > UInt32.MaxValue)
throw new OverflowException ();
return new UIntConstant ((uint) Value, Location);
- }
- if (target_type == TypeManager.int64_type) {
+ case BuildinTypeSpec.Type.Long:
if (in_checked_context && Value > Int64.MaxValue)
throw new OverflowException ();
return new LongConstant ((long) Value, Location);
- }
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.char_type) {
+ case BuildinTypeSpec.Type.Char:
if (in_checked_context && Value > Char.MaxValue)
throw new OverflowException ();
return new CharConstant ((char) Value, Location);
- }
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.Emit (OpCodes.Ldc_R4, Value);
}
- public override string AsString ()
+ public override object GetValue ()
+ {
+ return Value;
+ }
+
+ public override string GetValueAsLiteral ()
{
return Value.ToString ();
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
- return Value;
+ throw new NotSupportedException ();
}
public override bool IsDefaultValue {
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
- if (in_checked_context){
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
+ if (in_checked_context) {
if (Value < byte.MinValue || Value > byte.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.sbyte_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.SByte:
+ if (in_checked_context) {
if (Value < sbyte.MinValue || Value > sbyte.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.short_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Short:
+ if (in_checked_context) {
if (Value < short.MinValue || Value > short.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new ShortConstant ((short) Value, Location);
- }
- if (target_type == TypeManager.ushort_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.UShort:
+ if (in_checked_context) {
if (Value < ushort.MinValue || Value > ushort.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new UShortConstant ((ushort) Value, Location);
- }
- if (target_type == TypeManager.int32_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Int:
+ if (in_checked_context) {
if (Value < int.MinValue || Value > int.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new IntConstant ((int) Value, Location);
- }
- if (target_type == TypeManager.uint32_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.UInt:
+ if (in_checked_context) {
if (Value < uint.MinValue || Value > uint.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new UIntConstant ((uint) Value, Location);
- }
- if (target_type == TypeManager.int64_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Long:
+ if (in_checked_context) {
if (Value < long.MinValue || Value > long.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new LongConstant ((long) Value, Location);
- }
- if (target_type == TypeManager.uint64_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.ULong:
+ if (in_checked_context) {
if (Value < ulong.MinValue || Value > ulong.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new ULongConstant ((ulong) Value, Location);
- }
- if (target_type == TypeManager.double_type)
+ case BuildinTypeSpec.Type.Double:
return new DoubleConstant ((double) Value, Location);
- if (target_type == TypeManager.char_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Char:
+ if (in_checked_context) {
if (Value < (float) char.MinValue || Value > (float) char.MaxValue || float.IsNaN (Value))
throw new OverflowException ();
}
return new CharConstant ((char) Value, Location);
- }
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- enc.Stream.Write (Value);
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
ec.Emit (OpCodes.Ldc_R8, Value);
}
- public override string AsString ()
+ public override object GetValue ()
+ {
+ return Value;
+ }
+
+ public override string GetValueAsLiteral ()
{
return Value.ToString ();
}
- public override object GetValue ()
+ public override long GetValueAsLong ()
{
- return Value;
+ throw new NotSupportedException ();
}
public override bool IsDefaultValue {
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.byte_type) {
- if (in_checked_context){
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.Byte:
+ if (in_checked_context) {
if (Value < Byte.MinValue || Value > Byte.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
- }
- if (target_type == TypeManager.sbyte_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.SByte:
+ if (in_checked_context) {
if (Value < SByte.MinValue || Value > SByte.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new SByteConstant ((sbyte) Value, Location);
- }
- if (target_type == TypeManager.short_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Short:
+ if (in_checked_context) {
if (Value < short.MinValue || Value > short.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new ShortConstant ((short) Value, Location);
- }
- if (target_type == TypeManager.ushort_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.UShort:
+ if (in_checked_context) {
if (Value < ushort.MinValue || Value > ushort.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new UShortConstant ((ushort) Value, Location);
- }
- if (target_type == TypeManager.int32_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Int:
+ if (in_checked_context) {
if (Value < int.MinValue || Value > int.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new IntConstant ((int) Value, Location);
- }
- if (target_type == TypeManager.uint32_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.UInt:
+ if (in_checked_context) {
if (Value < uint.MinValue || Value > uint.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new UIntConstant ((uint) Value, Location);
- }
- if (target_type == TypeManager.int64_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Long:
+ if (in_checked_context) {
if (Value < long.MinValue || Value > long.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new LongConstant ((long) Value, Location);
- }
- if (target_type == TypeManager.uint64_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.ULong:
+ if (in_checked_context) {
if (Value < ulong.MinValue || Value > ulong.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new ULongConstant ((ulong) Value, Location);
- }
- if (target_type == TypeManager.float_type)
+ case BuildinTypeSpec.Type.Float:
return new FloatConstant ((float) Value, Location);
- if (target_type == TypeManager.char_type) {
- if (in_checked_context){
+ case BuildinTypeSpec.Type.Char:
+ if (in_checked_context) {
if (Value < (double) char.MinValue || Value > (double) char.MaxValue || double.IsNaN (Value))
throw new OverflowException ();
}
return new CharConstant ((char) Value, Location);
- }
- if (target_type == TypeManager.decimal_type)
+ case BuildinTypeSpec.Type.Decimal:
return new DecimalConstant ((decimal) Value, Location);
+ }
return null;
}
Value = d;
}
- override public string AsString ()
- {
- return Value.ToString () + "M";
- }
-
protected override Expression DoResolve (ResolveContext rc)
{
type = TypeManager.decimal_type;
return this;
}
- public override object GetValue ()
- {
- return (object) Value;
- }
-
public override void Emit (EmitContext ec)
{
int [] words = decimal.GetBits (Value);
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
- if (target_type == TypeManager.sbyte_type)
- return new SByteConstant ((sbyte)Value, loc);
- if (target_type == TypeManager.byte_type)
- return new ByteConstant ((byte)Value, loc);
- if (target_type == TypeManager.short_type)
- return new ShortConstant ((short)Value, loc);
- if (target_type == TypeManager.ushort_type)
- return new UShortConstant ((ushort)Value, loc);
- if (target_type == TypeManager.int32_type)
- return new IntConstant ((int)Value, loc);
- if (target_type == TypeManager.uint32_type)
- return new UIntConstant ((uint)Value, loc);
- if (target_type == TypeManager.int64_type)
- return new LongConstant ((long)Value, loc);
- if (target_type == TypeManager.uint64_type)
- return new ULongConstant ((ulong)Value, loc);
- if (target_type == TypeManager.char_type)
- return new CharConstant ((char)Value, loc);
- if (target_type == TypeManager.float_type)
- return new FloatConstant ((float)Value, loc);
- if (target_type == TypeManager.double_type)
- return new DoubleConstant ((double)Value, loc);
+ switch (target_type.BuildinType) {
+ case BuildinTypeSpec.Type.SByte:
+ return new SByteConstant ((sbyte) Value, loc);
+ case BuildinTypeSpec.Type.Byte:
+ return new ByteConstant ((byte) Value, loc);
+ case BuildinTypeSpec.Type.Short:
+ return new ShortConstant ((short) Value, loc);
+ case BuildinTypeSpec.Type.UShort:
+ return new UShortConstant ((ushort) Value, loc);
+ case BuildinTypeSpec.Type.Int:
+ return new IntConstant ((int) Value, loc);
+ case BuildinTypeSpec.Type.UInt:
+ return new UIntConstant ((uint) Value, loc);
+ case BuildinTypeSpec.Type.Long:
+ return new LongConstant ((long) Value, loc);
+ case BuildinTypeSpec.Type.ULong:
+ return new ULongConstant ((ulong) Value, loc);
+ case BuildinTypeSpec.Type.Char:
+ return new CharConstant ((char) Value, loc);
+ case BuildinTypeSpec.Type.Float:
+ return new FloatConstant ((float) Value, loc);
+ case BuildinTypeSpec.Type.Double:
+ return new DoubleConstant ((double) Value, loc);
+ }
return null;
}
+ public override object GetValue ()
+ {
+ return Value;
+ }
+
+ public override string GetValueAsLiteral ()
+ {
+ return Value.ToString () + "M";
+ }
+
+ public override long GetValueAsLong ()
+ {
+ throw new NotSupportedException ();
+ }
}
public class StringConstant : Constant {
Value = s;
}
- // FIXME: Escape the string.
- override public string AsString ()
- {
- return "\"" + Value + "\"";
- }
-
protected override Expression DoResolve (ResolveContext rc)
{
type = TypeManager.string_type;
{
return Value;
}
+
+ public override string GetValueAsLiteral ()
+ {
+ // FIXME: Escape the string.
+ return "\"" + Value + "\"";
+ }
+
+ public override long GetValueAsLong ()
+ {
+ throw new NotSupportedException ();
+ }
public override void Emit (EmitContext ec)
{
// Use string.Empty for both literals and constants even if
// it's not allowed at language level
//
- if (Value.Length == 0 && RootContext.Optimize && !TypeManager.IsEqual (ec.CurrentType, TypeManager.string_type)) {
+ if (Value.Length == 0 && ec.Module.Compiler.Settings.Optimize && ec.CurrentType != TypeManager.string_type) {
if (TypeManager.string_empty == null)
TypeManager.string_empty = TypeManager.GetPredefinedField (TypeManager.string_type, "Empty", loc, TypeManager.string_type);
this.type = type;
}
- public override string AsString ()
- {
- return GetSignatureForError ();
- }
-
public override Expression CreateExpressionTree (ResolveContext ec)
{
if (type == InternalType.Null || type == TypeManager.object_type) {
public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
// Type it as string cast
- if (targetType == TypeManager.object_type || targetType == TypeManager.null_type)
+ if (targetType == TypeManager.object_type || targetType == InternalType.Null)
enc.Encode (TypeManager.string_type);
var ac = targetType as ArrayContainer;
if (ac != null) {
- if (ac.Rank != 1)
+ if (ac.Rank != 1 || ac.Element.IsArray)
base.EncodeAttributeValue (rc, enc, targetType);
else
- enc.Stream.Write (uint.MaxValue);
+ enc.Encode (uint.MaxValue);
} else {
- enc.Stream.Write (byte.MaxValue);
+ enc.Encode (byte.MaxValue);
}
}
}
}
- public override string GetSignatureForError ()
- {
- return "null";
- }
-
public override Constant ConvertExplicitly (bool inCheckedContext, TypeSpec targetType)
{
if (targetType.IsPointer) {
}
// Exlude internal compiler types
- if (targetType == InternalType.AnonymousMethod)
+ if (targetType.Kind == MemberKind.InternalCompilerType && targetType != InternalType.Dynamic && targetType != InternalType.Null)
return null;
if (!IsLiteral && !Convert.ImplicitStandardConversionExists (this, targetType))
return ConvertExplicitly (false, targetType);
}
+ public override string GetSignatureForError ()
+ {
+ return "null";
+ }
+
public override object GetValue ()
{
return null;
}
+ public override string GetValueAsLiteral ()
+ {
+ return GetSignatureForError ();
+ }
+
+ public override long GetValueAsLong ()
+ {
+ throw new NotSupportedException ();
+ }
+
public override bool IsDefaultValue {
get { return true; }
}
this.side_effect = side_effect;
}
- public override string AsString ()
- {
- return value.AsString ();
- }
-
protected override Expression DoResolve (ResolveContext rc)
{
value = value.Resolve (rc);
return value.GetValue ();
}
+ public override string GetValueAsLiteral ()
+ {
+ return value.GetValueAsLiteral ();
+ }
+
+ public override long GetValueAsLong ()
+ {
+ return value.GetValueAsLong ();
+ }
+
public override void Emit (EmitContext ec)
{
side_effect.EmitSideEffect (ec);
public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
Constant new_value = value.ConvertExplicitly (in_checked_context, target_type);
- return new_value == null ? null : new SideEffectConstant (new_value, side_effect, new_value.Location);
+ if (new_value == null)
+ return null;
+
+ var c = new SideEffectConstant (new_value, side_effect, new_value.Location);
+ c.type = target_type;
+ c.eclass = eclass;
+ return c;
}
}
}