Mercurial > projects > ldc
comparison gen/llvmhelpers.cpp @ 419:023fa78c1203
Fixed delegate casts.
author | Tomas Lindquist Olsen <tomas.l.olsen@gmail.com> |
---|---|
date | Mon, 28 Jul 2008 08:05:21 +0200 |
parents | 0e6b4d65d3f8 |
children | c8d98ccad0cc |
comparison
equal
deleted
inserted
replaced
418:94c4e090c1af | 419:023fa78c1203 |
---|---|
808 } | 808 } |
809 | 809 |
810 return new DImValue(to, rval); | 810 return new DImValue(to, rval); |
811 } | 811 } |
812 | 812 |
813 DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to) | |
814 { | |
815 LLValue* res = 0; | |
816 to = to->toBasetype(); | |
817 | |
818 if (to->ty == Tdelegate) | |
819 { | |
820 const LLType* toll = getPtrToType(DtoType(to)); | |
821 res = DtoBitCast(val->getRVal(), toll); | |
822 } | |
823 else | |
824 { | |
825 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); | |
826 fatal(); | |
827 } | |
828 | |
829 return new DImValue(to, res); | |
830 } | |
831 | |
813 DValue* DtoCast(Loc& loc, DValue* val, Type* to) | 832 DValue* DtoCast(Loc& loc, DValue* val, Type* to) |
814 { | 833 { |
815 Type* fromtype = DtoDType(val->getType()); | 834 Type* fromtype = DtoDType(val->getType()); |
816 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars()); | 835 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars()); |
817 if (fromtype->isintegral()) { | 836 if (fromtype->isintegral()) { |
829 else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) { | 848 else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) { |
830 return DtoCastArray(val, to); | 849 return DtoCastArray(val, to); |
831 } | 850 } |
832 else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) { | 851 else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) { |
833 return DtoCastPtr(loc, val, to); | 852 return DtoCastPtr(loc, val, to); |
853 } | |
854 else if (fromtype->ty == Tdelegate) { | |
855 return DtoCastDelegate(loc, val, to); | |
834 } | 856 } |
835 else { | 857 else { |
836 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); | 858 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); |
837 fatal(); | 859 fatal(); |
838 } | 860 } |