* CheckBox.cs: Do not change the status of a checkbox when there
[mono.git] / mcs / mcs / 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.CSharp {
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                         eclass = ExprClass.Value;
38                 }
39                 
40                 override public string AsString ()
41                 {
42                         return "null";
43                 }
44
45                 public override object GetValue ()
46                 {
47                         return null;
48                 }
49
50                 public override Expression DoResolve (EmitContext ec)
51                 {
52                         type = TypeManager.object_type;
53                         return this;
54                 }
55
56                 public override void Emit (EmitContext ec)
57                 {
58                         ec.ig.Emit (OpCodes.Ldnull);
59                 }
60         }
61
62         //
63         // A null literal in a pointer context
64         //
65         public class NullPointer : NullLiteral {
66                 public new static readonly NullLiteral Null;
67
68                 static NullPointer ()
69                 {
70                         Null = new NullPointer ();
71                 }
72                 
73                 public override void Emit (EmitContext ec)
74                 {
75                         ILGenerator ig = ec.ig;
76                                 
77                         ig.Emit (OpCodes.Ldc_I4_0);
78                         ig.Emit (OpCodes.Conv_U);
79                 }
80         }
81
82         public class BoolLiteral : BoolConstant {
83                 public BoolLiteral (bool val) : base (val)
84                 {
85                 }
86
87                 public override Expression DoResolve (EmitContext ec)
88                 {
89                         type = TypeManager.bool_type;
90                         return this;
91                 }
92         }
93
94         public class CharLiteral : CharConstant {
95                 public CharLiteral (char c) : base (c)
96                 {
97                 }
98
99                 public override Expression DoResolve (EmitContext ec)
100                 {
101                         type = TypeManager.char_type;
102                         return this;
103                 }
104         }
105
106         public class IntLiteral : IntConstant {
107                 public static IntLiteral One, Zero;
108                 
109                 static IntLiteral ()
110                 {
111                         Zero = new IntLiteral (0);
112                         One = new IntLiteral (1);
113                 }
114                 
115                 public IntLiteral (int l) : base (l)
116                 {
117                 }
118
119                 public override Expression DoResolve (EmitContext ec)
120                 {
121                         type = TypeManager.int32_type;
122                         return this;
123                 }
124         }
125
126         public class UIntLiteral : UIntConstant {
127                 public UIntLiteral (uint l) : base (l)
128                 {
129                 }
130
131                 public override Expression DoResolve (EmitContext ec)
132                 {
133                         type = TypeManager.uint32_type;
134                         return this;
135                 }
136         }
137         
138         public class LongLiteral : LongConstant {
139                 public LongLiteral (long l) : base (l)
140                 {
141                 }
142
143                 public override Expression DoResolve (EmitContext ec)
144                 {
145                         type = TypeManager.int64_type;
146
147                         return this;
148                 }
149         }
150
151         public class ULongLiteral : ULongConstant {
152                 public ULongLiteral (ulong l) : base (l)
153                 {
154                 }
155
156                 public override Expression DoResolve (EmitContext ec)
157                 {
158                         type = TypeManager.uint64_type;
159                         return this;
160                 }
161         }
162         
163         public class FloatLiteral : FloatConstant {
164                 
165                 public FloatLiteral (float f) : base (f)
166                 {
167                 }
168
169                 public override Expression DoResolve (EmitContext ec)
170                 {
171                         type = TypeManager.float_type;
172                         return this;
173                 }
174         }
175
176         public class DoubleLiteral : DoubleConstant {
177                 public DoubleLiteral (double d) : base (d)
178                 {
179                 }
180
181                 public override Expression DoResolve (EmitContext ec)
182                 {
183                         type = TypeManager.double_type;
184
185                         return this;
186                 }
187         }
188
189         public class DecimalLiteral : DecimalConstant {
190                 public DecimalLiteral (decimal d) : base (d)
191                 {
192                 }
193
194                 public override Expression DoResolve (EmitContext ec)
195                 {
196                         type = TypeManager.decimal_type;
197                         return this;
198                 }
199         }
200
201         public class StringLiteral : StringConstant {
202                 public StringLiteral (string s) : base (s)
203                 {
204                 }
205
206                 public override Expression DoResolve (EmitContext ec)
207                 {
208                         type = TypeManager.string_type;
209
210                         return this;
211                 }
212         }
213 }