Mercurial > projects > ddmd
annotate dmd/TypeBasic.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
rev | line source |
---|---|
0 | 1 module dmd.TypeBasic; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Type; |
5 import dmd.Id; | |
6 import dmd.MOD; | |
7 import dmd.TOK; | |
8 import dmd.Token; | |
9 import dmd.TFLAGS; | |
10 import dmd.TY; | |
11 import dmd.Loc; | |
12 import dmd.Scope; | |
13 import dmd.Expression; | |
14 import dmd.IntegerExp; | |
15 import dmd.Identifier; | |
16 import dmd.OutBuffer; | |
17 import dmd.HdrGenState; | |
18 import dmd.CppMangleState; | |
19 import dmd.MATCH; | |
20 import dmd.RealExp; | |
21 import dmd.ComplexExp; | |
22 import dmd.Util; | |
23 import dmd.Port; | |
24 import dmd.Complex; | |
25 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
26 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
27 |
0 | 28 class TypeBasic : Type |
29 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
31 |
0 | 32 string dstring; |
33 uint flags; | |
34 | |
35 this(TY ty) | |
36 { | |
178 | 37 register(); |
0 | 38 super(ty); |
39 | |
40 enum TFLAGSintegral = 1; | |
41 enum TFLAGSfloating = 2; | |
42 enum TFLAGSunsigned = 4; | |
43 enum TFLAGSreal = 8; | |
44 enum TFLAGSimaginary = 0x10; | |
45 enum TFLAGScomplex = 0x20; | |
46 | |
47 string d; | |
48 | |
49 uint flags = 0; | |
50 switch (ty) | |
51 { | |
52 case TY.Tvoid: d = Token.toChars(TOK.TOKvoid); | |
53 break; | |
54 | |
55 case TY.Tint8: d = Token.toChars(TOK.TOKint8); | |
56 flags |= TFLAGSintegral; | |
57 break; | |
58 | |
59 case TY.Tuns8: d = Token.toChars(TOK.TOKuns8); | |
60 flags |= TFLAGSintegral | TFLAGSunsigned; | |
61 break; | |
62 | |
63 case TY.Tint16: d = Token.toChars(TOK.TOKint16); | |
64 flags |= TFLAGSintegral; | |
65 break; | |
66 | |
67 case TY.Tuns16: d = Token.toChars(TOK.TOKuns16); | |
68 flags |= TFLAGSintegral | TFLAGSunsigned; | |
69 break; | |
70 | |
71 case TY.Tint32: d = Token.toChars(TOK.TOKint32); | |
72 flags |= TFLAGSintegral; | |
73 break; | |
74 | |
75 case TY.Tuns32: d = Token.toChars(TOK.TOKuns32); | |
76 flags |= TFLAGSintegral | TFLAGSunsigned; | |
77 break; | |
78 | |
79 case TY.Tfloat32: d = Token.toChars(TOK.TOKfloat32); | |
80 flags |= TFLAGSfloating | TFLAGSreal; | |
81 break; | |
82 | |
83 case TY.Tint64: d = Token.toChars(TOK.TOKint64); | |
84 flags |= TFLAGSintegral; | |
85 break; | |
86 | |
87 case TY.Tuns64: d = Token.toChars(TOK.TOKuns64); | |
88 flags |= TFLAGSintegral | TFLAGSunsigned; | |
89 break; | |
90 | |
91 case TY.Tfloat64: d = Token.toChars(TOK.TOKfloat64); | |
92 flags |= TFLAGSfloating | TFLAGSreal; | |
93 break; | |
94 | |
95 case TY.Tfloat80: d = Token.toChars(TOK.TOKfloat80); | |
96 flags |= TFLAGSfloating | TFLAGSreal; | |
97 break; | |
98 | |
99 case TY.Timaginary32: d = Token.toChars(TOK.TOKimaginary32); | |
100 flags |= TFLAGSfloating | TFLAGSimaginary; | |
101 break; | |
102 | |
103 case TY.Timaginary64: d = Token.toChars(TOK.TOKimaginary64); | |
104 flags |= TFLAGSfloating | TFLAGSimaginary; | |
105 break; | |
106 | |
107 case TY.Timaginary80: d = Token.toChars(TOK.TOKimaginary80); | |
108 flags |= TFLAGSfloating | TFLAGSimaginary; | |
109 break; | |
110 | |
111 case TY.Tcomplex32: d = Token.toChars(TOK.TOKcomplex32); | |
112 flags |= TFLAGSfloating | TFLAGScomplex; | |
113 break; | |
114 | |
115 case TY.Tcomplex64: d = Token.toChars(TOK.TOKcomplex64); | |
116 flags |= TFLAGSfloating | TFLAGScomplex; | |
117 break; | |
118 | |
119 case TY.Tcomplex80: d = Token.toChars(TOK.TOKcomplex80); | |
120 flags |= TFLAGSfloating | TFLAGScomplex; | |
121 break; | |
122 | |
123 case TY.Tbool: d = "bool"; | |
124 flags |= TFLAGSintegral | TFLAGSunsigned; | |
125 break; | |
126 | |
127 case TY.Tascii: d = Token.toChars(TOK.TOKchar); | |
128 flags |= TFLAGSintegral | TFLAGSunsigned; | |
129 break; | |
130 | |
131 case TY.Twchar: d = Token.toChars(TOK.TOKwchar); | |
132 flags |= TFLAGSintegral | TFLAGSunsigned; | |
133 break; | |
134 | |
135 case TY.Tdchar: d = Token.toChars(TOK.TOKdchar); | |
136 flags |= TFLAGSintegral | TFLAGSunsigned; | |
137 break; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
138 default: |
0 | 139 } |
140 | |
141 this.dstring = d; | |
142 this.flags = flags; | |
143 merge(); | |
144 } | |
145 | |
72 | 146 override Type syntaxCopy() |
0 | 147 { |
148 // No semantic analysis done on basic types, no need to copy | |
149 return this; | |
150 } | |
151 | |
72 | 152 override ulong size(Loc loc) |
0 | 153 { |
154 uint size; | |
155 | |
156 //printf("TypeBasic.size()\n"); | |
157 switch (ty) | |
158 { | |
159 case TY.Tint8: | |
160 case TY.Tuns8: size = 1; break; | |
161 case TY.Tint16: | |
162 case TY.Tuns16: size = 2; break; | |
163 case TY.Tint32: | |
164 case TY.Tuns32: | |
165 case TY.Tfloat32: | |
166 case TY.Timaginary32: | |
167 size = 4; break; | |
168 case TY.Tint64: | |
169 case TY.Tuns64: | |
170 case TY.Tfloat64: | |
171 case TY.Timaginary64: | |
172 size = 8; break; | |
173 case TY.Tfloat80: | |
174 case TY.Timaginary80: | |
175 size = REALSIZE; break; | |
176 case TY.Tcomplex32: | |
177 size = 8; break; | |
178 case TY.Tcomplex64: | |
179 size = 16; break; | |
180 case TY.Tcomplex80: | |
181 size = REALSIZE * 2; break; | |
182 | |
183 case TY.Tvoid: | |
184 //size = Type.size(); // error message | |
185 size = 1; | |
186 break; | |
187 | |
188 case TY.Tbool: size = 1; break; | |
189 case TY.Tascii: size = 1; break; | |
190 case TY.Twchar: size = 2; break; | |
191 case TY.Tdchar: size = 4; break; | |
192 | |
193 default: | |
194 assert(0); | |
195 } | |
196 | |
197 //printf("TypeBasic.size() = %d\n", size); | |
198 return size; | |
199 } | |
200 | |
72 | 201 override uint alignsize() |
0 | 202 { |
203 uint sz; | |
204 | |
205 switch (ty) | |
206 { | |
207 case TY.Tfloat80: | |
208 case TY.Timaginary80: | |
209 case TY.Tcomplex80: | |
210 sz = REALALIGNSIZE; | |
211 break; | |
212 | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
213 version (POSIX) { ///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS |
0 | 214 case TY.Tint64: |
215 case TY.Tuns64: | |
216 case TY.Tfloat64: | |
217 case TY.Timaginary64: | |
218 case TY.Tcomplex32: | |
219 case TY.Tcomplex64: | |
220 sz = 4; | |
221 break; | |
222 } | |
223 | |
224 default: | |
225 sz = cast(uint)size(Loc(0)); /// | |
226 break; | |
227 } | |
228 | |
229 return sz; | |
230 } | |
231 | |
72 | 232 override Expression getProperty(Loc loc, Identifier ident) |
0 | 233 { |
234 Expression e; | |
235 long ivalue; | |
236 real fvalue; | |
237 | |
238 //printf("TypeBasic.getProperty('%s')\n", ident.toChars()); | |
239 if (ident is Id.max) | |
240 { | |
241 switch (ty) | |
242 { | |
243 case TY.Tint8: ivalue = byte.max; goto Livalue; | |
244 case TY.Tuns8: ivalue = ubyte.max; goto Livalue; | |
245 case TY.Tint16: ivalue = short.max; goto Livalue; | |
246 case TY.Tuns16: ivalue = ushort.max; goto Livalue; | |
247 case TY.Tint32: ivalue = int.max; goto Livalue; | |
248 case TY.Tuns32: ivalue = uint.max; goto Livalue; | |
249 case TY.Tint64: ivalue = long.max; goto Livalue; | |
250 case TY.Tuns64: ivalue = ulong.max; goto Livalue; | |
251 case TY.Tbool: ivalue = bool.max; goto Livalue; | |
252 case TY.Tchar: ivalue = char.max; goto Livalue; | |
253 case TY.Twchar: ivalue = wchar.max; goto Livalue; | |
254 case TY.Tdchar: ivalue = 0x10FFFF; goto Livalue; | |
255 case TY.Tcomplex32: | |
256 case TY.Timaginary32: | |
257 case TY.Tfloat32: fvalue = float.max; goto Lfvalue; | |
258 case TY.Tcomplex64: | |
259 case TY.Timaginary64: | |
260 case TY.Tfloat64: fvalue = double.max;goto Lfvalue; | |
261 case TY.Tcomplex80: | |
262 case TY.Timaginary80: | |
263 case TY.Tfloat80: fvalue = real.max; goto Lfvalue; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
264 default: |
0 | 265 } |
266 } | |
267 else if (ident is Id.min) | |
268 { | |
269 switch (ty) | |
270 { | |
271 case TY.Tint8: ivalue = byte.min; goto Livalue; | |
272 case TY.Tuns8: ivalue = ubyte.min; goto Livalue; | |
273 case TY.Tint16: ivalue = short.min; goto Livalue; | |
274 case TY.Tuns16: ivalue = ushort.min; goto Livalue; | |
275 case TY.Tint32: ivalue = int.min; goto Livalue; | |
276 case TY.Tuns32: ivalue = uint.min; goto Livalue; | |
277 case TY.Tint64: ivalue = long.min; goto Livalue; | |
278 case TY.Tuns64: ivalue = ulong.min; goto Livalue; | |
279 case TY.Tbool: ivalue = bool.min; goto Livalue; | |
280 case TY.Tchar: ivalue = char.min; goto Livalue; | |
281 case TY.Twchar: ivalue = wchar.min; goto Livalue; | |
282 case TY.Tdchar: ivalue = dchar.min; goto Livalue; | |
283 case TY.Tcomplex32: | |
284 case TY.Timaginary32: | |
96 | 285 case Tfloat32: |
286 case Tcomplex64: | |
287 case Timaginary64: | |
288 case Tfloat64: | |
289 case Tcomplex80: | |
290 case Timaginary80: | |
291 case Tfloat80: | |
292 // For backwards compatibility - eventually, deprecate | |
293 goto Lmin_normal; | |
156 | 294 default: |
96 | 295 } |
296 } | |
297 else if (ident == Id.min_normal) | |
298 { | |
299 Lmin_normal: | |
300 switch (ty) | |
301 { | |
302 case Tcomplex32: | |
303 case Timaginary32: | |
0 | 304 case TY.Tfloat32: fvalue = float.min; goto Lfvalue; |
305 case TY.Tcomplex64: | |
306 case TY.Timaginary64: | |
307 case TY.Tfloat64: fvalue = double.min; goto Lfvalue; | |
308 case TY.Tcomplex80: | |
309 case TY.Timaginary80: | |
310 case TY.Tfloat80: fvalue = real.min; goto Lfvalue; | |
134
4251f96733f4
Fix of the hopefully last regression with dmd2.037
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
311 default: |
0 | 312 } |
313 } | |
314 else if (ident is Id.nan) | |
315 { | |
316 switch (ty) | |
317 { | |
318 case TY.Tcomplex32: | |
319 case TY.Tcomplex64: | |
320 case TY.Tcomplex80: | |
321 case TY.Timaginary32: | |
322 case TY.Timaginary64: | |
323 case TY.Timaginary80: | |
324 case TY.Tfloat32: | |
325 case TY.Tfloat64: | |
326 case TY.Tfloat80: | |
327 { | |
328 fvalue = real.nan; | |
329 goto Lfvalue; | |
330 } | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
331 default: |
0 | 332 } |
333 } | |
334 else if (ident is Id.infinity) | |
335 { | |
336 switch (ty) | |
337 { | |
338 case TY.Tcomplex32: | |
339 case TY.Tcomplex64: | |
340 case TY.Tcomplex80: | |
341 case TY.Timaginary32: | |
342 case TY.Timaginary64: | |
343 case TY.Timaginary80: | |
344 case TY.Tfloat32: | |
345 case TY.Tfloat64: | |
346 case TY.Tfloat80: | |
347 fvalue = real.infinity; | |
348 goto Lfvalue; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
349 default: |
0 | 350 } |
351 } | |
352 else if (ident is Id.dig) | |
353 { | |
354 switch (ty) | |
355 { | |
356 case TY.Tcomplex32: | |
357 case TY.Timaginary32: | |
358 case TY.Tfloat32: ivalue = float.dig; goto Lint; | |
359 case TY.Tcomplex64: | |
360 case TY.Timaginary64: | |
361 case TY.Tfloat64: ivalue = double.dig; goto Lint; | |
362 case TY.Tcomplex80: | |
363 case TY.Timaginary80: | |
364 case TY.Tfloat80: ivalue = real.dig; goto Lint; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
365 default: |
0 | 366 } |
367 } | |
368 else if (ident is Id.epsilon) | |
369 { | |
370 switch (ty) | |
371 { | |
372 case TY.Tcomplex32: | |
373 case TY.Timaginary32: | |
374 case TY.Tfloat32: fvalue = float.epsilon; goto Lfvalue; | |
375 case TY.Tcomplex64: | |
376 case TY.Timaginary64: | |
377 case TY.Tfloat64: fvalue = double.epsilon; goto Lfvalue; | |
378 case TY.Tcomplex80: | |
379 case TY.Timaginary80: | |
380 case TY.Tfloat80: fvalue = real.epsilon; goto Lfvalue; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
381 default: |
0 | 382 } |
383 } | |
384 else if (ident is Id.mant_dig) | |
385 { | |
386 switch (ty) | |
387 { | |
388 case TY.Tcomplex32: | |
389 case TY.Timaginary32: | |
390 case TY.Tfloat32: ivalue = float.mant_dig; goto Lint; | |
391 case TY.Tcomplex64: | |
392 case TY.Timaginary64: | |
393 case TY.Tfloat64: ivalue = double.mant_dig; goto Lint; | |
394 case TY.Tcomplex80: | |
395 case TY.Timaginary80: | |
396 case TY.Tfloat80: ivalue = real.mant_dig; goto Lint; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
397 default: |
0 | 398 } |
399 } | |
400 else if (ident is Id.max_10_exp) | |
401 { | |
402 switch (ty) | |
403 { | |
404 case TY.Tcomplex32: | |
405 case TY.Timaginary32: | |
406 case TY.Tfloat32: ivalue = float.max_10_exp; goto Lint; | |
407 case TY.Tcomplex64: | |
408 case TY.Timaginary64: | |
409 case TY.Tfloat64: ivalue = double.max_10_exp; goto Lint; | |
410 case TY.Tcomplex80: | |
411 case TY.Timaginary80: | |
412 case TY.Tfloat80: ivalue = real.max_10_exp; goto Lint; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
413 default: |
0 | 414 } |
415 } | |
416 else if (ident is Id.max_exp) | |
417 { | |
418 switch (ty) | |
419 { | |
420 case TY.Tcomplex32: | |
421 case TY.Timaginary32: | |
422 case TY.Tfloat32: ivalue = float.max_exp; goto Lint; | |
423 case TY.Tcomplex64: | |
424 case TY.Timaginary64: | |
425 case TY.Tfloat64: ivalue = double.max_exp; goto Lint; | |
426 case TY.Tcomplex80: | |
427 case TY.Timaginary80: | |
428 case TY.Tfloat80: ivalue = real.max_exp; goto Lint; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
429 default: |
0 | 430 } |
431 } | |
432 else if (ident is Id.min_10_exp) | |
433 { | |
434 switch (ty) | |
435 { | |
436 case TY.Tcomplex32: | |
437 case TY.Timaginary32: | |
438 case TY.Tfloat32: ivalue = float.min_10_exp; goto Lint; | |
439 case TY.Tcomplex64: | |
440 case TY.Timaginary64: | |
441 case TY.Tfloat64: ivalue = double.min_10_exp; goto Lint; | |
442 case TY.Tcomplex80: | |
443 case TY.Timaginary80: | |
444 case TY.Tfloat80: ivalue = real.min_10_exp; goto Lint; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
445 default: |
0 | 446 } |
447 } | |
448 else if (ident is Id.min_exp) | |
449 { | |
450 switch (ty) | |
451 { | |
452 case TY.Tcomplex32: | |
453 case TY.Timaginary32: | |
454 case TY.Tfloat32: ivalue = float.min_exp; goto Lint; | |
455 case TY.Tcomplex64: | |
456 case TY.Timaginary64: | |
457 case TY.Tfloat64: ivalue = double.min_exp; goto Lint; | |
458 case TY.Tcomplex80: | |
459 case TY.Timaginary80: | |
460 case TY.Tfloat80: ivalue = real.min_exp; goto Lint; | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
156
diff
changeset
|
461 default: |
0 | 462 } |
463 } | |
464 | |
465 Ldefault: | |
466 return Type.getProperty(loc, ident); | |
467 | |
468 Livalue: | |
469 e = new IntegerExp(loc, ivalue, this); | |
470 return e; | |
471 | |
472 Lfvalue: | |
473 if (isreal() || isimaginary()) | |
474 e = new RealExp(loc, fvalue, this); | |
475 else | |
476 { | |
477 Complex!(real) cvalue; | |
478 cvalue.re = fvalue; | |
479 cvalue.im = fvalue; | |
480 | |
481 //for (int i = 0; i < 20; i++) | |
96 | 482 // printf("%02x ", ((unsigned char *)&cvalue)[i]); |
0 | 483 //printf("\n"); |
484 e = new ComplexExp(loc, cvalue, this); | |
485 } | |
486 return e; | |
487 | |
488 Lint: | |
489 e = new IntegerExp(loc, ivalue, Type.tint32); | |
490 return e; | |
491 } | |
492 | |
72 | 493 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 494 { |
495 version (LOGDOTEXP) { | |
496 printf("TypeBasic.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
497 } | |
498 Type t; | |
499 | |
500 if (ident is Id.re) | |
501 { | |
502 switch (ty) | |
503 { | |
504 case TY.Tcomplex32: t = tfloat32; goto L1; | |
505 case TY.Tcomplex64: t = tfloat64; goto L1; | |
506 case TY.Tcomplex80: t = tfloat80; goto L1; | |
507 L1: | |
508 e = e.castTo(sc, t); | |
509 break; | |
510 | |
511 case TY.Tfloat32: | |
512 case TY.Tfloat64: | |
513 case TY.Tfloat80: | |
514 break; | |
515 | |
516 case TY.Timaginary32: t = tfloat32; goto L2; | |
517 case TY.Timaginary64: t = tfloat64; goto L2; | |
518 case TY.Timaginary80: t = tfloat80; goto L2; | |
519 L2: | |
520 e = new RealExp(Loc(0), 0.0, t); | |
521 break; | |
522 | |
523 default: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
524 e = Type.getProperty(e.loc, ident); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
525 break; |
0 | 526 } |
527 } | |
528 else if (ident is Id.im) | |
529 { | |
530 Type t2; | |
531 | |
532 switch (ty) | |
533 { | |
534 case TY.Tcomplex32: t = timaginary32; t2 = tfloat32; goto L3; | |
535 case TY.Tcomplex64: t = timaginary64; t2 = tfloat64; goto L3; | |
536 case TY.Tcomplex80: t = timaginary80; t2 = tfloat80; goto L3; | |
537 L3: | |
538 e = e.castTo(sc, t); | |
539 e.type = t2; | |
540 break; | |
541 | |
542 case TY.Timaginary32: t = tfloat32; goto L4; | |
543 case TY.Timaginary64: t = tfloat64; goto L4; | |
544 case TY.Timaginary80: t = tfloat80; goto L4; | |
545 L4: | |
546 e = e.copy(); | |
547 e.type = t; | |
548 break; | |
549 | |
550 case TY.Tfloat32: | |
551 case TY.Tfloat64: | |
552 case TY.Tfloat80: | |
553 e = new RealExp(Loc(0), 0.0, this); | |
554 break; | |
555 | |
556 default: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
557 e = Type.getProperty(e.loc, ident); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
558 break; |
0 | 559 } |
560 } | |
561 else | |
562 { | |
563 return Type.dotExp(sc, e, ident); | |
564 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
565 e = e.semantic(sc); |
0 | 566 return e; |
567 } | |
568 | |
72 | 569 override string toChars() |
0 | 570 { |
571 return Type.toChars(); | |
572 } | |
573 | |
72 | 574 override void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) |
0 | 575 { |
576 //printf("TypeBasic.toCBuffer2(mod = %d, this.mod = %d)\n", mod, this.mod); | |
577 if (mod != this.mod) | |
578 { | |
579 toCBuffer3(buf, hgs, mod); | |
580 return; | |
581 } | |
582 buf.writestring(dstring); | |
583 } | |
584 | |
585 version (CPP_MANGLE) { | |
586 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
587 { | |
588 assert(false); | |
589 } | |
590 } | |
72 | 591 override bool isintegral() |
0 | 592 { |
593 //printf("TypeBasic.isintegral('%s') x%x\n", toChars(), flags); | |
594 return (flags & TFLAGS.TFLAGSintegral) != 0; | |
595 } | |
596 | |
597 bool isbit() | |
598 { | |
599 assert(false); | |
600 } | |
601 | |
72 | 602 override bool isfloating() |
0 | 603 { |
604 return (flags & TFLAGS.TFLAGSfloating) != 0; | |
605 } | |
606 | |
72 | 607 override bool isreal() |
0 | 608 { |
609 return (flags & TFLAGS.TFLAGSreal) != 0; | |
610 } | |
611 | |
72 | 612 override bool isimaginary() |
0 | 613 { |
614 return (flags & TFLAGS.TFLAGSimaginary) != 0; | |
615 } | |
616 | |
72 | 617 override bool iscomplex() |
0 | 618 { |
619 return (flags & TFLAGS.TFLAGScomplex) != 0; | |
620 } | |
621 | |
72 | 622 override bool isscalar() |
0 | 623 { |
624 return (flags & (TFLAGS.TFLAGSintegral | TFLAGS.TFLAGSfloating)) != 0; | |
625 } | |
626 | |
72 | 627 override bool isunsigned() |
0 | 628 { |
629 return (flags & TFLAGS.TFLAGSunsigned) != 0; | |
630 } | |
631 | |
72 | 632 override MATCH implicitConvTo(Type to) |
0 | 633 { |
634 //printf("TypeBasic.implicitConvTo(%s) from %s\n", to.toChars(), toChars()); | |
635 if (this is to) | |
636 return MATCH.MATCHexact; | |
637 | |
638 version (DMDV2) { | |
639 if (ty is to.ty) | |
640 { | |
641 return (mod == to.mod) ? MATCH.MATCHexact : MATCH.MATCHconst; | |
642 } | |
643 } | |
644 | |
645 if (ty == TY.Tvoid || to.ty == TY.Tvoid) | |
646 return MATCH.MATCHnomatch; | |
647 if (to.ty == TY.Tbool) | |
648 return MATCH.MATCHnomatch; | |
649 if (!to.isTypeBasic()) | |
650 return MATCH.MATCHnomatch; | |
651 | |
652 TypeBasic tob = cast(TypeBasic)to; | |
653 if (flags & TFLAGS.TFLAGSintegral) | |
654 { | |
655 // Disallow implicit conversion of integers to imaginary or complex | |
656 if (tob.flags & (TFLAGS.TFLAGSimaginary | TFLAGS.TFLAGScomplex)) | |
657 return MATCH.MATCHnomatch; | |
658 | |
659 version (DMDV2) { | |
660 // If converting from integral to integral | |
661 if (1 && tob.flags & TFLAGS.TFLAGSintegral) | |
662 { ulong sz = size(Loc(0)); | |
663 ulong tosz = tob.size(Loc(0)); | |
664 | |
665 /* Can't convert to smaller size | |
666 */ | |
667 if (sz > tosz) | |
668 return MATCH.MATCHnomatch; | |
669 | |
670 /* Can't change sign if same size | |
671 */ | |
672 /*if (sz == tosz && (flags ^ tob.flags) & TFLAGSunsigned) | |
673 return MATCH.MATCHnomatch;*/ | |
674 } | |
675 } | |
676 } | |
677 else if (flags & TFLAGS.TFLAGSfloating) | |
678 { | |
679 // Disallow implicit conversion of floating point to integer | |
680 if (tob.flags & TFLAGS.TFLAGSintegral) | |
681 return MATCH.MATCHnomatch; | |
682 | |
683 assert(tob.flags & TFLAGS.TFLAGSfloating); | |
684 | |
685 // Disallow implicit conversion from complex to non-complex | |
686 if (flags & TFLAGS.TFLAGScomplex && !(tob.flags & TFLAGS.TFLAGScomplex)) | |
687 return MATCH.MATCHnomatch; | |
688 | |
689 // Disallow implicit conversion of real or imaginary to complex | |
690 if (flags & (TFLAGS.TFLAGSreal | TFLAGS.TFLAGSimaginary) && | |
691 tob.flags & TFLAGS.TFLAGScomplex) | |
692 return MATCH.MATCHnomatch; | |
693 | |
694 // Disallow implicit conversion to-from real and imaginary | |
695 if ((flags & (TFLAGS.TFLAGSreal | TFLAGS.TFLAGSimaginary)) != | |
696 (tob.flags & (TFLAGS.TFLAGSreal | TFLAGS.TFLAGSimaginary))) | |
697 return MATCH.MATCHnomatch; | |
698 } | |
699 return MATCH.MATCHconvert; | |
700 } | |
701 | |
72 | 702 override Expression defaultInit(Loc loc) |
0 | 703 { |
704 long value = 0; | |
705 | |
706 version (SNAN_DEFAULT_INIT) { | |
707 /* | |
708 * Use a payload which is different from the machine NaN, | |
709 * so that uninitialised variables can be | |
710 * detected even if exceptions are disabled. | |
711 */ | |
712 ushort[8] snan = [ 0, 0, 0, 0xA000, 0x7FFF, 0, 0, 0 ]; | |
713 /* | |
714 * Although long doubles are 10 bytes long, some | |
715 * C ABIs pad them out to 12 or even 16 bytes, so | |
716 * leave enough space in the snan array. | |
717 */ | |
718 assert(REALSIZE <= snan.sizeof); | |
719 real fvalue = *cast(real*)snan.ptr; | |
720 } | |
721 | |
722 version (LOGDEFAULTINIT) { | |
723 printf("TypeBasic.defaultInit() '%s'\n", toChars()); | |
724 } | |
725 switch (ty) | |
726 { | |
727 case TY.Tchar: | |
728 value = 0xFF; | |
729 break; | |
730 | |
731 case TY.Twchar: | |
732 case TY.Tdchar: | |
733 value = 0xFFFF; | |
734 break; | |
735 | |
736 case TY.Timaginary32: | |
737 case TY.Timaginary64: | |
738 case TY.Timaginary80: | |
739 case TY.Tfloat32: | |
740 case TY.Tfloat64: | |
741 case TY.Tfloat80: | |
742 version (SNAN_DEFAULT_INIT) { | |
743 return new RealExp(loc, fvalue, this); | |
744 } else { | |
745 return getProperty(loc, Id.nan); | |
746 } | |
747 | |
748 case TY.Tcomplex32: | |
749 case TY.Tcomplex64: | |
750 case TY.Tcomplex80: | |
751 version (SNAN_DEFAULT_INIT) { | |
752 { | |
753 // Can't use fvalue + I*fvalue (the im part becomes a quiet NaN). | |
754 Complex!(real) cvalue; | |
755 cvalue.re = fvalue; | |
756 cvalue.im = fvalue; | |
757 | |
758 return new ComplexExp(loc, cvalue, this); | |
759 } | |
760 } else { | |
761 return getProperty(loc, Id.nan); | |
762 } | |
763 | |
764 case TY.Tvoid: | |
765 error(loc, "void does not have a default initializer"); | |
766 | |
767 default: | |
768 break; /// | |
769 } | |
770 return new IntegerExp(loc, value, this); | |
771 } | |
772 | |
72 | 773 override bool isZeroInit(Loc loc) |
0 | 774 { |
775 switch (ty) | |
776 { | |
777 case TY.Tchar: | |
778 case TY.Twchar: | |
779 case TY.Tdchar: | |
780 case TY.Timaginary32: | |
781 case TY.Timaginary64: | |
782 case TY.Timaginary80: | |
783 case TY.Tfloat32: | |
784 case TY.Tfloat64: | |
785 case TY.Tfloat80: | |
786 case TY.Tcomplex32: | |
787 case TY.Tcomplex64: | |
788 case TY.Tcomplex80: | |
789 return false; // no | |
790 default: | |
791 break; | |
792 } | |
793 | |
794 return true; // yes | |
795 } | |
796 | |
72 | 797 override bool builtinTypeInfo() |
0 | 798 { |
799 version (DMDV2) { | |
800 return mod ? false : true; | |
801 } else { | |
802 return true; | |
803 } | |
804 } | |
805 | |
806 // For eliminating dynamic_cast | |
72 | 807 override TypeBasic isTypeBasic() |
0 | 808 { |
809 return this; | |
810 } | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
0
diff
changeset
|
811 } |