changeset 419:023fa78c1203

Fixed delegate casts.
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Mon, 28 Jul 2008 08:05:21 +0200
parents 94c4e090c1af
children 491264b7cb93
files gen/llvmhelpers.cpp gen/llvmhelpers.h
diffstat 2 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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();
--- 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