Fixed delegate casts.

This commit is contained in:
Tomas Lindquist Olsen
2008-07-28 08:05:21 +02:00
parent 713dfe71b5
commit 20d429e085
2 changed files with 23 additions and 0 deletions

View File

@@ -810,6 +810,25 @@ DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to)
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 @@ DValue* DtoCast(Loc& loc, DValue* val, Type* to)
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();

View File

@@ -48,6 +48,7 @@ DValue* DtoNullValue(Type* t);
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