Mercurial > projects > ddmd
comparison dmd/CastExp.d @ 79:43073c7c7769
updated to 2.035
also implemented a few missing functions
still crashes in Import.importAll though
author | Trass3r |
---|---|
date | Mon, 30 Aug 2010 03:57:51 +0200 |
parents | ef02e2e203c2 |
children | ceda59b4d255 |
comparison
equal
deleted
inserted
replaced
78:b98fa8a4bf04 | 79:43073c7c7769 |
---|---|
9 import dmd.CallExp; | 9 import dmd.CallExp; |
10 import dmd.Global; | 10 import dmd.Global; |
11 import dmd.Id; | 11 import dmd.Id; |
12 import dmd.Identifier; | 12 import dmd.Identifier; |
13 import dmd.BinExp; | 13 import dmd.BinExp; |
14 import dmd.backend.elem; | |
15 import dmd.UnaExp; | 14 import dmd.UnaExp; |
16 import dmd.VarExp; | 15 import dmd.VarExp; |
17 import dmd.Token; | 16 import dmd.Token; |
18 import dmd.VarDeclaration; | 17 import dmd.VarDeclaration; |
19 import dmd.InterState; | 18 import dmd.InterState; |
33 | 32 |
34 import dmd.Optimize; | 33 import dmd.Optimize; |
35 import dmd.PREC; | 34 import dmd.PREC; |
36 import dmd.Cast; | 35 import dmd.Cast; |
37 | 36 |
37 import dmd.codegen.Util; | |
38 import dmd.backend.elem; | |
39 import dmd.backend.mTY; | |
38 import dmd.backend.Util; | 40 import dmd.backend.Util; |
39 import dmd.expression.Util; | |
40 import dmd.backend.TYM; | 41 import dmd.backend.TYM; |
41 import dmd.backend.OPER; | 42 import dmd.backend.OPER; |
42 import dmd.codegen.Util; | |
43 import dmd.backend.RTLSYM; | 43 import dmd.backend.RTLSYM; |
44 import dmd.expression.Util; | |
44 | 45 |
45 class CastExp : UnaExp | 46 class CastExp : UnaExp |
46 { | 47 { |
47 // Possible to cast to one type while painting to another type | 48 // Possible to cast to one type while painting to another type |
48 Type to; // type to cast to | 49 Type to; // type to cast to |
443 return ((fty) * TY.TMAX + (tty)); | 444 return ((fty) * TY.TMAX + (tty)); |
444 } | 445 } |
445 | 446 |
446 override elem* toElem(IRState* irs) | 447 override elem* toElem(IRState* irs) |
447 { | 448 { |
448 elem* e; | |
449 TY fty; | 449 TY fty; |
450 TY tty; | 450 TY tty; |
451 tym_t ftym; | 451 tym_t ftym; |
452 tym_t ttym; | 452 tym_t ttym; |
453 OPER eop; | 453 OPER eop; |
454 Type t; | 454 |
455 Type tfrom; | 455 static if (false) |
456 | 456 { |
457 static if (false) { | |
458 printf("CastExp::toElem()\n"); | 457 printf("CastExp::toElem()\n"); |
459 print(); | 458 print(); |
460 printf("\tfrom: %s\n", e1.type.toChars()); | 459 printf("\tfrom: %s\n", e1.type.toChars()); |
461 printf("\tto : %s\n", to.toChars()); | 460 printf("\tto : %s\n", to.toChars()); |
462 } | 461 } |
463 | 462 |
464 e = e1.toElem(irs); | 463 elem* e = e1.toElem(irs); |
465 tfrom = e1.type.toBasetype(); | 464 Type tfrom = e1.type.toBasetype(); |
466 t = to.toBasetype(); // skip over typedef's | 465 Type t = to.toBasetype(); // skip over typedef's |
467 if (t.equals(tfrom)) | 466 if (t.equals(tfrom)) |
468 goto Lret; | 467 goto Lret; |
469 | 468 |
470 fty = tfrom.ty; | 469 fty = tfrom.ty; |
471 //printf("fty = %d\n", fty); | 470 //printf("fty = %d\n", fty); |
523 e = el_bin(OPER.OPcall, type.totym(), el_var(rtlsym[RTLSYM.RTLSYM_ARRAYCAST]), ep); | 522 e = el_bin(OPER.OPcall, type.totym(), el_var(rtlsym[RTLSYM.RTLSYM_ARRAYCAST]), ep); |
524 } | 523 } |
525 goto Lret; | 524 goto Lret; |
526 } | 525 } |
527 | 526 |
528 static if (false) { | 527 static if (false) |
528 { | |
529 // Convert from dynamic array string literal to static array | 529 // Convert from dynamic array string literal to static array |
530 if (tty == TY.Tsarray && fty == TY.Tarray && e1.op == TOK.TOKstring) | 530 if (tty == TY.Tsarray && fty == TY.Tarray && e1.op == TOK.TOKstring) |
531 { | 531 { |
532 goto Lret; // treat as a 'paint' | 532 goto Lret; // treat as a 'paint' |
533 } | 533 } |
605 ep = el_param(el_ptr(cdto.toSymbol()), e); | 605 ep = el_param(el_ptr(cdto.toSymbol()), e); |
606 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[rtl]), ep); | 606 e = el_bin(OPER.OPcall, TYM.TYnptr, el_var(rtlsym[rtl]), ep); |
607 goto Lret; | 607 goto Lret; |
608 } | 608 } |
609 | 609 |
610 ftym = e.Ety; | 610 ftym = tybasic(e.Ety); |
611 ttym = t.totym(); | 611 ttym = tybasic(t.totym()); |
612 if (ftym == ttym) | 612 if (ftym == ttym) |
613 goto Lret; | 613 goto Lret; |
614 | 614 |
615 switch (tty) | 615 switch (tty) |
616 { | 616 { |
655 } | 655 } |
656 | 656 |
657 Lagain: | 657 Lagain: |
658 switch (X(fty,tty)) | 658 switch (X(fty,tty)) |
659 { | 659 { |
660 static if (false) { | 660 static if (false) |
661 { | |
661 case X(TY.Tbit,TY.Tint8): | 662 case X(TY.Tbit,TY.Tint8): |
662 case X(TY.Tbit,TY.Tuns8): | 663 case X(TY.Tbit,TY.Tuns8): |
663 goto Lpaint; | 664 goto Lpaint; |
664 case X(TY.Tbit,TY.Tint16): | 665 case X(TY.Tbit,TY.Tint16): |
665 case X(TY.Tbit,TY.Tuns16): | 666 case X(TY.Tbit,TY.Tuns16): |
1219 | 1220 |
1220 default: | 1221 default: |
1221 if (fty == tty) | 1222 if (fty == tty) |
1222 goto Lpaint; | 1223 goto Lpaint; |
1223 //dump(0); | 1224 //dump(0); |
1224 //printf("fty = %d, tty = %d\n", fty, tty); | 1225 //writef("fty = %d, tty = %d, %d\n", fty, tty, t.ty); |
1225 error("e2ir: cannot cast from %s to %s", e1.type.toChars(), t.toChars()); | 1226 error("e2ir: cannot cast %s of type %s to type %s", e1.toChars(), e1.type.toChars(), t.toChars()); |
1226 goto Lzero; | 1227 goto Lzero; |
1227 | 1228 |
1228 Lzero: | 1229 Lzero: |
1229 e = el_long(ttym, 0); | 1230 e = el_long(ttym, 0); |
1230 break; | 1231 break; |