# HG changeset patch # User Tomas Lindquist Olsen # Date 1242590523 -7200 # Node ID 0bafe24a329f438cf4eb0b5eca3f992b45ab8318 # Parent 5a54b39af6d66074f21661b00d0368c1c0bfc8c0 Fixed class -> integer casts. diff -r 5a54b39af6d6 -r 0bafe24a329f gen/classes.cpp --- 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);