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