**** Merged from MCS ****
[mono-project.git] / mcs / mbas / literal.cs
blob2aec7d3588df966f95fce90f61e2c0fdaf1cce1e
1 //
2 // literal.cs: Literal representation for the IL tree.
3 //
4 // Author:
5 // Miguel de Icaza (miguel@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.
8 //
9 //
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.
21 using System;
22 using System.Reflection;
23 using System.Reflection.Emit;
25 namespace Mono.MonoBASIC {
27 public class NullLiteral : Constant {
28 public static readonly NullLiteral Null;
30 static NullLiteral ()
32 Null = new NullLiteral ();
35 public NullLiteral ()
37 if (Null != null)
38 throw new Exception ("More than one null has been created!");
39 eclass = ExprClass.Value;
42 override public string AsString ()
44 return "null";
47 public override object GetValue ()
49 return null;
52 public override Expression DoResolve (EmitContext ec)
54 type = TypeManager.object_type;
55 return this;
58 public override void Emit (EmitContext ec)
60 ec.ig.Emit (OpCodes.Ldnull);
64 public class BoolLiteral : BoolConstant {
65 public BoolLiteral (bool val) : base (val)
69 public override Expression DoResolve (EmitContext ec)
71 type = TypeManager.bool_type;
72 return this;
76 public class CharLiteral : CharConstant {
77 public CharLiteral (char c) : base (c)
81 public override Expression DoResolve (EmitContext ec)
83 type = TypeManager.char_type;
84 return this;
88 public class IntLiteral : IntConstant {
89 public IntLiteral (int l) : base (l)
93 public override Expression DoResolve (EmitContext ec)
95 type = TypeManager.int32_type;
96 return this;
100 public class ShortLiteral : ShortConstant {
101 public ShortLiteral (short l) : base (l)
105 public override Expression DoResolve (EmitContext ec)
107 type = TypeManager.short_type;
108 return this;
112 public class UIntLiteral : UIntConstant {
113 public UIntLiteral (uint l) : base (l)
117 public override Expression DoResolve (EmitContext ec)
119 type = TypeManager.uint32_type;
120 return this;
124 public class LongLiteral : LongConstant {
125 public LongLiteral (long l) : base (l)
129 public override Expression DoResolve (EmitContext ec)
131 type = TypeManager.int64_type;
133 return this;
137 public class ULongLiteral : ULongConstant {
138 public ULongLiteral (ulong l) : base (l)
142 public override Expression DoResolve (EmitContext ec)
144 type = TypeManager.uint64_type;
145 return this;
149 public class FloatLiteral : FloatConstant {
151 public FloatLiteral (float f) : base (f)
155 public override Expression DoResolve (EmitContext ec)
157 type = TypeManager.float_type;
158 return this;
162 public class DoubleLiteral : DoubleConstant {
163 public DoubleLiteral (double d) : base (d)
167 public override Expression DoResolve (EmitContext ec)
169 type = TypeManager.double_type;
171 return this;
175 public class DecimalLiteral : DecimalConstant {
176 public DecimalLiteral (decimal d) : base (d)
180 public override Expression DoResolve (EmitContext ec)
182 type = TypeManager.decimal_type;
183 return this;
187 public class StringLiteral : StringConstant {
188 public StringLiteral (string s) : base (s)
192 public override Expression DoResolve (EmitContext ec)
194 type = TypeManager.string_type;
196 return this;
200 public class DateLiteral : DateConstant {
201 public DateLiteral (DateTime s) : base (s)
205 public override Expression DoResolve (EmitContext ec)
207 type = TypeManager.date_type;
209 return this;