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 private NullPointer ()
79 type = TypeManager.object_type;
82 public override void Emit (EmitContext ec)
84 ILGenerator ig = ec.ig;
86 ig.Emit (OpCodes.Ldc_I4_0);
87 ig.Emit (OpCodes.Conv_U);
91 public class BoolLiteral : BoolConstant {
92 public BoolLiteral (bool val) : base (val)
96 public override Expression DoResolve (EmitContext ec)
98 type = TypeManager.bool_type;
103 public class CharLiteral : CharConstant {
104 public CharLiteral (char c) : base (c)
108 public override Expression DoResolve (EmitContext ec)
110 type = TypeManager.char_type;
115 public class IntLiteral : IntConstant {
116 public static IntLiteral One, Zero;
120 Zero = new IntLiteral (0);
121 One = new IntLiteral (1);
124 public IntLiteral (int l) : base (l)
128 public override Expression DoResolve (EmitContext ec)
130 type = TypeManager.int32_type;
135 public class UIntLiteral : UIntConstant {
136 public UIntLiteral (uint l) : base (l)
140 public override Expression DoResolve (EmitContext ec)
142 type = TypeManager.uint32_type;
147 public class LongLiteral : LongConstant {
148 public LongLiteral (long l) : base (l)
152 public override Expression DoResolve (EmitContext ec)
154 type = TypeManager.int64_type;
160 public class ULongLiteral : ULongConstant {
161 public ULongLiteral (ulong l) : base (l)
165 public override Expression DoResolve (EmitContext ec)
167 type = TypeManager.uint64_type;
172 public class FloatLiteral : FloatConstant {
174 public FloatLiteral (float f) : base (f)
178 public override Expression DoResolve (EmitContext ec)
180 type = TypeManager.float_type;
185 public class DoubleLiteral : DoubleConstant {
186 public DoubleLiteral (double d) : base (d)
190 public override Expression DoResolve (EmitContext ec)
192 type = TypeManager.double_type;
198 public class DecimalLiteral : DecimalConstant {
199 public DecimalLiteral (decimal d) : base (d)
203 public override Expression DoResolve (EmitContext ec)
205 type = TypeManager.decimal_type;
210 public class StringLiteral : StringConstant {
211 public StringLiteral (string s) : base (s)
215 public override Expression DoResolve (EmitContext ec)
217 type = TypeManager.string_type;