mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-04-17 17:29:02 +02:00
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
auto ma = new int[][] (3,9);
This commit is contained in:
@@ -477,6 +477,48 @@ DSliceValue* DtoNewDynArray(Type* arrayType, DValue* dim, bool defaultInit)
|
||||
return new DSliceValue(arrayType, arrayLen, newptr);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
DSliceValue* DtoNewMulDimDynArray(Type* arrayType, DValue** dims, size_t ndims, bool defaultInit)
|
||||
{
|
||||
Logger::println("DtoNewMulDimDynArray : %s", arrayType->toChars());
|
||||
LOG_SCOPE;
|
||||
|
||||
// typeinfo arg
|
||||
LLValue* arrayTypeInfo = DtoTypeInfoOf(arrayType);
|
||||
|
||||
// get runtime function
|
||||
bool zeroInit = arrayType->toBasetype()->nextOf()->isZeroInit();
|
||||
LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, zeroInit ? "_d_newarraymT" : "_d_newarraymiT" );
|
||||
|
||||
// build dims
|
||||
LLValue* dimsArg = new llvm::AllocaInst(DtoSize_t(), DtoConstUint(ndims), ".newdims", gIR->topallocapoint());
|
||||
for (size_t i=0; i<ndims; ++i)
|
||||
{
|
||||
LLValue* dim = dims[i]->getRVal();
|
||||
DtoStore(dim, DtoGEPi1(dimsArg, i));
|
||||
}
|
||||
|
||||
// call allocator
|
||||
LLConstant* arrayLen = DtoConstSize_t(ndims);
|
||||
LLValue* newptr = gIR->ir->CreateCall3(fn, arrayTypeInfo, arrayLen, dimsArg, ".gc_mem");
|
||||
|
||||
// cast to wanted type
|
||||
const LLType* dstType = DtoType(arrayType)->getContainedType(1);
|
||||
if (newptr->getType() != dstType)
|
||||
newptr = DtoBitCast(newptr, dstType, ".gc_mem");
|
||||
|
||||
Logger::cout() << "final ptr = " << *newptr << '\n';
|
||||
|
||||
#if 0
|
||||
if (defaultInit) {
|
||||
DValue* e = dty->defaultInit()->toElem(gIR);
|
||||
DtoArrayInit(newptr,dim,e->getRVal());
|
||||
}
|
||||
#endif
|
||||
|
||||
return new DSliceValue(arrayType, arrayLen, newptr);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
DSliceValue* DtoResizeDynArray(Type* arrayType, DValue* array, DValue* newdim)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user