2 // literal.cs: Literal representation for the IL tree.
5 // Miguel de Icaza (miguel@ximian.com)
7 // (C) 2001 Ximian, Inc.
10 // Notice that during parsing we create objects of type Literal, but the
11 // types are not loaded (thats why the Resolve method has to assign the
12 // type at that point).
14 // Literals differ from the constants in that we know we encountered them
15 // as a literal in the source code (and some extra rules apply there) and
16 // they have to be resolved (since during parsing we have not loaded the
17 // types yet) while constants are created only after types have been loaded
18 // and are fully resolved when born.
22 using System.Reflection;
23 using System.Reflection.Emit;
25 namespace Mono.CSharp {
27 public class NullLiteral : Constant {
28 public static readonly NullLiteral Null;
32 Null = new NullLiteral ();
38 throw new Exception ("More than one null has been created!");
41 override public string AsString ()
46 public override object GetValue ()
51 public override Expression DoResolve (EmitContext ec)
53 type = TypeManager.object_type;
57 public override void Emit (EmitContext ec)
59 ec.ig.Emit (OpCodes.Ldnull);
63 public class BoolLiteral : BoolConstant {
64 public BoolLiteral (bool val) : base (val)
68 public override Expression DoResolve (EmitContext ec)
70 type = TypeManager.bool_type;
75 public class CharLiteral : CharConstant {
76 public CharLiteral (char c) : base (c)
80 public override Expression DoResolve (EmitContext ec)
82 type = TypeManager.char_type;
87 public class IntLiteral : IntConstant {
88 public IntLiteral (int l) : base (l)
92 public override Expression DoResolve (EmitContext ec)
94 type = TypeManager.int32_type;
99 public class UIntLiteral : UIntConstant {
100 public UIntLiteral (uint l) : base (l)
104 public override Expression DoResolve (EmitContext ec)
106 type = TypeManager.uint32_type;
111 public class LongLiteral : LongConstant {
112 public LongLiteral (long l) : base (l)
116 public override Expression DoResolve (EmitContext ec)
118 type = TypeManager.int64_type;
124 public class ULongLiteral : ULongConstant {
125 public ULongLiteral (ulong l) : base (l)
129 public override Expression DoResolve (EmitContext ec)
131 type = TypeManager.uint64_type;
136 public class FloatLiteral : FloatConstant {
138 public FloatLiteral (float f) : base (f)
142 public override Expression DoResolve (EmitContext ec)
144 type = TypeManager.float_type;
149 public class DoubleLiteral : DoubleConstant {
150 public DoubleLiteral (double d) : base (d)
154 public override Expression DoResolve (EmitContext ec)
156 type = TypeManager.double_type;
162 public class DecimalLiteral : DecimalConstant {
163 public DecimalLiteral (decimal d) : base (d)
167 public override Expression DoResolve (EmitContext ec)
169 type = TypeManager.decimal_type;
173 public override void Emit (EmitContext ec)
175 throw new Exception ("Implement me");
179 public class StringLiteral : StringConstant {
180 public StringLiteral (string s) : base (s)
184 public override Expression DoResolve (EmitContext ec)
186 type = TypeManager.string_type;