Mercurial > projects > ldc
comparison gen/classes.cpp @ 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 | 68a0e361fdce |
children | 3af4ad55a004 |
comparison
equal
deleted
inserted
replaced
1388:5a54b39af6d6 | 1389:0bafe24a329f |
---|---|
251 | 251 |
252 Type* to = _to->toBasetype(); | 252 Type* to = _to->toBasetype(); |
253 | 253 |
254 // class -> pointer | 254 // class -> pointer |
255 if (to->ty == Tpointer) { | 255 if (to->ty == Tpointer) { |
256 Logger::println("to pointer"); | 256 IF_LOG Logger::println("to pointer"); |
257 const LLType* tolltype = DtoType(_to); | 257 const LLType* tolltype = DtoType(_to); |
258 LLValue* rval = DtoBitCast(val->getRVal(), tolltype); | 258 LLValue* rval = DtoBitCast(val->getRVal(), tolltype); |
259 return new DImValue(_to, rval); | 259 return new DImValue(_to, rval); |
260 } | 260 } |
261 // class -> bool | 261 // class -> bool |
262 else if (to->ty == Tbool) { | 262 else if (to->ty == Tbool) { |
263 Logger::println("to bool"); | 263 IF_LOG Logger::println("to bool"); |
264 LLValue* llval = val->getRVal(); | 264 LLValue* llval = val->getRVal(); |
265 LLValue* zero = LLConstant::getNullValue(llval->getType()); | 265 LLValue* zero = LLConstant::getNullValue(llval->getType()); |
266 return new DImValue(_to, gIR->ir->CreateICmpNE(llval, zero, "tmp")); | 266 return new DImValue(_to, gIR->ir->CreateICmpNE(llval, zero, "tmp")); |
267 } | |
268 // class -> integer | |
269 else if (to->isintegral()) { | |
270 IF_LOG Logger::println("to %s", to->toChars()); | |
271 | |
272 // get class ptr | |
273 LLValue* v = val->getRVal(); | |
274 // cast to size_t | |
275 v = gIR->ir->CreatePtrToInt(v, DtoSize_t(), ""); | |
276 // cast to the final int type | |
277 DImValue im(Type::tsize_t, v); | |
278 Loc loc; | |
279 return DtoCastInt(loc, &im, _to); | |
267 } | 280 } |
268 | 281 |
269 // must be class/interface | 282 // must be class/interface |
270 assert(to->ty == Tclass); | 283 assert(to->ty == Tclass); |
271 TypeClass* tc = (TypeClass*)to; | 284 TypeClass* tc = (TypeClass*)to; |