X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mcs%2Fmcs%2Fliteral.cs;h=1af2d0c9e379ecb600379156bfe84dbf1ab67bb9;hb=25b04d16d938df85b72479d1af667f8823fb6434;hp=7b1243f1112b22b09d63ff8b6ee18baadbfbaa6b;hpb=1bc916c295445e56c74e8550a1ff1fd0bdfbf0dd;p=mono.git diff --git a/mcs/mcs/literal.cs b/mcs/mcs/literal.cs index 7b1243f1112..1af2d0c9e37 100644 --- a/mcs/mcs/literal.cs +++ b/mcs/mcs/literal.cs @@ -6,6 +6,7 @@ // Marek Safar (marek.safar@seznam.cz) // // Copyright 2001 Ximian, Inc. +// Copyright 2011 Xamarin Inc // // // Notice that during parsing we create objects of type Literal, but the @@ -19,11 +20,20 @@ // and are fully resolved when born. // -using System; -using System.Reflection; +#if STATIC +using IKVM.Reflection.Emit; +#else using System.Reflection.Emit; +#endif -namespace Mono.CSharp { +namespace Mono.CSharp +{ + public interface ILiteralConstant + { +#if FULL_AST + char[] ParsedValue { get; set; } +#endif + } // // The null literal @@ -36,19 +46,11 @@ namespace Mono.CSharp { // Default type of null is an object // public NullLiteral (Location loc) - : base (InternalType.Null, loc) + : base (InternalType.NullLiteral, loc) { } - public override Expression CreateExpressionTree (ResolveContext ec) - { - // Optimized version, also avoids referencing literal internal type - Arguments args = new Arguments (1); - args.Add (new Argument (this)); - return CreateExpressionFactoryCall (ec, "Constant", args); - } - - public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec t, bool expl) + public override void Error_ValueCannotBeConverted (ResolveContext ec, TypeSpec t, bool expl) { if (t.IsGenericParameter) { ec.Report.Error(403, loc, @@ -57,24 +59,18 @@ namespace Mono.CSharp { return; } - if (TypeManager.IsValueType (t)) { + if (TypeSpec.IsValueType (t)) { ec.Report.Error(37, loc, "Cannot convert null to `{0}' because it is a value type", - TypeManager.CSharpName(t)); + t.GetSignatureForError ()); return; } - base.Error_ValueCannotBeConverted (ec, loc, t, expl); + base.Error_ValueCannotBeConverted (ec, t, expl); } - public override Constant ConvertImplicitly (ResolveContext rc, TypeSpec targetType) + public override string GetValueAsLiteral () { - // - // Null literal is of object type - // - if (targetType == TypeManager.object_type) - return this; - - return base.ConvertImplicitly (rc, targetType); + return "null"; } public override bool IsLiteral { @@ -87,105 +83,152 @@ namespace Mono.CSharp { } } - // - // A null literal in a pointer context - // - class NullPointer : NullLiteral { - public NullPointer (Location loc): - base (loc) + public class BoolLiteral : BoolConstant, ILiteralConstant + { + public BoolLiteral (BuiltinTypes types, bool val, Location loc) + : base (types, val, loc) { - type = TypeManager.object_type; } - public override void Emit (EmitContext ec) + public override bool IsLiteral { + get { return true; } + } + +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif + + public override object Accept (StructuralVisitor visitor) { - // - // Emits null pointer - // - ec.Emit (OpCodes.Ldc_I4_0); - ec.Emit (OpCodes.Conv_U); + return visitor.Visit (this); } } - public class BoolLiteral : BoolConstant { - public BoolLiteral (bool val, Location loc) : base (val, loc) + public class CharLiteral : CharConstant, ILiteralConstant + { + public CharLiteral (BuiltinTypes types, char c, Location loc) + : base (types, c, loc) { } public override bool IsLiteral { get { return true; } } - } - public class CharLiteral : CharConstant { - public CharLiteral (char c, Location loc) : base (c, loc) - { - } +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif - public override bool IsLiteral { - get { return true; } + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); } } - public class IntLiteral : IntConstant { - public IntLiteral (int l, Location loc) : base (l, loc) + public class IntLiteral : IntConstant, ILiteralConstant + { + public IntLiteral (BuiltinTypes types, int l, Location loc) + : base (types, l, loc) { } - public override Constant ConvertImplicitly (ResolveContext rc, TypeSpec type) + public override Constant ConvertImplicitly (TypeSpec type) { // // The 0 literal can be converted to an enum value // - if (Value == 0 && TypeManager.IsEnumType (type)) { - Constant c = ConvertImplicitly (rc, EnumSpec.GetUnderlyingType (type)); + if (Value == 0 && type.IsEnum) { + Constant c = ConvertImplicitly (EnumSpec.GetUnderlyingType (type)); if (c == null) return null; - return new EnumConstant (c, type).Resolve (rc); + return new EnumConstant (c, type); } - return base.ConvertImplicitly (rc, type); + return base.ConvertImplicitly (type); } public override bool IsLiteral { get { return true; } } + +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif + + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); + } } - public class UIntLiteral : UIntConstant { - public UIntLiteral (uint l, Location loc) : base (l, loc) + public class UIntLiteral : UIntConstant, ILiteralConstant + { + public UIntLiteral (BuiltinTypes types, uint l, Location loc) + : base (types, l, loc) { } public override bool IsLiteral { get { return true; } } + +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif + + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); + } } - - public class LongLiteral : LongConstant { - public LongLiteral (long l, Location loc) : base (l, loc) + + public class LongLiteral : LongConstant, ILiteralConstant + { + public LongLiteral (BuiltinTypes types, long l, Location loc) + : base (types, l, loc) { } public override bool IsLiteral { get { return true; } } + +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif + + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); + } } - public class ULongLiteral : ULongConstant { - public ULongLiteral (ulong l, Location loc) : base (l, loc) + public class ULongLiteral : ULongConstant, ILiteralConstant + { + public ULongLiteral (BuiltinTypes types, ulong l, Location loc) + : base (types, l, loc) { } public override bool IsLiteral { get { return true; } } + +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif + + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); + } } - - public class FloatLiteral : FloatConstant { - - public FloatLiteral (float f, Location loc) : base (f, loc) + + public class FloatLiteral : FloatConstant, ILiteralConstant + { + public FloatLiteral (BuiltinTypes types, float f, Location loc) + : base (types, f, loc) { } @@ -193,26 +236,36 @@ namespace Mono.CSharp { get { return true; } } +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif + + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); + } } - public class DoubleLiteral : DoubleConstant { - public DoubleLiteral (double d, Location loc) : base (d, loc) + public class DoubleLiteral : DoubleConstant, ILiteralConstant + { + public DoubleLiteral (BuiltinTypes types, double d, Location loc) + : base (types, d, loc) { } - 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 (target == TypeManager.float_type) { + if (target.BuiltinType == BuiltinTypeSpec.Type.Float) { Error_664 (ec, loc, "float", "f"); return; } - if (target == TypeManager.decimal_type) { + if (target.BuiltinType == BuiltinTypeSpec.Type.Decimal) { Error_664 (ec, loc, "decimal", "m"); return; } - base.Error_ValueCannotBeConverted (ec, loc, target, expl); + base.Error_ValueCannotBeConverted (ec, target, expl); } static void Error_664 (ResolveContext ec, Location loc, string type, string suffix) @@ -226,20 +279,41 @@ namespace Mono.CSharp { get { return true; } } +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif + + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); + } } - public class DecimalLiteral : DecimalConstant { - public DecimalLiteral (decimal d, Location loc) : base (d, loc) + public class DecimalLiteral : DecimalConstant, ILiteralConstant + { + public DecimalLiteral (BuiltinTypes types, decimal d, Location loc) + : base (types, d, loc) { } public override bool IsLiteral { get { return true; } } + +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif + + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); + } } - public class StringLiteral : StringConstant { - public StringLiteral (string s, Location loc) : base (s, loc) + public class StringLiteral : StringConstant, ILiteralConstant + { + public StringLiteral (BuiltinTypes types, string s, Location loc) + : base (types, s, loc) { } @@ -247,5 +321,13 @@ namespace Mono.CSharp { get { return true; } } +#if FULL_AST + public char[] ParsedValue { get; set; } +#endif + + public override object Accept (StructuralVisitor visitor) + { + return visitor.Visit (this); + } } }