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