X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fmcs%2Fliteral.cs;h=c7aae9204b0a775c51648643e8ade9d926fb42ca;hb=67597881bd4731b3f1c848fc9f8f13e63e7d2c0f;hp=a998bb28a8ed342a131d5f1dad0f5cbfcdb1242b;hpb=1d3cbfe8b8f8a453f616ad6ee7cfefdb8917ecac;p=mono.git diff --git a/mcs/mcs/literal.cs b/mcs/mcs/literal.cs old mode 100755 new mode 100644 index a998bb28a8e..c7aae9204b0 --- 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; } @@ -79,7 +73,18 @@ namespace Mono.CSharp { { ec.ig.Emit (OpCodes.Ldnull); } - + + public override Constant Increment () + { + throw new NotSupportedException (); + } + + public override bool IsDefaultValue { + get { + return true; + } + } + public override bool IsNegative { get { return false; @@ -89,20 +94,48 @@ namespace Mono.CSharp { public override bool IsZeroInteger { get { return true; } } + + public override string GetSignatureForError() + { + return "null"; + } + + 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)); + } + + public override Constant ToType (Type type, Location loc) + { + if (!type.IsValueType && !TypeManager.IsEnumType (type)) + 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; } @@ -117,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) { } @@ -129,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) { } @@ -141,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) { } @@ -161,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) { } @@ -173,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) { } @@ -186,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) { } @@ -199,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) { } @@ -211,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) { } @@ -224,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) { } @@ -236,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) { }