# HG changeset patch # User lindquist # Date 1192804635 -7200 # Node ID ff359b65fa6270d3034e741cf1d14f2bafb930ca # Parent ea65e12b0dd08b8c1dce5a09fc2c85c95fe59f7a [svn r49] foreach on dynamic arrays diff -r ea65e12b0dd0 -r ff359b65fa62 gen/statements.c --- a/gen/statements.c Fri Oct 19 16:05:06 2007 +0200 +++ b/gen/statements.c Fri Oct 19 16:37:15 2007 +0200 @@ -651,7 +651,8 @@ const llvm::Type* valtype = LLVM_DtoType(value->type); llvm::Value* valvar = new llvm::AllocaInst(keytype, "foreachval", p->topallocapoint()); - if (LLVM_DtoDType(aggr->type)->ty == Tsarray) + Type* aggrtype = LLVM_DtoDType(aggr->type); + if (aggrtype->ty == Tsarray) { assert(llvm::isa(val->getType())); assert(llvm::isa(val->getType()->getContainedType(0))); @@ -659,9 +660,14 @@ assert(n > 0); numiters = llvm::ConstantInt::get(keytype,n,false); } + else if (aggrtype->ty == Tarray) + { + numiters = p->ir->CreateLoad(LLVM_DtoGEPi(val,0,0,"tmp",p->scopebb())); + val = p->ir->CreateLoad(LLVM_DtoGEPi(val,0,1,"tmp",p->scopebb())); + } else { - assert(0); + assert(0 && "aggregate type is not Tarray or Tsarray"); } if (op == TOKforeach) { @@ -701,7 +707,11 @@ p->scope() = IRScope(begbb,nexbb); // get value for this iteration - value->llvmValue = LLVM_DtoGEP(val,llvm::ConstantInt::get(keytype,0,false),new llvm::LoadInst(keyvar,"tmp",p->scopebb()),"tmp",p->scopebb()); + llvm::Constant* zero = llvm::ConstantInt::get(keytype,0,false); + if (aggrtype->ty == Tsarray) + value->llvmValue = LLVM_DtoGEP(val,zero,new llvm::LoadInst(keyvar,"tmp",p->scopebb()),"tmp",p->scopebb()); + else if (aggrtype->ty == Tarray) + value->llvmValue = new llvm::GetElementPtrInst(val,new llvm::LoadInst(keyvar,"tmp",p->scopebb()),"tmp",p->scopebb()); // body p->scope() = IRScope(p->scopebb(),endbb);