Mercurial > projects > ldc
changeset 1203:d51b5fa41657
Implement static array -> static array cast. Fixes #223.
dynamic array -> static array is still misssing!
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 12 Apr 2009 16:18:02 +0200 |
parents | 7c7072437a89 |
children | 498c484f3a03 |
files | gen/arrays.cpp |
diffstat | 1 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/gen/arrays.cpp Sun Apr 12 14:58:18 2009 +0200 +++ b/gen/arrays.cpp Sun Apr 12 16:18:02 2009 +0200 @@ -939,7 +939,26 @@ else if (totype->ty == Tsarray) { if (Logger::enabled()) Logger::cout() << "to sarray" << '\n'; - assert(0); + + if (fromtype->ty == Tsarray) { + LLValue* uval = u->getRVal(); + + if (Logger::enabled()) + Logger::cout() << "uvalTy = " << *uval->getType() << '\n'; + + assert(isaPointer(uval->getType())); + const LLArrayType* arrty = isaArray(uval->getType()->getContainedType(0)); + + if(arrty->getNumElements()*fromtype->nextOf()->size() % totype->nextOf()->size() != 0) + { + error(loc, "invalid cast from '%s' to '%s', the element sizes don't line up", fromtype->toChars(), totype->toChars()); + fatal(); + } + + rval = DtoBitCast(uval, getPtrToType(tolltype)); + } + else + assert(0 && "Cast to static array not implemented!"); } else if (totype->ty == Tbool) { // return (arr.ptr !is null)