# HG changeset patch # User Tomas Lindquist Olsen # Date 1217225121 -7200 # Node ID 023fa78c1203a72c99e195e4a1a5f5528ce12b27 # Parent 94c4e090c1af48a5aa52dfe72ad14bb3b3215270 Fixed delegate casts. diff -r 94c4e090c1af -r 023fa78c1203 gen/llvmhelpers.cpp --- a/gen/llvmhelpers.cpp Mon Jul 28 07:25:13 2008 +0200 +++ b/gen/llvmhelpers.cpp Mon Jul 28 08:05:21 2008 +0200 @@ -810,6 +810,25 @@ return new DImValue(to, rval); } +DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to) +{ + LLValue* res = 0; + to = to->toBasetype(); + + if (to->ty == Tdelegate) + { + const LLType* toll = getPtrToType(DtoType(to)); + res = DtoBitCast(val->getRVal(), toll); + } + else + { + error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); + fatal(); + } + + return new DImValue(to, res); +} + DValue* DtoCast(Loc& loc, DValue* val, Type* to) { Type* fromtype = DtoDType(val->getType()); @@ -832,6 +851,9 @@ else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) { return DtoCastPtr(loc, val, to); } + else if (fromtype->ty == Tdelegate) { + return DtoCastDelegate(loc, val, to); + } else { error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars()); fatal(); diff -r 94c4e090c1af -r 023fa78c1203 gen/llvmhelpers.h --- a/gen/llvmhelpers.h Mon Jul 28 07:25:13 2008 +0200 +++ b/gen/llvmhelpers.h Mon Jul 28 08:05:21 2008 +0200 @@ -48,6 +48,7 @@ DValue* DtoCastInt(Loc& loc, DValue* val, Type* to); DValue* DtoCastPtr(Loc& loc, DValue* val, Type* to); DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to); +DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to); DValue* DtoCast(Loc& loc, DValue* val, Type* to); // is template instance check