comparison gen/arrays.cpp @ 286:a3b7c19c866c trunk

[svn r307] Fixed: multidimensional new expressions now work. Eg.: auto ma = new int[][] (3,9);
author lindquist
date Sat, 21 Jun 2008 04:47:14 +0200
parents 10554729bd02
children 00eb2c967c3a
comparison
equal deleted inserted replaced
285:297690b5d4a5 286:a3b7c19c866c
476 476
477 return new DSliceValue(arrayType, arrayLen, newptr); 477 return new DSliceValue(arrayType, arrayLen, newptr);
478 } 478 }
479 479
480 ////////////////////////////////////////////////////////////////////////////////////////// 480 //////////////////////////////////////////////////////////////////////////////////////////
481 DSliceValue* DtoNewMulDimDynArray(Type* arrayType, DValue** dims, size_t ndims, bool defaultInit)
482 {
483 Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars());
484 LOG_SCOPE;
485
486 // typeinfo arg
487 LLValue* arrayTypeInfo = DtoTypeInfoOf(arrayType);
488
489 // get runtime function
490 bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
491 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarraymT" : "_d_newarraymiT" );
492
493 // build dims
494 LLValue* dimsArg = new llvm::AllocaInst(DtoSize_t(), DtoConstUint(ndims), ".newdims", gIR->topallocapoint());
495 for (size_t i=0; i<ndims; ++i)
496 {
497 LLValue* dim = dims[i]->getRVal();
498 DtoStore(dim, DtoGEPi1(dimsArg, i));
499 }
500
501 // call allocator
502 LLConstant* arrayLen = DtoConstSize_t(ndims);
503 LLValue* newptr = gIR->ir->CreateCall3(fn, arrayTypeInfo, arrayLen, dimsArg, ".gc_mem");
504
505 // cast to wanted type
506 const LLType* dstType = DtoType(arrayType)->getContainedType(1);
507 if (newptr->getType() != dstType)
508 newptr = DtoBitCast(newptr, dstType, ".gc_mem");
509
510 Logger::cout() << "final ptr = " << *newptr << '\n';
511
512 #if 0
513 if (defaultInit) {
514 DValue* e = dty->defaultInit()->toElem(gIR);
515 DtoArrayInit(newptr,dim,e->getRVal());
516 }
517 #endif
518
519 return new DSliceValue(arrayType, arrayLen, newptr);
520 }
521
522 //////////////////////////////////////////////////////////////////////////////////////////
481 DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim) 523 DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim)
482 { 524 {
483 Logger::println("DtoResizeDynArray : %s", arrayType->toChars()); 525 Logger::println("DtoResizeDynArray : %s", arrayType->toChars());
484 LOG_SCOPE; 526 LOG_SCOPE;
485 527