X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fliteral.cs;h=c7aae9204b0a775c51648643e8ade9d926fb42ca;hb=67597881bd4731b3f1c848fc9f8f13e63e7d2c0f;hp=8582a4f8dfcd4facf87622c8242f002da9add880;hpb=0649b90c407fc29ee8377f2c6fb42ae2c006e26a;p=mono.git diff --git a/mcs/mcs/literal.cs b/mcs/mcs/literal.cs index 8582a4f8dfc..c7aae9204b0 100644 --- a/mcs/mcs/literal.cs +++ b/mcs/mcs/literal.cs @@ -47,14 +47,8 @@ namespace Mono.CSharp { // The null Literal constant // public class NullLiteral : Constant { - public static readonly NullLiteral Null; - - static NullLiteral () - { - Null = new NullLiteral (); - } - - public NullLiteral () + public NullLiteral (Location loc): + base (loc) { eclass = ExprClass.Value; } @@ -106,7 +100,7 @@ namespace Mono.CSharp { return "null"; } - public override void Error_ValueCannotBeConverted (Location loc, Type t) + public override void Error_ValueCannotBeConverted (Location loc, Type t, bool expl) { Report.Error (37, loc, "Cannot convert null to `{0}' because it is a value type", TypeManager.CSharpName (t)); @@ -115,25 +109,33 @@ namespace Mono.CSharp { public override Constant ToType (Type type, Location loc) { if (!type.IsValueType && !TypeManager.IsEnumType (type)) - return NullLiteral.Null; + return this; return base.ToType (type, loc); } + public override Constant Reduce(EmitContext ec, Type target_type) + { + if (!TypeManager.IsValueType (target_type)) + return new NullCast (this, target_type); + + return null; + } } // // A null literal in a pointer context // public class NullPointer : NullLiteral { - public new static readonly NullLiteral Null; + public static readonly NullLiteral Null; static NullPointer () { Null = new NullPointer (); } - private NullPointer () + private NullPointer (): + base (Location.Null) { type = TypeManager.object_type; } @@ -148,7 +150,7 @@ namespace Mono.CSharp { } public class BoolLiteral : BoolConstant { - public BoolLiteral (bool val) : base (val) + public BoolLiteral (bool val, Location loc) : base (val, loc) { } @@ -160,7 +162,7 @@ namespace Mono.CSharp { } public class CharLiteral : CharConstant { - public CharLiteral (char c) : base (c) + public CharLiteral (char c, Location loc) : base (c, loc) { } @@ -172,15 +174,7 @@ namespace Mono.CSharp { } public class IntLiteral : IntConstant { - public static IntLiteral One, Zero; - - static IntLiteral () - { - Zero = new IntLiteral (0); - One = new IntLiteral (1); - } - - public IntLiteral (int l) : base (l) + public IntLiteral (int l, Location loc) : base (l, loc) { } @@ -192,7 +186,7 @@ namespace Mono.CSharp { } public class UIntLiteral : UIntConstant { - public UIntLiteral (uint l) : base (l) + public UIntLiteral (uint l, Location loc) : base (l, loc) { } @@ -204,7 +198,7 @@ namespace Mono.CSharp { } public class LongLiteral : LongConstant { - public LongLiteral (long l) : base (l) + public LongLiteral (long l, Location loc) : base (l, loc) { } @@ -217,7 +211,7 @@ namespace Mono.CSharp { } public class ULongLiteral : ULongConstant { - public ULongLiteral (ulong l) : base (l) + public ULongLiteral (ulong l, Location loc) : base (l, loc) { } @@ -230,7 +224,7 @@ namespace Mono.CSharp { public class FloatLiteral : FloatConstant { - public FloatLiteral (float f) : base (f) + public FloatLiteral (float f, Location loc) : base (f, loc) { } @@ -242,7 +236,7 @@ namespace Mono.CSharp { } public class DoubleLiteral : DoubleConstant { - public DoubleLiteral (double d) : base (d) + public DoubleLiteral (double d, Location loc) : base (d, loc) { } @@ -255,7 +249,7 @@ namespace Mono.CSharp { } public class DecimalLiteral : DecimalConstant { - public DecimalLiteral (decimal d) : base (d) + public DecimalLiteral (decimal d, Location loc) : base (d, loc) { } @@ -267,7 +261,7 @@ namespace Mono.CSharp { } public class StringLiteral : StringConstant { - public StringLiteral (string s) : base (s) + public StringLiteral (string s, Location loc) : base (s, loc) { }