Mercurial > projects > ldc
diff gen/tollvm.cpp @ 113:27b9f749d9fe trunk
[svn r117] Initial working implementation of interfaces.
Groundwork for all the different types of class/interface casts laid out.
author | lindquist |
---|---|
date | Sat, 24 Nov 2007 06:33:00 +0100 |
parents | 5ab8e92611f9 |
children | 5880c12dba83 |
line wrap: on
line diff
--- a/gen/tollvm.cpp Thu Nov 22 22:30:10 2007 +0100 +++ b/gen/tollvm.cpp Sat Nov 24 06:33:00 2007 +0100 @@ -1140,11 +1140,35 @@ DValue* DtoCastClass(DValue* val, Type* _to) { - const llvm::Type* tolltype = DtoType(_to); Type* to = DtoDType(_to); - assert(to->ty == Tclass || to->ty == Tpointer); - llvm::Value* rval = new llvm::BitCastInst(val->getRVal(), tolltype, "tmp", gIR->scopebb()); - return new DImValue(_to, rval); + if (to->ty == Tpointer) { + const llvm::Type* tolltype = DtoType(_to); + llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype); + return new DImValue(_to, rval); + } + + assert(to->ty == Tclass); + TypeClass* tc = (TypeClass*)to; + + Type* from = DtoDType(val->getType()); + TypeClass* fc = (TypeClass*)from; + + if (tc->sym->isInterfaceDeclaration()) { + assert(!fc->sym->isInterfaceDeclaration()); + return DtoCastObjectToInterface(val, _to); + } + else { + if (fc->sym->isInterfaceDeclaration()) { + assert(0); + return DtoCastInterfaceToObject(val); + } + else { + const llvm::Type* tolltype = DtoType(_to); + assert(to->ty == Tclass); + llvm::Value* rval = DtoBitCast(val->getRVal(), tolltype); + return new DImValue(_to, rval); + } + } } DValue* DtoCast(DValue* val, Type* to)