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.MonoBASIC {
28 // The NullType just exists to compare type equality, and for
29 // expressions that might have the `null type'
31 public class NullType {
35 // The null Literal constant
38 public class NullLiteral : Constant {
39 public static readonly NullLiteral Null;
43 Null = new NullLiteral ();
49 throw new Exception ("More than one null has been created!");
50 eclass = ExprClass.Value;
53 override public string AsString ()
58 public override object GetValue ()
63 public override Expression DoResolve (EmitContext ec)
65 type = TypeManager.object_type;
69 public override void Emit (EmitContext ec)
71 ec.ig.Emit (OpCodes.Ldnull);
75 public class BoolLiteral : BoolConstant {
76 public BoolLiteral (bool val) : base (val)
80 public override Expression DoResolve (EmitContext ec)
82 type = TypeManager.bool_type;
87 public class CharLiteral : CharConstant {
88 public CharLiteral (char c) : base (c)
92 public override Expression DoResolve (EmitContext ec)
94 type = TypeManager.char_type;
99 public class IntLiteral : IntConstant {
100 public IntLiteral (int l) : base (l)
104 public override Expression DoResolve (EmitContext ec)
106 type = TypeManager.int32_type;
111 public class ShortLiteral : ShortConstant {
112 public ShortLiteral (short l) : base (l)
116 public override Expression DoResolve (EmitContext ec)
118 type = TypeManager.short_type;
123 public class UIntLiteral : UIntConstant {
124 public UIntLiteral (uint l) : base (l)
128 public override Expression DoResolve (EmitContext ec)
130 type = TypeManager.uint32_type;
135 public class LongLiteral : LongConstant {
136 public LongLiteral (long l) : base (l)
140 public override Expression DoResolve (EmitContext ec)
142 type = TypeManager.int64_type;
148 public class ULongLiteral : ULongConstant {
149 public ULongLiteral (ulong l) : base (l)
153 public override Expression DoResolve (EmitContext ec)
155 type = TypeManager.uint64_type;
160 public class FloatLiteral : FloatConstant {
162 public FloatLiteral (float f) : base (f)
166 public override Expression DoResolve (EmitContext ec)
168 type = TypeManager.float_type;
173 public class DoubleLiteral : DoubleConstant {
174 public DoubleLiteral (double d) : base (d)
178 public override Expression DoResolve (EmitContext ec)
180 type = TypeManager.double_type;
186 public class DecimalLiteral : DecimalConstant {
187 public DecimalLiteral (decimal d) : base (d)
191 public override Expression DoResolve (EmitContext ec)
193 type = TypeManager.decimal_type;
198 public class StringLiteral : StringConstant {
199 public StringLiteral (string s) : base (s)
203 public override Expression DoResolve (EmitContext ec)
205 type = TypeManager.string_type;
211 public class DateLiteral : DateConstant {
212 public DateLiteral (DateTime s) : base (s)
216 public override Expression DoResolve (EmitContext ec)
218 type = TypeManager.date_type;