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!");
39 eclass = ExprClass.Value;
42 override public string AsString ()
47 public override object GetValue ()
52 public override Expression DoResolve (EmitContext ec)
54 type = TypeManager.object_type;
58 public override void Emit (EmitContext ec)
60 ec.ig.Emit (OpCodes.Ldnull);
64 public class BoolLiteral : BoolConstant {
65 public BoolLiteral (bool val) : base (val)
69 public override Expression DoResolve (EmitContext ec)
71 type = TypeManager.bool_type;
76 public class CharLiteral : CharConstant {
77 public CharLiteral (char c) : base (c)
81 public override Expression DoResolve (EmitContext ec)
83 type = TypeManager.char_type;
88 public class IntLiteral : IntConstant {
89 public IntLiteral (int l) : base (l)
93 public override Expression DoResolve (EmitContext ec)
95 type = TypeManager.int32_type;
100 public class UIntLiteral : UIntConstant {
101 public UIntLiteral (uint l) : base (l)
105 public override Expression DoResolve (EmitContext ec)
107 type = TypeManager.uint32_type;
112 public class LongLiteral : LongConstant {
113 public LongLiteral (long l) : base (l)
117 public override Expression DoResolve (EmitContext ec)
119 type = TypeManager.int64_type;
125 public class ULongLiteral : ULongConstant {
126 public ULongLiteral (ulong l) : base (l)
130 public override Expression DoResolve (EmitContext ec)
132 type = TypeManager.uint64_type;
137 public class FloatLiteral : FloatConstant {
139 public FloatLiteral (float f) : base (f)
143 public override Expression DoResolve (EmitContext ec)
145 type = TypeManager.float_type;
150 public class DoubleLiteral : DoubleConstant {
151 public DoubleLiteral (double d) : base (d)
155 public override Expression DoResolve (EmitContext ec)
157 type = TypeManager.double_type;
163 public class DecimalLiteral : DecimalConstant {
164 public DecimalLiteral (decimal d) : base (d)
168 public override Expression DoResolve (EmitContext ec)
170 type = TypeManager.decimal_type;
175 public class StringLiteral : StringConstant {
176 public StringLiteral (string s) : base (s)
180 public override Expression DoResolve (EmitContext ec)
182 type = TypeManager.string_type;