This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mcs / mbas / literal.cs
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).
13 //
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.
19 //
20
21 using System;
22 using System.Reflection;
23 using System.Reflection.Emit;
24
25 namespace Mono.MonoBASIC {
26
27         public class NullLiteral : Constant {
28                 public static readonly NullLiteral Null;
29                 
30                 static NullLiteral ()
31                 {
32                         Null = new NullLiteral ();
33                 }
34                         
35                 public NullLiteral ()
36                 {
37                         if (Null != null)
38                                 throw new Exception ("More than one null has been created!");
39                         eclass = ExprClass.Value;
40                 }
41                 
42                 override public string AsString ()
43                 {
44                         return "null";
45                 }
46
47                 public override object GetValue ()
48                 {
49                         return null;
50                 }
51
52                 public override Expression DoResolve (EmitContext ec)
53                 {
54                         type = TypeManager.object_type;
55                         return this;
56                 }
57
58                 public override void Emit (EmitContext ec)
59                 {
60                         ec.ig.Emit (OpCodes.Ldnull);
61                 }
62         }
63
64         public class BoolLiteral : BoolConstant {
65                 public BoolLiteral (bool val) : base (val)
66                 {
67                 }
68
69                 public override Expression DoResolve (EmitContext ec)
70                 {
71                         type = TypeManager.bool_type;
72                         return this;
73                 }
74         }
75
76         public class CharLiteral : CharConstant {
77                 public CharLiteral (char c) : base (c)
78                 {
79                 }
80
81                 public override Expression DoResolve (EmitContext ec)
82                 {
83                         type = TypeManager.char_type;
84                         return this;
85                 }
86         }
87
88         public class IntLiteral : IntConstant {
89                 public IntLiteral (int l) : base (l)
90                 {
91                 }
92
93                 public override Expression DoResolve (EmitContext ec)
94                 {
95                         type = TypeManager.int32_type;
96                         return this;
97                 }
98         }
99
100         public class ShortLiteral : ShortConstant {
101                 public ShortLiteral (short l) : base (l)
102                 {
103                 }
104
105                 public override Expression DoResolve (EmitContext ec)
106                 {
107                         type = TypeManager.short_type;
108                         return this;
109                 }
110         }
111
112         public class UIntLiteral : UIntConstant {
113                 public UIntLiteral (uint l) : base (l)
114                 {
115                 }
116
117                 public override Expression DoResolve (EmitContext ec)
118                 {
119                         type = TypeManager.uint32_type;
120                         return this;
121                 }
122         }
123         
124         public class LongLiteral : LongConstant {
125                 public LongLiteral (long l) : base (l)
126                 {
127                 }
128
129                 public override Expression DoResolve (EmitContext ec)
130                 {
131                         type = TypeManager.int64_type;
132
133                         return this;
134                 }
135         }
136
137         public class ULongLiteral : ULongConstant {
138                 public ULongLiteral (ulong l) : base (l)
139                 {
140                 }
141
142                 public override Expression DoResolve (EmitContext ec)
143                 {
144                         type = TypeManager.uint64_type;
145                         return this;
146                 }
147         }
148         
149         public class FloatLiteral : FloatConstant {
150                 
151                 public FloatLiteral (float f) : base (f)
152                 {
153                 }
154
155                 public override Expression DoResolve (EmitContext ec)
156                 {
157                         type = TypeManager.float_type;
158                         return this;
159                 }
160         }
161
162         public class DoubleLiteral : DoubleConstant {
163                 public DoubleLiteral (double d) : base (d)
164                 {
165                 }
166
167                 public override Expression DoResolve (EmitContext ec)
168                 {
169                         type = TypeManager.double_type;
170
171                         return this;
172                 }
173         }
174
175         public class DecimalLiteral : DecimalConstant {
176                 public DecimalLiteral (decimal d) : base (d)
177                 {
178                 }
179
180                 public override Expression DoResolve (EmitContext ec)
181                 {
182                         type = TypeManager.decimal_type;
183                         return this;
184                 }
185         }
186
187         public class StringLiteral : StringConstant {
188                 public StringLiteral (string s) : base (s)
189                 {
190                 }
191
192                 public override Expression DoResolve (EmitContext ec)
193                 {
194                         type = TypeManager.string_type;
195
196                         return this;
197                 }
198         }
199         
200         public class DateLiteral : DateConstant {
201                 public DateLiteral (DateTime s) : base (s)
202                 {
203                 }
204
205                 public override Expression DoResolve (EmitContext ec)
206                 {
207                         type = TypeManager.date_type;
208
209                         return this;
210                 }
211         }
212 }