Mercurial > projects > ldc
changeset 1389:0bafe24a329f
Fixed class -> integer casts.
author | Tomas Lindquist Olsen <tomas.l.olsen gmail com> |
---|---|
date | Sun, 17 May 2009 22:02:03 +0200 |
parents | 5a54b39af6d6 |
children | c5a92bee639d |
files | gen/classes.cpp |
diffstat | 1 files changed, 15 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/gen/classes.cpp Sun May 17 17:55:53 2009 +0200 +++ b/gen/classes.cpp Sun May 17 22:02:03 2009 +0200 @@ -253,18 +253,31 @@ // class -> pointer if (to->ty == Tpointer) { - Logger::println("to pointer"); + IF_LOG Logger::println("to pointer"); const LLType* tolltype = DtoType(_to); LLValue* rval = DtoBitCast(val->getRVal(), tolltype); return new DImValue(_to, rval); } // class -> bool else if (to->ty == Tbool) { - Logger::println("to bool"); + IF_LOG Logger::println("to bool"); LLValue* llval = val->getRVal(); LLValue* zero = LLConstant::getNullValue(llval->getType()); return new DImValue(_to, gIR->ir->CreateICmpNE(llval, zero, "tmp")); } + // class -> integer + else if (to->isintegral()) { + IF_LOG Logger::println("to %s", to->toChars()); + + // get class ptr + LLValue* v = val->getRVal(); + // cast to size_t + v = gIR->ir->CreatePtrToInt(v, DtoSize_t(), ""); + // cast to the final int type + DImValue im(Type::tsize_t, v); + Loc loc; + return DtoCastInt(loc, &im, _to); + } // must be class/interface assert(to->ty == Tclass);