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 ();
37 eclass = ExprClass.Value;
40 override public string AsString ()
45 public override object GetValue ()
50 public override Expression DoResolve (EmitContext ec)
52 type = TypeManager.object_type;
56 public override void Emit (EmitContext ec)
58 ec.ig.Emit (OpCodes.Ldnull);
61 public override bool IsZeroInteger {
67 // A null literal in a pointer context
69 public class NullPointer : NullLiteral {
70 public new static readonly NullLiteral Null;
74 Null = new NullPointer ();
77 public override void Emit (EmitContext ec)
79 ILGenerator ig = ec.ig;
81 ig.Emit (OpCodes.Ldc_I4_0);
82 ig.Emit (OpCodes.Conv_U);
86 public class BoolLiteral : BoolConstant {
87 public BoolLiteral (bool val) : base (val)
91 public override Expression DoResolve (EmitContext ec)
93 type = TypeManager.bool_type;
98 public class CharLiteral : CharConstant {
99 public CharLiteral (char c) : base (c)
103 public override Expression DoResolve (EmitContext ec)
105 type = TypeManager.char_type;
110 public class IntLiteral : IntConstant {
111 public static IntLiteral One, Zero;
115 Zero = new IntLiteral (0);
116 One = new IntLiteral (1);
119 public IntLiteral (int l) : base (l)
123 public override Expression DoResolve (EmitContext ec)
125 type = TypeManager.int32_type;
130 public class UIntLiteral : UIntConstant {
131 public UIntLiteral (uint l) : base (l)
135 public override Expression DoResolve (EmitContext ec)
137 type = TypeManager.uint32_type;
142 public class LongLiteral : LongConstant {
143 public LongLiteral (long l) : base (l)
147 public override Expression DoResolve (EmitContext ec)
149 type = TypeManager.int64_type;
155 public class ULongLiteral : ULongConstant {
156 public ULongLiteral (ulong l) : base (l)
160 public override Expression DoResolve (EmitContext ec)
162 type = TypeManager.uint64_type;
167 public class FloatLiteral : FloatConstant {
169 public FloatLiteral (float f) : base (f)
173 public override Expression DoResolve (EmitContext ec)
175 type = TypeManager.float_type;
180 public class DoubleLiteral : DoubleConstant {
181 public DoubleLiteral (double d) : base (d)
185 public override Expression DoResolve (EmitContext ec)
187 type = TypeManager.double_type;
193 public class DecimalLiteral : DecimalConstant {
194 public DecimalLiteral (decimal d) : base (d)
198 public override Expression DoResolve (EmitContext ec)
200 type = TypeManager.decimal_type;
205 public class StringLiteral : StringConstant {
206 public StringLiteral (string s) : base (s)
210 public override Expression DoResolve (EmitContext ec)
212 type = TypeManager.string_type;