diff --git a/gen/arrays.cpp b/gen/arrays.cpp index 53daa91d19..2dbc8efd6c 100644 --- a/gen/arrays.cpp +++ b/gen/arrays.cpp @@ -263,85 +263,6 @@ void DtoSetArray(DValue* array, LLValue* dim, LLValue* ptr) ////////////////////////////////////////////////////////////////////////////////////////// -// The function is almost identical copy of DtoConstArrayInitializer but it returns -// initializer type not the initializer itself. -// FIXME: is there any way to merge this next two functions? -LLType* DtoConstArrayInitializerType(ArrayInitializer* arrinit) -{ - Type* arrty = arrinit->type->toBasetype(); - if (arrty->ty != Tsarray) - return DtoType(arrinit->type); - - TypeSArray* tsa = static_cast(arrty); - size_t arrlen = static_cast(tsa->dim->toInteger()); - - // get elem type - Type* elemty = arrty->nextOf(); - LLType* llelemty = DtoTypeNotVoid(elemty); - - // make sure the number of initializers is sane - if (arrinit->index.dim > arrlen || arrinit->dim > arrlen) - { - error(arrinit->loc, "too many initializers, %u, for array[%zu]", arrinit->index.dim, arrlen); - fatal(); - } - - // true if array elements differ in type, can happen with array of unions - bool mismatch = false; - - // allocate room for types - std::vector types(arrlen, NULL); - - // go through each initializer, they're not sorted by index by the frontend - size_t j = 0; - for (size_t i = 0; i < arrinit->index.dim; i++) - { - // get index - Expression* idx = static_cast(arrinit->index.data[i]); - - // idx can be null, then it's just the next element - if (idx) - j = idx->toInteger(); - assert(j < arrlen); - - // get value - Initializer* val = static_cast(arrinit->value.data[i]); - assert(val); - - LLType* c = DtoConstInitializerType(elemty, val); - assert(c); - if (c != llelemty) - mismatch = true; - - types[j] = c; - j++; - } - - // fill out any null entries still left with default type - - // element default types - LLType* deftype = DtoConstInitializerType(elemty, 0); - bool mismatch2 = (deftype != llelemty); - - for (size_t i = 0; i < arrlen; i++) - { - if (types[i] != NULL) - continue; - - types[i] = deftype; - - if (mismatch2) - mismatch = true; - } - - if (mismatch) - return LLStructType::get(gIR->context(), types); // FIXME should this pack? - else - return LLArrayType::get(deftype, arrlen); -} - -////////////////////////////////////////////////////////////////////////////////////////// - LLConstant* DtoConstArrayInitializer(ArrayInitializer* arrinit) { Logger::println("DtoConstArrayInitializer: %s | %s", arrinit->toChars(), arrinit->type->toChars()); diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index 90546920f0..c36d56415d 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -1304,60 +1304,6 @@ LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr) // INITIALIZER HELPERS ////////////////////////////////////////////////////////////////////////////////////////*/ -LLType* DtoConstInitializerType(Type* type, Initializer* init) -{ - if (type->ty == Ttypedef) { - TypeTypedef *td = static_cast(type); - if (td->sym->init) - return DtoConstInitializerType(td->sym->basetype, td->sym->init); - } - - type = type->toBasetype(); - if (type->ty == Tsarray) - { - if (!init) - { - TypeSArray *tsa = static_cast(type); - LLType *llnext = DtoConstInitializerType(type->nextOf(), init); - return LLArrayType::get(llnext, tsa->dim->toUInteger()); - } - else if (ArrayInitializer* ai = init->isArrayInitializer()) - { - return DtoConstArrayInitializerType(ai); - } - } - else if (type->ty == Tstruct) - { - if (!init) - { - LdefaultInit: - TypeStruct *ts = static_cast(type); - DtoResolveStruct(ts->sym); - return ts->sym->ir.irStruct->getDefaultInit()->getType(); - } - else if (ExpInitializer* ex = init->isExpInitializer()) - { - if (ex->exp->op == TOKstructliteral) { - StructLiteralExp* le = static_cast(ex->exp); - if (!le->constType) - le->constType = LLStructType::create(gIR->context(), std::string(type->toChars()) + "_init"); - return le->constType; - } else if (ex->exp->op == TOKvar) { - if (static_cast(ex->exp)->var->isStaticStructInitDeclaration()) - goto LdefaultInit; - } - } - else if (StructInitializer* si = init->isStructInitializer()) - { - if (!si->ltype) - si->ltype = LLStructType::create(gIR->context(), std::string(type->toChars()) + "_init"); - return si->ltype; - } - } - - return DtoTypeNotVoid(type); -} - LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init) { LLConstant* _init = 0; // may return zero diff --git a/gen/llvmhelpers.h b/gen/llvmhelpers.h index ab4c8d453d..efd37be229 100644 --- a/gen/llvmhelpers.h +++ b/gen/llvmhelpers.h @@ -117,7 +117,6 @@ DValue* DtoDeclarationExp(Dsymbol* declaration); LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr = 0); // initializer helpers -LLType* DtoConstInitializerType(Type* type, Initializer* init); LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init); LLConstant* DtoConstExpInit(Loc loc, Type* t, Expression* exp); DValue* DtoInitializer(LLValue* target, Initializer* init);