Mercurial > projects > ddmd
annotate dmd/CastExp.d @ 192:eb38fdcb3e62 default tip
updated to compile with dmd2.062
author | korDen |
---|---|
date | Sat, 02 Mar 2013 01:25:52 -0800 |
parents | b0d41ff5e0df |
children |
rev | line source |
---|---|
72 | 1 module dmd.CastExp; |
2 | |
114 | 3 import dmd.common; |
72 | 4 import dmd.Expression; |
129 | 5 import dmd.GlobalExpressions; |
72 | 6 import dmd.TY; |
7 import dmd.TypeStruct; | |
73 | 8 import dmd.ErrorExp; |
72 | 9 import dmd.TypeExp; |
10 import dmd.DotIdExp; | |
11 import dmd.CallExp; | |
12 import dmd.Global; | |
13 import dmd.Id; | |
14 import dmd.Identifier; | |
15 import dmd.BinExp; | |
16 import dmd.UnaExp; | |
17 import dmd.VarExp; | |
18 import dmd.Token; | |
19 import dmd.VarDeclaration; | |
20 import dmd.InterState; | |
21 import dmd.MATCH; | |
22 import dmd.Type; | |
23 import dmd.OutBuffer; | |
24 import dmd.Loc; | |
25 import dmd.Scope; | |
26 import dmd.IntRange; | |
27 import dmd.IRState; | |
28 import dmd.ArrayTypes; | |
29 import dmd.HdrGenState; | |
30 import dmd.MOD; | |
31 import dmd.TOK; | |
32 import dmd.WANT; | |
33 import dmd.ClassDeclaration; | |
34 | |
35 import dmd.Optimize; | |
36 import dmd.PREC; | |
37 import dmd.Cast; | |
38 | |
79 | 39 import dmd.codegen.Util; |
40 import dmd.backend.elem; | |
41 import dmd.backend.mTY; | |
72 | 42 import dmd.backend.Util; |
43 import dmd.backend.TYM; | |
44 import dmd.backend.OPER; | |
45 import dmd.backend.RTLSYM; | |
79 | 46 import dmd.expression.Util; |
72 | 47 |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
48 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
|
49 |
0 | 50 class CastExp : UnaExp |
51 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
52 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
|
53 |
72 | 54 // Possible to cast to one type while painting to another type |
0 | 55 Type to; // type to cast to |
56 MOD mod; // MODxxxxx | |
57 | |
58 this(Loc loc, Expression e, Type t) | |
59 { | |
178 | 60 register(); |
61 | |
72 | 62 super(loc, TOK.TOKcast, CastExp.sizeof, e); |
63 to = t; | |
0 | 64 this.mod = cast(MOD)~0; |
65 } | |
66 | |
67 this(Loc loc, Expression e, MOD mod) | |
72 | 68 { |
178 | 69 register(); |
70 | |
72 | 71 super(loc, TOK.TOKcast, CastExp.sizeof, e); |
72 to = null; | |
0 | 73 this.mod = mod; |
74 } | |
75 | |
72 | 76 override Expression syntaxCopy() |
0 | 77 { |
72 | 78 return to ? new CastExp(loc, e1.syntaxCopy(), to.syntaxCopy()) |
0 | 79 : new CastExp(loc, e1.syntaxCopy(), mod); |
80 } | |
81 | |
72 | 82 override Expression semantic(Scope sc) |
0 | 83 { |
72 | 84 Expression e; |
85 BinExp b; | |
86 UnaExp u; | |
87 | |
88 version (LOGSEMANTIC) { | |
89 printf("CastExp.semantic('%s')\n", toChars()); | |
90 } | |
91 | |
92 //static int x; assert(++x < 10); | |
93 | |
94 if (type) | |
95 return this; | |
96 super.semantic(sc); | |
97 if (e1.type) // if not a tuple | |
98 { | |
73 | 99 e1 = resolveProperties(sc, e1); |
100 | |
101 if (!to) | |
102 { | |
103 /* Handle cast(const) and cast(immutable), etc. | |
104 */ | |
105 to = e1.type.castMod(mod); | |
106 } | |
107 else | |
108 to = to.semantic(loc, sc); | |
109 | |
110 if (!to.equals(e1.type)) | |
111 { | |
112 e = op_overload(sc); | |
113 if (e) | |
114 { | |
115 return e.implicitCastTo(sc, to); | |
116 } | |
117 } | |
72 | 118 |
109 | 119 if (e1.op == TOKtemplate) |
120 { | |
121 error("cannot cast template %s to type %s", e1.toChars(), to.toChars()); | |
122 return new ErrorExp(); | |
123 } | |
124 | |
73 | 125 Type t1b = e1.type.toBasetype(); |
126 Type tob = to.toBasetype(); | |
127 if (tob.ty == TY.Tstruct && | |
128 !tob.equals(t1b) && | |
129 (cast(TypeStruct)tob).sym.search(Loc(0), Id.call, 0) | |
130 ) | |
131 { | |
132 /* Look to replace: | |
133 * cast(S)t | |
134 * with: | |
135 * S(t) | |
136 */ | |
72 | 137 |
73 | 138 // Rewrite as to.call(e1) |
139 e = new TypeExp(loc, to); | |
140 e = new DotIdExp(loc, e, Id.call); | |
141 e = new CallExp(loc, e, e1); | |
142 e = e.semantic(sc); | |
143 return e; | |
144 } | |
145 | |
146 // Struct casts are possible only when the sizes match | |
147 if (tob.ty == Tstruct || t1b.ty == Tstruct) | |
72 | 148 { |
73 | 149 size_t fromsize = cast(size_t)t1b.size(loc); |
150 size_t tosize = cast(size_t)tob.size(loc); | |
151 if (fromsize != tosize) | |
152 { | |
153 error("cannot cast from %s to %s", e1.type.toChars(), to.toChars()); | |
154 return new ErrorExp(); | |
155 } | |
72 | 156 } |
157 } | |
158 else if (!to) | |
73 | 159 { |
160 error("cannot cast tuple"); | |
161 to = Type.terror; | |
72 | 162 } |
163 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
164 //static if (true) { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
165 if (sc.func && sc.func.isSafe() && !sc.intypeof) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
166 //} else { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
167 // if (global.params.safe && !sc.module_.safe && !sc.intypeof) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
168 //} |
72 | 169 { // Disallow unsafe casts |
170 Type tob = to.toBasetype(); | |
171 Type t1b = e1.type.toBasetype(); | |
172 if (!t1b.isMutable() && tob.isMutable()) | |
173 { // Cast not mutable to mutable | |
174 Lunsafe: | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
175 error("cast from %s to %s not allowed in safe code", e1.type.toChars(), to.toChars()); |
72 | 176 } |
177 else if (t1b.isShared() && !tob.isShared()) | |
178 // Cast away shared | |
179 goto Lunsafe; | |
180 else if (tob.ty == TY.Tpointer) | |
181 { if (t1b.ty != TY.Tpointer) | |
182 goto Lunsafe; | |
183 Type tobn = tob.nextOf().toBasetype(); | |
184 Type t1bn = t1b.nextOf().toBasetype(); | |
185 | |
186 if (!t1bn.isMutable() && tobn.isMutable()) | |
187 // Cast away pointer to not mutable | |
188 goto Lunsafe; | |
189 | |
190 if (t1bn.isShared() && !tobn.isShared()) | |
191 // Cast away pointer to shared | |
192 goto Lunsafe; | |
193 | |
135 | 194 if (t1bn.isWild() && !tobn.isConst() && !tobn.isWild()) |
195 // Cast wild to anything but const | wild | |
196 goto Lunsafe; | |
197 | |
72 | 198 if (tobn.isTypeBasic() && tobn.size() < t1bn.size()) { |
199 // Allow things like casting a long* to an int* | |
200 ; | |
201 } else if (tobn.ty != TY.Tvoid) { | |
202 // Cast to a pointer other than void* | |
203 goto Lunsafe; | |
204 } | |
205 } | |
206 | |
207 // BUG: Check for casting array types, such as void[] to int*[] | |
208 } | |
209 | |
210 e = e1.castTo(sc, to); | |
0 | 211 return e; |
212 } | |
213 | |
72 | 214 override MATCH implicitConvTo(Type t) |
0 | 215 { |
72 | 216 static if (false) { |
217 printf("CastExp::implicitConvTo(this=%s, type=%s, t=%s)\n", toChars(), type.toChars(), t.toChars()); | |
218 } | |
219 MATCH result = type.implicitConvTo(t); | |
220 | |
221 if (result == MATCHnomatch) | |
222 { | |
223 if (t.isintegral() && | |
224 e1.type.isintegral() && | |
225 e1.implicitConvTo(t) != MATCHnomatch) | |
226 result = MATCHconvert; | |
227 else | |
228 result = Expression.implicitConvTo(t); | |
229 } | |
0 | 230 return result; |
231 } | |
232 | |
72 | 233 override IntRange getIntRange() |
0 | 234 { |
72 | 235 IntRange ir; |
236 ir = e1.getIntRange(); | |
237 // Do sign extension | |
238 switch (e1.type.toBasetype().ty) | |
239 { | |
240 case Tint8: | |
241 if (ir.imax & 0x80) | |
242 ir.imax |= 0xFFFFFFFFFFFFFF00UL; | |
243 break; | |
244 case Tint16: | |
245 if (ir.imax & 0x8000) | |
246 ir.imax |= 0xFFFFFFFFFFFF0000UL; | |
247 break; | |
248 case Tint32: | |
249 if (ir.imax & 0x80000000) | |
250 ir.imax |= 0xFFFFFFFF00000000UL; | |
251 break; | |
252 default: | |
253 } | |
73 | 254 |
255 if (type.isintegral()) | |
256 { | |
257 ir.imin &= type.sizemask(); | |
258 ir.imax &= type.sizemask(); | |
259 } | |
260 | |
261 //printf("CastExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); | |
53 | 262 return ir; |
0 | 263 } |
264 | |
72 | 265 override Expression optimize(int result) |
266 { | |
267 //printf("CastExp.optimize(result = %d) %s\n", result, toChars()); | |
268 //printf("from %s to %s\n", type.toChars(), to.toChars()); | |
269 //printf("from %s\n", type.toChars()); | |
270 //printf("e1.type %s\n", e1.type.toChars()); | |
271 //printf("type = %p\n", type); | |
272 assert(type); | |
273 TOK op1 = e1.op; | |
274 | |
275 Expression e1old = e1; | |
276 e1 = e1.optimize(result); | |
277 e1 = fromConstInitializer(result, e1); | |
278 | |
279 if (e1 == e1old && | |
280 e1.op == TOK.TOKarrayliteral && | |
281 type.toBasetype().ty == TY.Tpointer && | |
282 e1.type.toBasetype().ty != TY.Tsarray) | |
283 { | |
284 // Casting this will result in the same expression, and | |
285 // infinite loop because of Expression.implicitCastTo() | |
286 return this; // no change | |
287 } | |
288 | |
289 if ((e1.op == TOK.TOKstring || e1.op == TOK.TOKarrayliteral) && | |
290 (type.ty == TY.Tpointer || type.ty == TY.Tarray) && | |
291 e1.type.nextOf().size() == type.nextOf().size() | |
292 ) | |
293 { | |
294 Expression e = e1.castTo(null, type); | |
295 | |
296 static if (false) { | |
297 printf(" returning1 %s\n", e.toChars()); | |
298 } | |
299 return e; | |
300 } | |
301 | |
302 if (e1.op == TOK.TOKstructliteral && | |
303 e1.type.implicitConvTo(type) >= MATCH.MATCHconst) | |
304 { | |
305 e1.type = type; | |
306 static if (false) { | |
307 printf(" returning2 %s\n", e1.toChars()); | |
308 } | |
309 return e1; | |
310 } | |
311 | |
312 /* The first test here is to prevent infinite loops | |
313 */ | |
314 if (op1 != TOK.TOKarrayliteral && e1.op == TOK.TOKarrayliteral) | |
315 return e1.castTo(null, to); | |
316 if (e1.op == TOK.TOKnull && | |
317 (type.ty == TY.Tpointer || type.ty == TY.Tclass || type.ty == TY.Tarray)) | |
318 { | |
319 e1.type = type; | |
320 static if (false) { | |
321 printf(" returning3 %s\n", e1.toChars()); | |
322 } | |
323 return e1; | |
324 } | |
325 | |
326 if (result & WANT.WANTflags && type.ty == TY.Tclass && e1.type.ty == TY.Tclass) | |
327 { | |
328 // See if we can remove an unnecessary cast | |
329 ClassDeclaration cdfrom; | |
330 ClassDeclaration cdto; | |
331 int offset; | |
332 | |
333 cdfrom = e1.type.isClassHandle(); | |
334 cdto = type.isClassHandle(); | |
335 if (cdto.isBaseOf(cdfrom, &offset) && offset == 0) | |
336 { | |
337 e1.type = type; | |
338 static if (false) { | |
339 printf(" returning4 %s\n", e1.toChars()); | |
340 } | |
341 return e1; | |
342 } | |
343 } | |
344 | |
345 // We can convert 'head const' to mutable | |
346 if (to.constOf().equals(e1.type.constOf())) | |
347 // if (to.constConv(e1.type) >= MATCHconst) | |
348 { | |
349 e1.type = type; | |
350 static if (false) { | |
351 printf(" returning5 %s\n", e1.toChars()); | |
352 } | |
353 return e1; | |
354 } | |
355 | |
356 Expression e; | |
357 | |
358 if (e1.isConst()) | |
359 { | |
360 if (e1.op == TOK.TOKsymoff) | |
361 { | |
362 if (type.size() == e1.type.size() && | |
363 type.toBasetype().ty != TY.Tsarray) | |
364 { | |
365 e1.type = type; | |
366 return e1; | |
367 } | |
368 return this; | |
369 } | |
370 if (to.toBasetype().ty == TY.Tvoid) | |
371 e = this; | |
372 else | |
373 e = Cast(type, to, e1); | |
374 } | |
375 else | |
376 e = this; | |
377 static if (false) { | |
378 printf(" returning6 %s\n", e.toChars()); | |
379 } | |
0 | 380 return e; |
381 } | |
382 | |
72 | 383 override Expression interpret(InterState istate) |
0 | 384 { |
129 | 385 Expression e; |
386 Expression e1; | |
387 | |
388 version (LOG) { | |
389 printf("CastExp.interpret() %.*s\n", toChars()); | |
390 } | |
391 e1 = this.e1.interpret(istate); | |
392 if (e1 is EXP_CANT_INTERPRET) | |
393 goto Lcant; | |
394 return Cast(type, to, e1); | |
395 | |
396 Lcant: | |
397 version (LOG) { | |
398 printf("CastExp.interpret() %.*s CANT\n", toChars()); | |
399 } | |
400 return EXP_CANT_INTERPRET; | |
0 | 401 } |
402 | |
72 | 403 override bool checkSideEffect(int flag) |
0 | 404 { |
123 | 405 /* if not: |
406 * cast(void) | |
407 * cast(classtype)func() | |
408 */ | |
409 if (!to.equals(Type.tvoid) && !(to.ty == Tclass && e1.op == TOKcall && e1.type.ty == Tclass)) | |
410 return Expression.checkSideEffect(flag); | |
411 | |
412 return true; | |
0 | 413 } |
414 | |
72 | 415 override void checkEscape() |
0 | 416 { |
72 | 417 Type tb = type.toBasetype(); |
418 if (tb.ty == TY.Tarray && e1.op == TOK.TOKvar && e1.type.toBasetype().ty ==TY.Tsarray) | |
419 { | |
420 VarExp ve = cast(VarExp)e1; | |
421 VarDeclaration v = ve.var.isVarDeclaration(); | |
422 if (v) | |
423 { | |
424 if (!v.isDataseg() && !v.isParameter()) | |
425 error("escaping reference to local %s", v.toChars()); | |
426 } | |
0 | 427 } |
428 } | |
429 | |
72 | 430 override void toCBuffer(OutBuffer buf, HdrGenState* hgs) |
0 | 431 { |
72 | 432 buf.writestring("cast("); |
433 version (DMDV1) { | |
434 to.toCBuffer(buf, null, hgs); | |
435 } else { | |
436 if (to) | |
437 to.toCBuffer(buf, null, hgs); | |
438 else | |
439 { | |
135 | 440 MODtoBuffer(buf, mod); |
72 | 441 } |
442 } | |
443 buf.writeByte(')'); | |
0 | 444 expToCBuffer(buf, hgs, e1, precedence[op]); |
445 } | |
446 | |
72 | 447 override void buildArrayIdent(OutBuffer buf, Expressions arguments) |
0 | 448 { |
72 | 449 Type tb = type.toBasetype(); |
450 if (tb.ty == Tarray || tb.ty == Tsarray) | |
451 { | |
452 e1.buildArrayIdent(buf, arguments); | |
453 } | |
454 else | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
455 Expression.buildArrayIdent(buf, arguments); |
0 | 456 } |
457 | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
129
diff
changeset
|
458 override Expression buildArrayLoop(Parameters fparams) |
0 | 459 { |
72 | 460 Type tb = type.toBasetype(); |
461 if (tb.ty == Tarray || tb.ty == Tsarray) | |
462 { | |
463 return e1.buildArrayLoop(fparams); | |
464 } | |
465 else | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
466 return Expression.buildArrayLoop(fparams); |
72 | 467 } |
468 | |
469 static int X(int fty, int tty) { | |
470 return ((fty) * TY.TMAX + (tty)); | |
0 | 471 } |
472 | |
72 | 473 override elem* toElem(IRState* irs) |
0 | 474 { |
72 | 475 TY fty; |
476 TY tty; | |
477 tym_t ftym; | |
478 tym_t ttym; | |
479 OPER eop; | |
480 | |
79 | 481 static if (false) |
482 { | |
72 | 483 printf("CastExp::toElem()\n"); |
484 print(); | |
485 printf("\tfrom: %s\n", e1.type.toChars()); | |
486 printf("\tto : %s\n", to.toChars()); | |
487 } | |
488 | |
79 | 489 elem* e = e1.toElem(irs); |
490 Type tfrom = e1.type.toBasetype(); | |
491 Type t = to.toBasetype(); // skip over typedef's | |
72 | 492 if (t.equals(tfrom)) |
493 goto Lret; | |
494 | |
495 fty = tfrom.ty; | |
496 //printf("fty = %d\n", fty); | |
497 tty = t.ty; | |
498 | |
499 if (tty == TY.Tpointer && fty == TY.Tarray | |
500 ///static if (false) { | |
501 /// && (t.next.ty == Tvoid || t.next.equals(e1.type.next)) | |
502 ///} | |
503 ) | |
504 { | |
505 if (e.Eoper == OPER.OPvar) | |
506 { | |
507 // e1 . *(&e1 + 4) | |
508 e = el_una(OPER.OPaddr, TYM.TYnptr, e); | |
509 e = el_bin(OPER.OPadd, TYM.TYnptr, e, el_long(TYM.TYint, 4)); | |
510 e = el_una(OPER.OPind, t.totym(),e); | |
511 } | |
512 else | |
513 { | |
514 // e1 . (unsigned)(e1 >> 32) | |
515 e = el_bin(OPER.OPshr, TYM.TYullong, e, el_long(TYM.TYint, 32)); | |
516 e = el_una(OPER.OP64_32, t.totym(), e); | |
517 } | |
518 goto Lret; | |
519 } | |
520 | |
521 if (tty == TY.Tpointer && fty == TY.Tsarray | |
522 ///static if (false) { | |
523 /// && (t.next.ty == Tvoid || t.next.equals(e1.type.next)) | |
524 ///} | |
525 ) | |
526 { | |
527 // e1 . &e1 | |
528 e = el_una(OPER.OPaddr, TYM.TYnptr, e); | |
529 goto Lret; | |
530 } | |
531 | |
532 // Convert from static array to dynamic array | |
533 if (tty == TY.Tarray && fty == TY.Tsarray) | |
534 { | |
535 e = sarray_toDarray(loc, tfrom, t, e); | |
536 goto Lret; | |
537 } | |
538 | |
539 // Convert from dynamic array to dynamic array | |
540 if (tty == TY.Tarray && fty == TY.Tarray) | |
541 { | |
542 uint fsize = cast(uint)tfrom.nextOf().size(); | |
543 uint tsize = cast(uint)t.nextOf().size(); | |
544 | |
545 if (fsize != tsize) | |
546 { | |
547 elem* ep = el_params(e, el_long(TYM.TYint, fsize), el_long(TYM.TYint, tsize), null); | |
548 e = el_bin(OPER.OPcall, type.totym(), el_var(rtlsym[RTLSYM.RTLSYM_ARRAYCAST]), ep); | |
549 } | |
550 goto Lret; | |
551 } | |
552 | |
79 | 553 static if (false) |
554 { | |
72 | 555 // Convert from dynamic array string literal to static array |
556 if (tty == TY.Tsarray && fty == TY.Tarray && e1.op == TOK.TOKstring) | |
557 { | |
558 goto Lret; // treat as a 'paint' | |
559 } | |
560 } | |
561 | |
562 // Casting from base class to derived class requires a runtime check | |
563 if (fty == TY.Tclass && tty == TY.Tclass) | |
564 { | |
565 // Casting from derived class to base class is a no-op | |
566 ClassDeclaration cdfrom; | |
567 ClassDeclaration cdto; | |
568 int offset; | |
569 int rtl = RTLSYM.RTLSYM_DYNAMIC_CAST; | |
570 | |
571 cdfrom = tfrom.isClassHandle(); | |
572 cdto = t.isClassHandle(); | |
573 if (cdfrom.isInterfaceDeclaration()) | |
574 { | |
575 rtl = RTLSYM.RTLSYM_INTERFACE_CAST; | |
576 if (cdfrom.isCPPinterface()) | |
577 { | |
578 if (cdto.isCPPinterface()) | |
579 { | |
580 /* Casting from a C++ interface to a C++ interface | |
581 * is always a 'paint' operation | |
582 */ | |
583 goto Lret; // no-op | |
584 } | |
585 | |
586 /* Casting from a C++ interface to a class | |
587 * always results in null because there is no runtime | |
588 * information available to do it. | |
589 * | |
590 * Casting from a C++ interface to a non-C++ interface | |
591 * always results in null because there's no way one | |
592 * can be derived from the other. | |
593 */ | |
594 e = el_bin(OPER.OPcomma, TYM.TYnptr, e, el_long(TYM.TYnptr, 0)); | |
595 goto Lret; | |
596 } | |
597 } | |
598 if (cdto.isBaseOf(cdfrom, &offset) && offset != OFFSET_RUNTIME) | |
599 { | |
600 /* The offset from cdfrom=>cdto is known at compile time. | |
601 */ | |
602 | |
603 //printf("offset = %d\n", offset); | |
604 if (offset) | |
605 { | |
606 /* Rewrite cast as (e ? e + offset : null) | |
607 */ | |
608 elem* etmp; | |
609 elem* ex; | |
610 | |
611 if (e1.op == TOK.TOKthis) | |
612 { | |
613 // Assume 'this' is never null, so skip null check | |
614 e = el_bin(OPER.OPadd, TYM.TYnptr, e, el_long(TYM.TYint, offset)); | |
615 } | |
616 else | |
617 { | |
618 etmp = el_same(&e); | |
619 ex = el_bin(OPER.OPadd, TYM.TYnptr, etmp, el_long(TYM.TYint, offset)); | |
620 ex = el_bin(OPER.OPcolon, TYM.TYnptr, ex, el_long(TYM.TYnptr, 0)); | |
621 e = el_bin(OPER.OPcond, TYM.TYnptr, e, ex); | |
622 } | |
623 } | |
624 goto Lret; // no-op | |
625 } | |
626 | |
627 /* The offset from cdfrom=>cdto can only be determined at runtime. | |
628 */ | |
629 elem* ep; | |
630 | |
631 ep = el_param(el_ptr(cdto.toSymbol()), e); | |
632 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[rtl]), ep); | |
633 goto Lret; | |
634 } | |
635 | |
79 | 636 ftym = tybasic(e.Ety); |
637 ttym = tybasic(t.totym()); | |
72 | 638 if (ftym == ttym) |
639 goto Lret; | |
640 | |
641 switch (tty) | |
642 { | |
643 case TY.Tpointer: | |
644 if (fty == TY.Tdelegate) | |
645 goto Lpaint; | |
646 tty = TY.Tuns32; | |
647 break; | |
648 | |
649 case TY.Tchar: | |
650 tty = TY.Tuns8; | |
651 break; | |
652 case TY.Twchar: | |
653 tty = TY.Tuns16; | |
654 break; | |
655 case TY.Tdchar: | |
656 tty = TY.Tuns32; | |
657 break; | |
658 case TY.Tvoid: | |
659 goto Lpaint; | |
660 | |
661 case TY.Tbool: | |
662 { | |
663 // Construct e?true:false | |
664 elem* eq; | |
665 | |
666 e = el_una(OPER.OPbool, ttym, e); | |
667 goto Lret; | |
668 } | |
669 | |
670 default: | |
671 break; /// | |
672 } | |
673 | |
674 switch (fty) | |
675 { | |
676 case TY.Tpointer: fty = TY.Tuns32; break; | |
677 case TY.Tchar: fty = TY.Tuns8; break; | |
678 case TY.Twchar: fty = TY.Tuns16; break; | |
679 case TY.Tdchar: fty = TY.Tuns32; break; | |
680 default: break; /// | |
681 } | |
682 | |
683 Lagain: | |
684 switch (X(fty,tty)) | |
685 { | |
79 | 686 static if (false) |
687 { | |
72 | 688 case X(TY.Tbit,TY.Tint8): |
689 case X(TY.Tbit,TY.Tuns8): | |
690 goto Lpaint; | |
691 case X(TY.Tbit,TY.Tint16): | |
692 case X(TY.Tbit,TY.Tuns16): | |
693 case X(TY.Tbit,TY.Tint32): | |
694 case X(TY.Tbit,TY.Tuns32): | |
695 eop = OPu8_16; | |
696 goto Leop; | |
697 case X(TY.Tbit,TY.Tint64): | |
698 case X(TY.Tbit,TY.Tuns64): | |
699 case X(TY.Tbit,TY.Tfloat32): | |
700 case X(TY.Tbit,TY.Tfloat64): | |
701 case X(TY.Tbit,TY.Tfloat80): | |
702 case X(TY.Tbit,TY.Tcomplex32): | |
703 case X(TY.Tbit,TY.Tcomplex64): | |
704 case X(TY.Tbit,TY.Tcomplex80): | |
705 e = el_una(OPER.OPu8_16, TYM.TYuint, e); | |
706 fty = TY.Tuns32; | |
707 goto Lagain; | |
708 case X(Tbit,Timaginary32): | |
709 case X(Tbit,Timaginary64): | |
710 case X(Tbit,Timaginary80): | |
711 goto Lzero; | |
712 } | |
713 /* ============================= */ | |
714 | |
715 case X(TY.Tbool,TY.Tint8): | |
716 case X(TY.Tbool,TY.Tuns8): | |
717 goto Lpaint; | |
718 case X(TY.Tbool,TY.Tint16): | |
719 case X(TY.Tbool,TY.Tuns16): | |
720 case X(TY.Tbool,TY.Tint32): | |
721 case X(TY.Tbool,TY.Tuns32): | |
722 eop = OPER.OPu8_16; | |
723 goto Leop; | |
724 case X(TY.Tbool,TY.Tint64): | |
725 case X(TY.Tbool,TY.Tuns64): | |
726 case X(TY.Tbool,TY.Tfloat32): | |
727 case X(TY.Tbool,TY.Tfloat64): | |
728 case X(TY.Tbool,TY.Tfloat80): | |
729 case X(TY.Tbool,TY.Tcomplex32): | |
730 case X(TY.Tbool,TY.Tcomplex64): | |
731 case X(TY.Tbool,TY.Tcomplex80): | |
732 e = el_una(OPER.OPu8_16, TYM.TYuint, e); | |
733 fty = TY.Tuns32; | |
734 goto Lagain; | |
735 case X(TY.Tbool,TY.Timaginary32): | |
736 case X(TY.Tbool,TY.Timaginary64): | |
737 case X(TY.Tbool,TY.Timaginary80): | |
738 goto Lzero; | |
739 | |
740 /* ============================= */ | |
741 | |
742 case X(TY.Tint8,TY.Tuns8): | |
743 goto Lpaint; | |
744 case X(TY.Tint8,TY.Tint16): | |
745 case X(TY.Tint8,TY.Tuns16): | |
746 case X(TY.Tint8,TY.Tint32): | |
747 case X(TY.Tint8,TY.Tuns32): | |
748 eop = OPER.OPs8_16; | |
749 goto Leop; | |
750 case X(TY.Tint8,TY.Tint64): | |
751 case X(TY.Tint8,TY.Tuns64): | |
752 case X(TY.Tint8,TY.Tfloat32): | |
753 case X(TY.Tint8,TY.Tfloat64): | |
754 case X(TY.Tint8,TY.Tfloat80): | |
755 case X(TY.Tint8,TY.Tcomplex32): | |
756 case X(TY.Tint8,TY.Tcomplex64): | |
757 case X(TY.Tint8,TY.Tcomplex80): | |
758 e = el_una(OPER.OPs8_16, TYM.TYint, e); | |
759 fty = TY.Tint32; | |
760 goto Lagain; | |
761 case X(TY.Tint8,TY.Timaginary32): | |
762 case X(TY.Tint8,TY.Timaginary64): | |
763 case X(TY.Tint8,TY.Timaginary80): | |
764 goto Lzero; | |
765 | |
766 /* ============================= */ | |
767 | |
768 case X(TY.Tuns8,TY.Tint8): | |
769 goto Lpaint; | |
770 case X(TY.Tuns8,TY.Tint16): | |
771 case X(TY.Tuns8,TY.Tuns16): | |
772 case X(TY.Tuns8,TY.Tint32): | |
773 case X(TY.Tuns8,TY.Tuns32): | |
774 eop = OPER.OPu8_16; | |
775 goto Leop; | |
776 case X(TY.Tuns8,TY.Tint64): | |
777 case X(TY.Tuns8,TY.Tuns64): | |
778 case X(TY.Tuns8,TY.Tfloat32): | |
779 case X(TY.Tuns8,TY.Tfloat64): | |
780 case X(TY.Tuns8,TY.Tfloat80): | |
781 case X(TY.Tuns8,TY.Tcomplex32): | |
782 case X(TY.Tuns8,TY.Tcomplex64): | |
783 case X(TY.Tuns8,TY.Tcomplex80): | |
784 e = el_una(OPER.OPu8_16, TYM.TYuint, e); | |
785 fty = TY.Tuns32; | |
786 goto Lagain; | |
787 case X(TY.Tuns8,TY.Timaginary32): | |
788 case X(TY.Tuns8,TY.Timaginary64): | |
789 case X(TY.Tuns8,TY.Timaginary80): | |
790 goto Lzero; | |
791 | |
792 /* ============================= */ | |
793 | |
794 case X(TY.Tint16,TY.Tint8): | |
795 case X(TY.Tint16,TY.Tuns8): | |
796 eop = OPER.OP16_8; | |
797 goto Leop; | |
798 case X(TY.Tint16,TY.Tuns16): | |
799 goto Lpaint; | |
800 case X(TY.Tint16,TY.Tint32): | |
801 case X(TY.Tint16,TY.Tuns32): | |
802 eop = OPER.OPs16_32; | |
803 goto Leop; | |
804 case X(TY.Tint16,TY.Tint64): | |
805 case X(TY.Tint16,TY.Tuns64): | |
806 e = el_una(OPER.OPs16_32, TYM.TYint, e); | |
807 fty = TY.Tint32; | |
808 goto Lagain; | |
809 case X(TY.Tint16,TY.Tfloat32): | |
810 case X(TY.Tint16,TY.Tfloat64): | |
811 case X(TY.Tint16,TY.Tfloat80): | |
812 case X(TY.Tint16,TY.Tcomplex32): | |
813 case X(TY.Tint16,TY.Tcomplex64): | |
814 case X(TY.Tint16,TY.Tcomplex80): | |
815 e = el_una(OPER.OPs16_d, TYM.TYdouble, e); | |
816 fty = TY.Tfloat64; | |
817 goto Lagain; | |
818 case X(TY.Tint16,TY.Timaginary32): | |
819 case X(TY.Tint16,TY.Timaginary64): | |
820 case X(TY.Tint16,TY.Timaginary80): | |
821 goto Lzero; | |
822 | |
823 /* ============================= */ | |
824 | |
825 case X(TY.Tuns16,TY.Tint8): | |
826 case X(TY.Tuns16,TY.Tuns8): | |
827 eop = OPER.OP16_8; | |
828 goto Leop; | |
829 case X(TY.Tuns16,TY.Tint16): | |
830 goto Lpaint; | |
831 case X(TY.Tuns16,TY.Tint32): | |
832 case X(TY.Tuns16,TY.Tuns32): | |
833 eop = OPER.OPu16_32; | |
834 goto Leop; | |
835 case X(TY.Tuns16,TY.Tint64): | |
836 case X(TY.Tuns16,TY.Tuns64): | |
837 case X(TY.Tuns16,TY.Tfloat64): | |
838 case X(TY.Tuns16,TY.Tfloat32): | |
839 case X(TY.Tuns16,TY.Tfloat80): | |
840 case X(TY.Tuns16,TY.Tcomplex32): | |
841 case X(TY.Tuns16,TY.Tcomplex64): | |
842 case X(TY.Tuns16,TY.Tcomplex80): | |
843 e = el_una(OPER.OPu16_32, TYM.TYuint, e); | |
844 fty = TY.Tuns32; | |
845 goto Lagain; | |
846 case X(TY.Tuns16,TY.Timaginary32): | |
847 case X(TY.Tuns16,TY.Timaginary64): | |
848 case X(TY.Tuns16,TY.Timaginary80): | |
849 goto Lzero; | |
850 | |
851 /* ============================= */ | |
852 | |
853 case X(TY.Tint32,TY.Tint8): | |
854 case X(TY.Tint32,TY.Tuns8): | |
855 e = el_una(OPER.OP32_16, TYM.TYshort, e); | |
856 fty = TY.Tint16; | |
857 goto Lagain; | |
858 case X(TY.Tint32,TY.Tint16): | |
859 case X(TY.Tint32,TY.Tuns16): | |
860 eop = OPER.OP32_16; | |
861 goto Leop; | |
862 case X(TY.Tint32,TY.Tuns32): | |
863 goto Lpaint; | |
864 case X(TY.Tint32,TY.Tint64): | |
865 case X(TY.Tint32,TY.Tuns64): | |
866 eop = OPER.OPs32_64; | |
867 goto Leop; | |
868 case X(TY.Tint32,TY.Tfloat32): | |
869 case X(TY.Tint32,TY.Tfloat64): | |
870 case X(TY.Tint32,TY.Tfloat80): | |
871 case X(TY.Tint32,TY.Tcomplex32): | |
872 case X(TY.Tint32,TY.Tcomplex64): | |
873 case X(TY.Tint32,TY.Tcomplex80): | |
874 e = el_una(OPER.OPs32_d, TYM.TYdouble, e); | |
875 fty = TY.Tfloat64; | |
876 goto Lagain; | |
877 case X(TY.Tint32,TY.Timaginary32): | |
878 case X(TY.Tint32,TY.Timaginary64): | |
879 case X(TY.Tint32,TY.Timaginary80): | |
880 goto Lzero; | |
881 | |
882 /* ============================= */ | |
883 | |
884 case X(TY.Tuns32,TY.Tint8): | |
885 case X(TY.Tuns32,TY.Tuns8): | |
886 e = el_una(OPER.OP32_16, TYM.TYshort, e); | |
887 fty = TY.Tuns16; | |
888 goto Lagain; | |
889 case X(TY.Tuns32,TY.Tint16): | |
890 case X(TY.Tuns32,TY.Tuns16): | |
891 eop = OPER.OP32_16; | |
892 goto Leop; | |
893 case X(TY.Tuns32,TY.Tint32): | |
894 goto Lpaint; | |
895 case X(TY.Tuns32,TY.Tint64): | |
896 case X(TY.Tuns32,TY.Tuns64): | |
897 eop = OPER.OPu32_64; | |
898 goto Leop; | |
899 case X(TY.Tuns32,TY.Tfloat32): | |
900 case X(TY.Tuns32,TY.Tfloat64): | |
901 case X(TY.Tuns32,TY.Tfloat80): | |
902 case X(TY.Tuns32,TY.Tcomplex32): | |
903 case X(TY.Tuns32,TY.Tcomplex64): | |
904 case X(TY.Tuns32,TY.Tcomplex80): | |
905 e = el_una(OPER.OPu32_d, TYM.TYdouble, e); | |
906 fty = TY.Tfloat64; | |
907 goto Lagain; | |
908 case X(TY.Tuns32,TY.Timaginary32): | |
909 case X(TY.Tuns32,TY.Timaginary64): | |
910 case X(TY.Tuns32,TY.Timaginary80): | |
911 goto Lzero; | |
912 | |
913 /* ============================= */ | |
914 | |
915 case X(TY.Tint64,TY.Tint8): | |
916 case X(TY.Tint64,TY.Tuns8): | |
917 case X(TY.Tint64,TY.Tint16): | |
918 case X(TY.Tint64,TY.Tuns16): | |
919 e = el_una(OPER.OP64_32, TYM.TYint, e); | |
920 fty = TY.Tint32; | |
921 goto Lagain; | |
922 case X(TY.Tint64,TY.Tint32): | |
923 case X(TY.Tint64,TY.Tuns32): | |
924 eop = OPER.OP64_32; | |
925 goto Leop; | |
926 case X(TY.Tint64,TY.Tuns64): | |
927 goto Lpaint; | |
928 case X(TY.Tint64,TY.Tfloat32): | |
929 case X(TY.Tint64,TY.Tfloat64): | |
930 case X(TY.Tint64,TY.Tfloat80): | |
931 case X(TY.Tint64,TY.Tcomplex32): | |
932 case X(TY.Tint64,TY.Tcomplex64): | |
933 case X(TY.Tint64,TY.Tcomplex80): | |
934 e = el_una(OPER.OPs64_d, TYM.TYdouble, e); | |
935 fty = TY.Tfloat64; | |
936 goto Lagain; | |
937 case X(TY.Tint64,TY.Timaginary32): | |
938 case X(TY.Tint64,TY.Timaginary64): | |
939 case X(TY.Tint64,TY.Timaginary80): | |
940 goto Lzero; | |
941 | |
942 /* ============================= */ | |
943 | |
944 case X(TY.Tuns64,TY.Tint8): | |
945 case X(TY.Tuns64,TY.Tuns8): | |
946 case X(TY.Tuns64,TY.Tint16): | |
947 case X(TY.Tuns64,TY.Tuns16): | |
948 e = el_una(OPER.OP64_32, TYM.TYint, e); | |
949 fty = TY.Tint32; | |
950 goto Lagain; | |
951 case X(TY.Tuns64,TY.Tint32): | |
952 case X(TY.Tuns64,TY.Tuns32): | |
953 eop = OPER.OP64_32; | |
954 goto Leop; | |
955 case X(TY.Tuns64,TY.Tint64): | |
956 goto Lpaint; | |
957 case X(TY.Tuns64,TY.Tfloat32): | |
958 case X(TY.Tuns64,TY.Tfloat64): | |
959 case X(TY.Tuns64,TY.Tfloat80): | |
960 case X(TY.Tuns64,TY.Tcomplex32): | |
961 case X(TY.Tuns64,TY.Tcomplex64): | |
962 case X(TY.Tuns64,TY.Tcomplex80): | |
963 e = el_una(OPER.OPu64_d, TYM.TYdouble, e); | |
964 fty = TY.Tfloat64; | |
965 goto Lagain; | |
966 case X(TY.Tuns64,TY.Timaginary32): | |
967 case X(TY.Tuns64,TY.Timaginary64): | |
968 case X(TY.Tuns64,TY.Timaginary80): | |
969 goto Lzero; | |
970 | |
971 /* ============================= */ | |
972 | |
973 case X(TY.Tfloat32,TY.Tint8): | |
974 case X(TY.Tfloat32,TY.Tuns8): | |
975 case X(TY.Tfloat32,TY.Tint16): | |
976 case X(TY.Tfloat32,TY.Tuns16): | |
977 case X(TY.Tfloat32,TY.Tint32): | |
978 case X(TY.Tfloat32,TY.Tuns32): | |
979 case X(TY.Tfloat32,TY.Tint64): | |
980 case X(TY.Tfloat32,TY.Tuns64): | |
981 case X(TY.Tfloat32,TY.Tfloat80): | |
982 e = el_una(OPER.OPf_d, TYM.TYdouble, e); | |
983 fty = TY.Tfloat64; | |
984 goto Lagain; | |
985 case X(TY.Tfloat32,TY.Tfloat64): | |
986 eop = OPER.OPf_d; | |
987 goto Leop; | |
988 case X(TY.Tfloat32,TY.Timaginary32): | |
989 goto Lzero; | |
990 case X(TY.Tfloat32,TY.Timaginary64): | |
991 goto Lzero; | |
992 case X(TY.Tfloat32,TY.Timaginary80): | |
993 goto Lzero; | |
994 case X(TY.Tfloat32,TY.Tcomplex32): | |
995 case X(TY.Tfloat32,TY.Tcomplex64): | |
996 case X(TY.Tfloat32,TY.Tcomplex80): | |
997 e = el_bin(OPER.OPadd,TYM.TYcfloat,el_long(TYM.TYifloat,0),e); | |
998 fty = TY.Tcomplex32; | |
999 goto Lagain; | |
1000 | |
1001 /* ============================= */ | |
1002 | |
1003 case X(TY.Tfloat64,TY.Tint8): | |
1004 case X(TY.Tfloat64,TY.Tuns8): | |
1005 e = el_una(OPER.OPd_s16, TYM.TYshort, e); | |
1006 fty = TY.Tint16; | |
1007 goto Lagain; | |
1008 case X(TY.Tfloat64,TY.Tint16): | |
1009 eop = OPER.OPd_s16; | |
1010 goto Leop; | |
1011 case X(TY.Tfloat64,TY.Tuns16): | |
1012 eop = OPER.OPd_u16; | |
1013 goto Leop; | |
1014 case X(TY.Tfloat64,TY.Tint32): | |
1015 eop = OPER.OPd_s32; | |
1016 goto Leop; | |
1017 case X(TY.Tfloat64,TY.Tuns32): | |
1018 eop = OPER.OPd_u32; | |
1019 goto Leop; | |
1020 case X(TY.Tfloat64,TY.Tint64): | |
1021 eop = OPER.OPd_s64; | |
1022 goto Leop; | |
1023 case X(TY.Tfloat64,TY.Tuns64): | |
1024 eop = OPER.OPd_u64; | |
1025 goto Leop; | |
1026 case X(TY.Tfloat64,TY.Tfloat32): | |
1027 eop = OPER.OPd_f; | |
1028 goto Leop; | |
1029 case X(TY.Tfloat64,TY.Tfloat80): | |
1030 eop = OPER.OPd_ld; | |
1031 goto Leop; | |
1032 case X(TY.Tfloat64,TY.Timaginary32): | |
1033 goto Lzero; | |
1034 case X(TY.Tfloat64,TY.Timaginary64): | |
1035 goto Lzero; | |
1036 case X(TY.Tfloat64,TY.Timaginary80): | |
1037 goto Lzero; | |
1038 case X(TY.Tfloat64,TY.Tcomplex32): | |
1039 case X(TY.Tfloat64,TY.Tcomplex64): | |
1040 case X(TY.Tfloat64,TY.Tcomplex80): | |
1041 e = el_bin(OPER.OPadd,TYM.TYcfloat,el_long(TYM.TYidouble,0),e); | |
1042 fty = TY.Tcomplex64; | |
1043 goto Lagain; | |
1044 | |
1045 /* ============================= */ | |
1046 | |
1047 case X(TY.Tfloat80,TY.Tint8): | |
1048 case X(TY.Tfloat80,TY.Tuns8): | |
1049 case X(TY.Tfloat80,TY.Tint16): | |
1050 case X(TY.Tfloat80,TY.Tuns16): | |
1051 case X(TY.Tfloat80,TY.Tint32): | |
1052 case X(TY.Tfloat80,TY.Tuns32): | |
1053 case X(TY.Tfloat80,TY.Tint64): | |
1054 case X(TY.Tfloat80,TY.Tfloat32): | |
1055 e = el_una(OPER.OPld_d, TYM.TYdouble, e); | |
1056 fty = TY.Tfloat64; | |
1057 goto Lagain; | |
1058 case X(TY.Tfloat80,TY.Tuns64): | |
1059 eop = OPER.OPld_u64; | |
1060 goto Leop; | |
1061 case X(TY.Tfloat80,TY.Tfloat64): | |
1062 eop = OPER.OPld_d; | |
1063 goto Leop; | |
1064 case X(TY.Tfloat80,TY.Timaginary32): | |
1065 goto Lzero; | |
1066 case X(TY.Tfloat80,TY.Timaginary64): | |
1067 goto Lzero; | |
1068 case X(TY.Tfloat80,TY.Timaginary80): | |
1069 goto Lzero; | |
1070 case X(TY.Tfloat80,TY.Tcomplex32): | |
1071 case X(TY.Tfloat80,TY.Tcomplex64): | |
1072 case X(TY.Tfloat80,TY.Tcomplex80): | |
1073 e = el_bin(OPER.OPadd,TYM.TYcldouble,e,el_long(TYM.TYildouble,0)); | |
1074 fty = TY.Tcomplex80; | |
1075 goto Lagain; | |
1076 | |
1077 /* ============================= */ | |
1078 | |
1079 case X(TY.Timaginary32,TY.Tint8): | |
1080 case X(TY.Timaginary32,TY.Tuns8): | |
1081 case X(TY.Timaginary32,TY.Tint16): | |
1082 case X(TY.Timaginary32,TY.Tuns16): | |
1083 case X(TY.Timaginary32,TY.Tint32): | |
1084 case X(TY.Timaginary32,TY.Tuns32): | |
1085 case X(TY.Timaginary32,TY.Tint64): | |
1086 case X(TY.Timaginary32,TY.Tuns64): | |
1087 case X(TY.Timaginary32,TY.Tfloat32): | |
1088 case X(TY.Timaginary32,TY.Tfloat64): | |
1089 case X(TY.Timaginary32,TY.Tfloat80): | |
1090 goto Lzero; | |
1091 case X(TY.Timaginary32,TY.Timaginary64): | |
1092 eop = OPER.OPf_d; | |
1093 goto Leop; | |
1094 case X(TY.Timaginary32,TY.Timaginary80): | |
1095 e = el_una(OPER.OPf_d, TYM.TYidouble, e); | |
1096 fty = TY.Timaginary64; | |
1097 goto Lagain; | |
1098 case X(TY.Timaginary32,TY.Tcomplex32): | |
1099 case X(TY.Timaginary32,TY.Tcomplex64): | |
1100 case X(TY.Timaginary32,TY.Tcomplex80): | |
1101 e = el_bin(OPER.OPadd,TYM.TYcfloat,el_long(TYM.TYfloat,0),e); | |
1102 fty = TY.Tcomplex32; | |
1103 goto Lagain; | |
1104 | |
1105 /* ============================= */ | |
1106 | |
1107 case X(TY.Timaginary64,TY.Tint8): | |
1108 case X(TY.Timaginary64,TY.Tuns8): | |
1109 case X(TY.Timaginary64,TY.Tint16): | |
1110 case X(TY.Timaginary64,TY.Tuns16): | |
1111 case X(TY.Timaginary64,TY.Tint32): | |
1112 case X(TY.Timaginary64,TY.Tuns32): | |
1113 case X(TY.Timaginary64,TY.Tint64): | |
1114 case X(TY.Timaginary64,TY.Tuns64): | |
1115 case X(TY.Timaginary64,TY.Tfloat32): | |
1116 case X(TY.Timaginary64,TY.Tfloat64): | |
1117 case X(TY.Timaginary64,TY.Tfloat80): | |
1118 goto Lzero; | |
1119 case X(TY.Timaginary64,TY.Timaginary32): | |
1120 eop = OPER.OPd_f; | |
1121 goto Leop; | |
1122 case X(TY.Timaginary64,TY.Timaginary80): | |
1123 eop = OPER.OPd_ld; | |
1124 goto Leop; | |
1125 case X(TY.Timaginary64,TY.Tcomplex32): | |
1126 case X(TY.Timaginary64,TY.Tcomplex64): | |
1127 case X(TY.Timaginary64,TY.Tcomplex80): | |
1128 e = el_bin(OPER.OPadd, TYM.TYcdouble, el_long(TYM.TYdouble,0), e); | |
1129 fty = TY.Tcomplex64; | |
1130 goto Lagain; | |
1131 | |
1132 /* ============================= */ | |
1133 | |
1134 case X(TY.Timaginary80,TY.Tint8): | |
1135 case X(TY.Timaginary80,TY.Tuns8): | |
1136 case X(TY.Timaginary80,TY.Tint16): | |
1137 case X(TY.Timaginary80,TY.Tuns16): | |
1138 case X(TY.Timaginary80,TY.Tint32): | |
1139 case X(TY.Timaginary80,TY.Tuns32): | |
1140 case X(TY.Timaginary80,TY.Tint64): | |
1141 case X(TY.Timaginary80,TY.Tuns64): | |
1142 case X(TY.Timaginary80,TY.Tfloat32): | |
1143 case X(TY.Timaginary80,TY.Tfloat64): | |
1144 case X(TY.Timaginary80,TY.Tfloat80): | |
1145 goto Lzero; | |
1146 case X(TY.Timaginary80,TY.Timaginary32): | |
1147 e = el_una(OPER.OPf_d, TYM.TYidouble, e); | |
1148 fty = TY.Timaginary64; | |
1149 goto Lagain; | |
1150 case X(TY.Timaginary80,TY.Timaginary64): | |
1151 eop = OPER.OPld_d; | |
1152 goto Leop; | |
1153 case X(TY.Timaginary80,TY.Tcomplex32): | |
1154 case X(TY.Timaginary80,TY.Tcomplex64): | |
1155 case X(TY.Timaginary80,TY.Tcomplex80): | |
1156 e = el_bin(OPER.OPadd, TYM.TYcldouble, el_long(TYM.TYldouble,0), e); | |
1157 fty = TY.Tcomplex80; | |
1158 goto Lagain; | |
1159 | |
1160 /* ============================= */ | |
1161 | |
1162 case X(TY.Tcomplex32,TY.Tint8): | |
1163 case X(TY.Tcomplex32,TY.Tuns8): | |
1164 case X(TY.Tcomplex32,TY.Tint16): | |
1165 case X(TY.Tcomplex32,TY.Tuns16): | |
1166 case X(TY.Tcomplex32,TY.Tint32): | |
1167 case X(TY.Tcomplex32,TY.Tuns32): | |
1168 case X(TY.Tcomplex32,TY.Tint64): | |
1169 case X(TY.Tcomplex32,TY.Tuns64): | |
1170 case X(TY.Tcomplex32,TY.Tfloat32): | |
1171 case X(TY.Tcomplex32,TY.Tfloat64): | |
1172 case X(TY.Tcomplex32,TY.Tfloat80): | |
1173 e = el_una(OPER.OPc_r, TYM.TYfloat, e); | |
1174 fty = TY.Tfloat32; | |
1175 goto Lagain; | |
1176 case X(TY.Tcomplex32,TY.Timaginary32): | |
1177 case X(TY.Tcomplex32,TY.Timaginary64): | |
1178 case X(TY.Tcomplex32,TY.Timaginary80): | |
1179 e = el_una(OPER.OPc_i, TYM.TYifloat, e); | |
1180 fty = TY.Timaginary32; | |
1181 goto Lagain; | |
1182 case X(TY.Tcomplex32,TY.Tcomplex64): | |
1183 case X(TY.Tcomplex32,TY.Tcomplex80): | |
1184 e = el_una(OPER.OPf_d, TYM.TYcdouble, e); | |
1185 fty = TY.Tcomplex64; | |
1186 goto Lagain; | |
1187 | |
1188 /* ============================= */ | |
1189 | |
1190 case X(TY.Tcomplex64,TY.Tint8): | |
1191 case X(TY.Tcomplex64,TY.Tuns8): | |
1192 case X(TY.Tcomplex64,TY.Tint16): | |
1193 case X(TY.Tcomplex64,TY.Tuns16): | |
1194 case X(TY.Tcomplex64,TY.Tint32): | |
1195 case X(TY.Tcomplex64,TY.Tuns32): | |
1196 case X(TY.Tcomplex64,TY.Tint64): | |
1197 case X(TY.Tcomplex64,TY.Tuns64): | |
1198 case X(TY.Tcomplex64,TY.Tfloat32): | |
1199 case X(TY.Tcomplex64,TY.Tfloat64): | |
1200 case X(TY.Tcomplex64,TY.Tfloat80): | |
1201 e = el_una(OPER.OPc_r, TYM.TYdouble, e); | |
1202 fty = TY.Tfloat64; | |
1203 goto Lagain; | |
1204 case X(TY.Tcomplex64,TY.Timaginary32): | |
1205 case X(TY.Tcomplex64,TY.Timaginary64): | |
1206 case X(TY.Tcomplex64,TY.Timaginary80): | |
1207 e = el_una(OPER.OPc_i, TYM.TYidouble, e); | |
1208 fty = TY.Timaginary64; | |
1209 goto Lagain; | |
1210 case X(TY.Tcomplex64,TY.Tcomplex32): | |
1211 eop = OPER.OPd_f; | |
1212 goto Leop; | |
1213 case X(TY.Tcomplex64,TY.Tcomplex80): | |
1214 eop = OPER.OPd_ld; | |
1215 goto Leop; | |
1216 | |
1217 /* ============================= */ | |
1218 | |
1219 case X(TY.Tcomplex80,TY.Tint8): | |
1220 case X(TY.Tcomplex80,TY.Tuns8): | |
1221 case X(TY.Tcomplex80,TY.Tint16): | |
1222 case X(TY.Tcomplex80,TY.Tuns16): | |
1223 case X(TY.Tcomplex80,TY.Tint32): | |
1224 case X(TY.Tcomplex80,TY.Tuns32): | |
1225 case X(TY.Tcomplex80,TY.Tint64): | |
1226 case X(TY.Tcomplex80,TY.Tuns64): | |
1227 case X(TY.Tcomplex80,TY.Tfloat32): | |
1228 case X(TY.Tcomplex80,TY.Tfloat64): | |
1229 case X(TY.Tcomplex80,TY.Tfloat80): | |
1230 e = el_una(OPER.OPc_r, TYM.TYldouble, e); | |
1231 fty = TY.Tfloat80; | |
1232 goto Lagain; | |
1233 case X(TY.Tcomplex80,TY.Timaginary32): | |
1234 case X(TY.Tcomplex80,TY.Timaginary64): | |
1235 case X(TY.Tcomplex80,TY.Timaginary80): | |
1236 e = el_una(OPER.OPc_i, TYM.TYildouble, e); | |
1237 fty = TY.Timaginary80; | |
1238 goto Lagain; | |
1239 case X(TY.Tcomplex80,TY.Tcomplex32): | |
1240 case X(TY.Tcomplex80,TY.Tcomplex64): | |
1241 e = el_una(OPER.OPld_d, TYM.TYcdouble, e); | |
1242 fty = TY.Tcomplex64; | |
1243 goto Lagain; | |
1244 | |
1245 /* ============================= */ | |
1246 | |
1247 default: | |
1248 if (fty == tty) | |
1249 goto Lpaint; | |
1250 //dump(0); | |
79 | 1251 //writef("fty = %d, tty = %d, %d\n", fty, tty, t.ty); |
1252 error("e2ir: cannot cast %s of type %s to type %s", e1.toChars(), e1.type.toChars(), t.toChars()); | |
72 | 1253 goto Lzero; |
1254 | |
1255 Lzero: | |
1256 e = el_long(ttym, 0); | |
1257 break; | |
1258 | |
1259 Lpaint: | |
1260 e.Ety = ttym; | |
1261 break; | |
1262 | |
1263 Leop: | |
1264 e = el_una(eop, ttym, e); | |
1265 break; | |
1266 } | |
1267 Lret: | |
1268 // Adjust for any type paints | |
1269 t = type.toBasetype(); | |
1270 e.Ety = t.totym(); | |
1271 | |
1272 el_setLoc(e,loc); | |
0 | 1273 return e; |
1274 } | |
1275 | |
72 | 1276 override Identifier opId() |
0 | 1277 { |
1278 return Id.cast_; | |
1279 } | |
1280 } | |
1281 |