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;
26 // I put System.Null just so we do not have to special case it on
27 // TypeManager.CSharpName
31 // Represents the Null Type, just used as a placeholder for the type in NullLiteral
37 namespace Mono.CSharp {
39 public class NullLiteral : Constant {
40 public static readonly NullLiteral Null;
44 Null = new NullLiteral ();
49 eclass = ExprClass.Value;
52 override public string AsString ()
57 public override object GetValue ()
62 public override Expression DoResolve (EmitContext ec)
64 type = typeof (System.Null);
68 public override void Emit (EmitContext ec)
70 ec.ig.Emit (OpCodes.Ldnull);
73 public override bool IsZeroInteger {
79 // A null literal in a pointer context
81 public class NullPointer : NullLiteral {
82 public new static readonly NullLiteral Null;
86 Null = new NullPointer ();
89 private NullPointer ()
91 type = TypeManager.object_type;
94 public override void Emit (EmitContext ec)
96 ILGenerator ig = ec.ig;
98 ig.Emit (OpCodes.Ldc_I4_0);
99 ig.Emit (OpCodes.Conv_U);
103 public class BoolLiteral : BoolConstant {
104 public BoolLiteral (bool val) : base (val)
108 public override Expression DoResolve (EmitContext ec)
110 type = TypeManager.bool_type;
115 public class CharLiteral : CharConstant {
116 public CharLiteral (char c) : base (c)
120 public override Expression DoResolve (EmitContext ec)
122 type = TypeManager.char_type;
127 public class IntLiteral : IntConstant {
128 public static IntLiteral One, Zero;
132 Zero = new IntLiteral (0);
133 One = new IntLiteral (1);
136 public IntLiteral (int l) : base (l)
140 public override Expression DoResolve (EmitContext ec)
142 type = TypeManager.int32_type;
147 public class UIntLiteral : UIntConstant {
148 public UIntLiteral (uint l) : base (l)
152 public override Expression DoResolve (EmitContext ec)
154 type = TypeManager.uint32_type;
159 public class LongLiteral : LongConstant {
160 public LongLiteral (long l) : base (l)
164 public override Expression DoResolve (EmitContext ec)
166 type = TypeManager.int64_type;
172 public class ULongLiteral : ULongConstant {
173 public ULongLiteral (ulong l) : base (l)
177 public override Expression DoResolve (EmitContext ec)
179 type = TypeManager.uint64_type;
184 public class FloatLiteral : FloatConstant {
186 public FloatLiteral (float f) : base (f)
190 public override Expression DoResolve (EmitContext ec)
192 type = TypeManager.float_type;
197 public class DoubleLiteral : DoubleConstant {
198 public DoubleLiteral (double d) : base (d)
202 public override Expression DoResolve (EmitContext ec)
204 type = TypeManager.double_type;
210 public class DecimalLiteral : DecimalConstant {
211 public DecimalLiteral (decimal d) : base (d)
215 public override Expression DoResolve (EmitContext ec)
217 type = TypeManager.decimal_type;
222 public class StringLiteral : StringConstant {
223 public StringLiteral (string s) : base (s)
227 public override Expression DoResolve (EmitContext ec)
229 type = TypeManager.string_type;