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 IsNegative {
79 public override bool IsZeroInteger {
85 // A null literal in a pointer context
87 public class NullPointer : NullLiteral {
88 public new static readonly NullLiteral Null;
92 Null = new NullPointer ();
95 private NullPointer ()
97 type = TypeManager.object_type;
100 public override void Emit (EmitContext ec)
102 ILGenerator ig = ec.ig;
104 ig.Emit (OpCodes.Ldc_I4_0);
105 ig.Emit (OpCodes.Conv_U);
109 public class BoolLiteral : BoolConstant {
110 public BoolLiteral (bool val) : base (val)
114 public override Expression DoResolve (EmitContext ec)
116 type = TypeManager.bool_type;
121 public class CharLiteral : CharConstant {
122 public CharLiteral (char c) : base (c)
126 public override Expression DoResolve (EmitContext ec)
128 type = TypeManager.char_type;
133 public class IntLiteral : IntConstant {
134 public static IntLiteral One, Zero;
138 Zero = new IntLiteral (0);
139 One = new IntLiteral (1);
142 public IntLiteral (int l) : base (l)
146 public override Expression DoResolve (EmitContext ec)
148 type = TypeManager.int32_type;
153 public class UIntLiteral : UIntConstant {
154 public UIntLiteral (uint l) : base (l)
158 public override Expression DoResolve (EmitContext ec)
160 type = TypeManager.uint32_type;
165 public class LongLiteral : LongConstant {
166 public LongLiteral (long l) : base (l)
170 public override Expression DoResolve (EmitContext ec)
172 type = TypeManager.int64_type;
178 public class ULongLiteral : ULongConstant {
179 public ULongLiteral (ulong l) : base (l)
183 public override Expression DoResolve (EmitContext ec)
185 type = TypeManager.uint64_type;
190 public class FloatLiteral : FloatConstant {
192 public FloatLiteral (float f) : base (f)
196 public override Expression DoResolve (EmitContext ec)
198 type = TypeManager.float_type;
203 public class DoubleLiteral : DoubleConstant {
204 public DoubleLiteral (double d) : base (d)
208 public override Expression DoResolve (EmitContext ec)
210 type = TypeManager.double_type;
216 public class DecimalLiteral : DecimalConstant {
217 public DecimalLiteral (decimal d) : base (d)
221 public override Expression DoResolve (EmitContext ec)
223 type = TypeManager.decimal_type;
228 public class StringLiteral : StringConstant {
229 public StringLiteral (string s) : base (s)
233 public override Expression DoResolve (EmitContext ec)
235 type = TypeManager.string_type;