mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-02 16:11:08 +03:00
Get rid of now-obsolete DtoConstInitializerType.
This commit is contained in:
parent
eef05ba019
commit
41e580a79f
3 changed files with 0 additions and 134 deletions
|
@ -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<TypeSArray*>(arrty);
|
||||
size_t arrlen = static_cast<size_t>(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<LLType*> 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<Expression*>(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<Initializer*>(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());
|
||||
|
|
|
@ -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<TypeTypedef*>(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<TypeSArray*>(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<TypeStruct*>(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<StructLiteralExp*>(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<VarExp*>(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
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue