//
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 () + ")";
- }
-
- public override bool GetAttributableValue (ResolveContext ec, Type value_type, out object value)
- {
- if (value_type == TypeManager.object_type) {
- value = GetTypedValue ();
- return true;
- }
-
- Constant c = ImplicitConversionRequired (ec, value_type, loc);
- if (c == null) {
- value = null;
- return false;
- }
-
- value = c.GetTypedValue ();
- return true;
+ return this.GetType ().Name + " (" + GetValueAsLiteral () + ")";
}
/// <summary>
/// </summary>
public abstract object GetValue ();
+ 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, Type target, bool expl)
+ public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl)
{
if (!expl && IsLiteral &&
(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 Constant ImplicitConversionRequired (ResolveContext ec, Type type, Location loc)
+ public Constant ImplicitConversionRequired (ResolveContext ec, TypeSpec type, Location loc)
{
Constant c = ConvertImplicitly (ec, type);
if (c == null)
return c;
}
- public virtual Constant ConvertImplicitly (ResolveContext rc, Type type)
+ public virtual Constant ConvertImplicitly (ResolveContext rc, TypeSpec type)
{
if (this.type == type)
return this;
//
// Returns a constant instance based on Type
//
- public static Constant CreateConstant (ResolveContext rc, Type t, object v, Location loc)
+ public static Constant CreateConstant (ResolveContext rc, TypeSpec t, object v, Location loc)
{
return CreateConstantFromValue (t, v, loc).Resolve (rc);
}
- public static Constant CreateConstantFromValue (Type t, object v, Location loc)
+ public static Constant CreateConstantFromValue (TypeSpec t, object v, Location loc)
{
if (t == TypeManager.int32_type)
return new IntConstant ((int) v, loc);
if (t == TypeManager.decimal_type)
return new DecimalConstant ((decimal) v, loc);
if (TypeManager.IsEnumType (t)) {
- Type real_type = TypeManager.GetEnumUnderlyingType (t);
+ var real_type = EnumSpec.GetUnderlyingType (t);
return new EnumConstant (CreateConstantFromValue (real_type, v, loc).Resolve (null), t);
}
if (v == null) {
/// It throws OverflowException
/// </summary>
// DON'T CALL THIS METHOD DIRECTLY AS IT DOES NOT HANDLE ENUMS
- public abstract Constant ConvertExplicitly (bool in_checked_context, Type target_type);
+ public abstract Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type);
/// <summary>
/// Attempts to do a compile-time folding of a constant cast.
/// </summary>
- public Constant TryReduce (ResolveContext ec, Type target_type, Location loc)
+ public Constant TryReduce (ResolveContext ec, TypeSpec target_type, Location loc)
{
try {
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);
}
}
- Constant TryReduce (ResolveContext ec, Type target_type)
+ Constant TryReduce (ResolveContext ec, TypeSpec target_type)
{
if (Type == target_type)
return this;
Constant c;
if (TypeManager.IsEnumType (target_type)) {
- c = TryReduce (ec, TypeManager.GetEnumUnderlyingType (target_type));
+ c = TryReduce (ec, EnumSpec.GetUnderlyingType (target_type));
if (c == null)
return null;
/// Need to pass type as the constant can require a boxing
/// and in such case no optimization is possible
/// </summary>
- public bool IsDefaultInitializer (Type type)
+ public bool IsDefaultInitializer (TypeSpec type)
{
if (type == Type)
return IsDefaultValue;
// do nothing
}
- protected override void CloneTo (CloneContext clonectx, Expression target)
+ public sealed override Expression Clone (CloneContext clonectx)
{
- // CloneTo: Nothing, we do not keep any state on this expression
+ // No cloning is not needed for constants
+ return this;
}
- public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
+ protected override void CloneTo (CloneContext clonectx, Expression target)
{
- return System.Linq.Expressions.Expression.Constant (GetTypedValue (), type);
+ throw new NotSupportedException ("should not be reached");
}
- public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
+ public override System.Linq.Expressions.Expression MakeExpression (BuilderContext ctx)
{
- // A constant cannot be of generic type
+#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)
{
}
- public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, Type target, bool expl)
+ public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl)
{
try {
ConvertExplicitly (true, target);
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 void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
+ {
+ enc.Encode (Value);
+ }
public override void Emit (EmitContext ec)
{
if (Value)
- ec.ig.Emit (OpCodes.Ldc_I4_1);
+ ec.Emit (OpCodes.Ldc_I4_1);
else
- ec.ig.Emit (OpCodes.Ldc_I4_0);
+ ec.Emit (OpCodes.Ldc_I4_0);
}
public override bool IsDefaultValue {
get { return Value == false; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
return null;
}
Value = v;
}
- public override void Emit (EmitContext ec)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- IntLiteral.EmitInt (ec.ig, Value);
+ enc.Encode (Value);
}
- public override string AsString ()
+ public override void Emit (EmitContext ec)
{
- return Value.ToString ();
+ ec.EmitInt (Value);
}
protected override Expression DoResolve (ResolveContext ec)
get { return Value == 0; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.sbyte_type) {
if (in_checked_context){
return this;
}
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
+ {
+ enc.Encode ((ushort) Value);
+ }
+
public override void Emit (EmitContext ec)
{
- IntLiteral.EmitInt (ec.ig, Value);
+ ec.EmitInt (Value);
}
static string descape (char c)
return c.ToString ();
}
- public override string AsString ()
+ public override object GetValue ()
{
- return "\"" + descape (Value) + "\"";
+ return Value;
}
- public override object GetValue ()
+ public override string GetValueAsLiteral ()
{
- return Value;
+ return "\"" + descape (Value) + "\"";
}
public override bool IsDefaultValue {
get { return Value == '\0'; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context){
return this;
}
- public override void Emit (EmitContext ec)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- IntLiteral.EmitInt (ec.ig, Value);
+ enc.Encode (Value);
}
- public override string AsString ()
+ public override void Emit (EmitContext ec)
{
- return Value.ToString ();
+ ec.EmitInt (Value);
}
public override object GetValue ()
get { return Value == 0; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context && Value < 0)
return this;
}
- public override void Emit (EmitContext ec)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- IntLiteral.EmitInt (ec.ig, Value);
+ enc.Encode (Value);
}
- public override string AsString ()
+ public override void Emit (EmitContext ec)
{
- return Value.ToString ();
+ ec.EmitInt (Value);
}
public override object GetValue ()
}
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context){
return this;
}
- public override void Emit (EmitContext ec)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- IntLiteral.EmitInt (ec.ig, Value);
+ enc.Encode (Value);
}
- public override string AsString ()
+ public override void Emit (EmitContext ec)
{
- return Value.ToString ();
+ ec.EmitInt (Value);
}
public override object GetValue ()
get { return Value == 0; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context){
return this;
}
- static public void EmitInt (ILGenerator ig, int i)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- switch (i){
- case -1:
- ig.Emit (OpCodes.Ldc_I4_M1);
- break;
-
- case 0:
- ig.Emit (OpCodes.Ldc_I4_0);
- break;
-
- case 1:
- ig.Emit (OpCodes.Ldc_I4_1);
- break;
-
- case 2:
- ig.Emit (OpCodes.Ldc_I4_2);
- break;
-
- case 3:
- ig.Emit (OpCodes.Ldc_I4_3);
- break;
-
- case 4:
- ig.Emit (OpCodes.Ldc_I4_4);
- break;
-
- case 5:
- ig.Emit (OpCodes.Ldc_I4_5);
- break;
-
- case 6:
- ig.Emit (OpCodes.Ldc_I4_6);
- break;
-
- case 7:
- ig.Emit (OpCodes.Ldc_I4_7);
- break;
-
- case 8:
- ig.Emit (OpCodes.Ldc_I4_8);
- break;
-
- default:
- if (i >= -128 && i <= 127){
- ig.Emit (OpCodes.Ldc_I4_S, (sbyte) i);
- } else
- ig.Emit (OpCodes.Ldc_I4, i);
- break;
- }
+ enc.Encode (Value);
}
public override void Emit (EmitContext ec)
{
- EmitInt (ec.ig, Value);
- }
-
- public override string AsString ()
- {
- return Value.ToString ();
+ ec.EmitInt (Value);
}
public override object GetValue ()
get { return Value == 0; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context){
return null;
}
- public override Constant ConvertImplicitly (ResolveContext rc, Type type)
+ public override Constant ConvertImplicitly (ResolveContext rc, TypeSpec type)
{
if (this.type == type)
return this;
/// into a different data type using casts (See Implicit Constant
/// Expression Conversions)
/// </summary>
- Constant TryImplicitIntConversion (Type target_type)
+ Constant TryImplicitIntConversion (TypeSpec target_type)
{
if (target_type == TypeManager.sbyte_type) {
if (Value >= SByte.MinValue && Value <= SByte.MaxValue)
return this;
}
- public override void Emit (EmitContext ec)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- IntLiteral.EmitInt (ec.ig, unchecked ((int) Value));
+ enc.Encode (Value);
}
- public override string AsString ()
+ public override void Emit (EmitContext ec)
{
- return Value.ToString ();
+ ec.EmitInt (unchecked ((int) Value));
}
public override object GetValue ()
get { return Value == 0; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ 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)
+ if (Value < 0 || Value > byte.MaxValue)
throw new OverflowException ();
}
return new ByteConstant ((byte) Value, Location);
return this;
}
- public override void Emit (EmitContext ec)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- EmitLong (ec.ig, Value);
- }
-
- static public void EmitLong (ILGenerator ig, long l)
- {
- if (l >= int.MinValue && l <= int.MaxValue) {
- IntLiteral.EmitInt (ig, unchecked ((int) l));
- ig.Emit (OpCodes.Conv_I8);
- return;
- }
-
- if (l >= 0 && l <= uint.MaxValue) {
- IntLiteral.EmitInt (ig, unchecked ((int) l));
- ig.Emit (OpCodes.Conv_U8);
- return;
- }
-
- ig.Emit (OpCodes.Ldc_I8, l);
+ enc.Encode (Value);
}
- public override string AsString ()
+ public override void Emit (EmitContext ec)
{
- return Value.ToString ();
+ ec.EmitLong (Value);
}
public override object GetValue ()
get { return Value == 0; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context){
return null;
}
- public override Constant ConvertImplicitly (ResolveContext rc, Type type)
+ public override Constant ConvertImplicitly (ResolveContext rc, TypeSpec type)
{
if (Value >= 0 && type == TypeManager.uint64_type) {
return new ULongConstant ((ulong) Value, loc).Resolve (rc);
return this;
}
- public override void Emit (EmitContext ec)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- ILGenerator ig = ec.ig;
-
- LongLiteral.EmitLong (ig, unchecked ((long) Value));
+ enc.Encode (Value);
}
- public override string AsString ()
+ public override void Emit (EmitContext ec)
{
- return Value.ToString ();
+ ec.EmitLong (unchecked ((long) Value));
}
public override object GetValue ()
get { return Value == 0; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context && Value > Byte.MaxValue)
return this;
}
- public override void Emit (EmitContext ec)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- ec.ig.Emit (OpCodes.Ldc_R4, Value);
+ enc.Encode (Value);
}
- public override string AsString ()
+ public override void Emit (EmitContext ec)
{
- return Value.ToString ();
+ ec.Emit (OpCodes.Ldc_R4, Value);
}
public override object GetValue ()
return Value;
}
+ public override string GetValueAsLiteral ()
+ {
+ return Value.ToString ();
+ }
+
public override bool IsDefaultValue {
get {
return Value == 0;
}
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context){
return this;
}
- public override void Emit (EmitContext ec)
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
{
- ec.ig.Emit (OpCodes.Ldc_R8, Value);
+ enc.Encode (Value);
}
- public override string AsString ()
+ public override void Emit (EmitContext ec)
{
- return Value.ToString ();
+ ec.Emit (OpCodes.Ldc_R8, Value);
}
public override object GetValue ()
return Value;
}
+ public override string GetValueAsLiteral ()
+ {
+ return Value.ToString ();
+ }
+
public override bool IsDefaultValue {
get {
return Value == 0;
}
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.byte_type) {
if (in_checked_context){
Value = d;
}
- override public string AsString ()
- {
- return Value.ToString () + "M";
- }
-
protected override Expression DoResolve (ResolveContext rc)
{
type = TypeManager.decimal_type;
public override object GetValue ()
{
- return (object) Value;
+ return Value;
}
- public override void Emit (EmitContext ec)
+ public override string GetValueAsLiteral ()
{
- ILGenerator ig = ec.ig;
+ return Value.ToString () + "M";
+ }
+ public override void Emit (EmitContext ec)
+ {
int [] words = decimal.GetBits (Value);
int power = (words [3] >> 16) & 0xff;
return;
}
- IntConstant.EmitInt (ig, (int) Value);
- ig.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_int_arg);
+ ec.EmitInt ((int) Value);
+ ec.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_int_arg);
return;
}
return;
}
- LongConstant.EmitLong (ig, (long) Value);
- ig.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_long_arg);
+ ec.EmitLong ((long) Value);
+ ec.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_long_arg);
return;
}
}
- IntConstant.EmitInt (ig, words [0]);
- IntConstant.EmitInt (ig, words [1]);
- IntConstant.EmitInt (ig, words [2]);
+ ec.EmitInt (words [0]);
+ ec.EmitInt (words [1]);
+ ec.EmitInt (words [2]);
// sign
- IntConstant.EmitInt (ig, words [3] >> 31);
+ ec.EmitInt (words [3] >> 31);
// power
- IntConstant.EmitInt (ig, power);
+ ec.EmitInt (power);
if (TypeManager.void_decimal_ctor_five_args == null) {
TypeManager.void_decimal_ctor_five_args = TypeManager.GetPredefinedConstructor (
return;
}
- ig.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_five_args);
+ ec.Emit (OpCodes.Newobj, TypeManager.void_decimal_ctor_five_args);
}
public override bool IsDefaultValue {
}
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
if (target_type == TypeManager.sbyte_type)
return new SByteConstant ((sbyte)Value, loc);
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 void Emit (EmitContext ec)
{
if (Value == null) {
- ec.ig.Emit (OpCodes.Ldnull);
+ ec.Emit (OpCodes.Ldnull);
return;
}
// 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 && RootContext.Optimize && ec.CurrentType != TypeManager.string_type) {
if (TypeManager.string_empty == null)
- TypeManager.string_empty = TypeManager.GetPredefinedField (TypeManager.string_type, "Empty", loc);
+ TypeManager.string_empty = TypeManager.GetPredefinedField (TypeManager.string_type, "Empty", loc, TypeManager.string_type);
if (TypeManager.string_empty != null) {
- ec.ig.Emit (OpCodes.Ldsfld, TypeManager.string_empty);
+ ec.Emit (OpCodes.Ldsfld, TypeManager.string_empty);
return;
}
}
- ec.ig.Emit (OpCodes.Ldstr, Value);
+ ec.Emit (OpCodes.Ldstr, Value);
+ }
+
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
+ {
+ // cast to object
+ if (type != targetType)
+ enc.Encode (type);
+
+ enc.Encode (Value);
}
public override bool IsDefaultValue {
}
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ public override Constant ConvertExplicitly (bool in_checked_context, TypeSpec target_type)
{
return null;
}
//
public class NullConstant : Constant
{
- public NullConstant (Type type, Location loc)
+ public NullConstant (TypeSpec type, Location loc)
: base (loc)
{
eclass = ExprClass.Value;
this.type = type;
}
- public override string AsString ()
+ public override Expression CreateExpressionTree (ResolveContext ec)
{
- return GetSignatureForError ();
+ if (type == InternalType.Null || type == TypeManager.object_type) {
+ // Optimized version, also avoids referencing literal internal type
+ Arguments args = new Arguments (1);
+ args.Add (new Argument (this));
+ return CreateExpressionFactoryCall (ec, "Constant", args);
+ }
+
+ return base.CreateExpressionTree (ec);
}
protected override Expression DoResolve (ResolveContext ec)
return this;
}
+ public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
+ {
+ // Type it as string cast
+ 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 || ac.Element.IsArray)
+ base.EncodeAttributeValue (rc, enc, targetType);
+ else
+ enc.Encode (uint.MaxValue);
+ } else {
+ enc.Encode (byte.MaxValue);
+ }
+ }
+
public override void Emit (EmitContext ec)
{
- ec.ig.Emit (OpCodes.Ldnull);
+ ec.Emit (OpCodes.Ldnull);
// Only to make verifier happy
if (TypeManager.IsGenericParameter (type))
- ec.ig.Emit (OpCodes.Unbox_Any, type);
+ ec.Emit (OpCodes.Unbox_Any, type);
}
public override string ExprClassName {
}
}
- public override string GetSignatureForError ()
- {
- return "null";
- }
-
- public override Constant ConvertExplicitly (bool inCheckedContext, Type targetType)
+ public override Constant ConvertExplicitly (bool inCheckedContext, TypeSpec targetType)
{
if (targetType.IsPointer) {
if (IsLiteral || this is NullPointer)
}
// 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 null;
}
- public override Constant ConvertImplicitly (ResolveContext rc, Type targetType)
+ public override Constant ConvertImplicitly (ResolveContext rc, TypeSpec 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 bool IsDefaultValue {
get { return true; }
}
public override bool IsZeroInteger {
get { return true; }
}
-
- public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
- {
- type = storey.MutateType (type);
- }
}
/// <summary>
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 void Emit (EmitContext ec)
{
side_effect.EmitSideEffect (ec);
get { return value.IsZeroInteger; }
}
- public override Constant ConvertExplicitly (bool in_checked_context, Type target_type)
+ 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);