mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-02 08:01:11 +03:00
Refactoring-only part of DtoConstExpInit fix.
This commit is contained in:
parent
d9ce9ce67b
commit
ae48a19251
2 changed files with 17 additions and 22 deletions
|
@ -1308,18 +1308,11 @@ LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init)
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static LLConstant* expand_to_sarray(Type *base, Expression* exp)
|
static LLConstant* expand_to_sarray(Type* targetType, Type* initType, LLConstant* initConst)
|
||||||
{
|
{
|
||||||
Logger::println("building type %s from expression (%s) of type %s", base->toChars(), exp->toChars(), exp->type->toChars());
|
Type* expbase = stripModifiers(initType);
|
||||||
LLType* dstTy = DtoType(base);
|
IF_LOG Logger::println("expbase: %s", expbase->toChars());
|
||||||
if (Logger::enabled())
|
Type* t = targetType;
|
||||||
Logger::cout() << "final llvm type requested: " << *dstTy << '\n';
|
|
||||||
|
|
||||||
LLConstant* val = exp->toConstElem(gIR);
|
|
||||||
|
|
||||||
Type* expbase = stripModifiers(exp->type->toBasetype());
|
|
||||||
Logger::println("expbase: %s", expbase->toChars());
|
|
||||||
Type* t = base->toBasetype();
|
|
||||||
|
|
||||||
LLSmallVector<size_t, 4> dims;
|
LLSmallVector<size_t, 4> dims;
|
||||||
|
|
||||||
|
@ -1341,19 +1334,21 @@ static LLConstant* expand_to_sarray(Type *base, Expression* exp)
|
||||||
std::vector<LLConstant*> inits;
|
std::vector<LLConstant*> inits;
|
||||||
while (i--)
|
while (i--)
|
||||||
{
|
{
|
||||||
LLArrayType* arrty = LLArrayType::get(val->getType(), dims[i]);
|
LLArrayType* arrty = LLArrayType::get(initConst->getType(), dims[i]);
|
||||||
inits.clear();
|
inits.clear();
|
||||||
inits.insert(inits.end(), dims[i], val);
|
inits.insert(inits.end(), dims[i], initConst);
|
||||||
val = LLConstantArray::get(arrty, inits);
|
initConst = LLConstantArray::get(arrty, inits);
|
||||||
}
|
}
|
||||||
|
|
||||||
return val;
|
return initConst;
|
||||||
}
|
}
|
||||||
|
|
||||||
LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp)
|
LLConstant* DtoConstExpInit(Loc loc, Type* targetType, Expression* exp)
|
||||||
{
|
{
|
||||||
|
LLConstant* val = exp->toConstElem(gIR);
|
||||||
|
|
||||||
Type* expbase = stripModifiers(exp->type->toBasetype())->merge();
|
Type* expbase = stripModifiers(exp->type->toBasetype())->merge();
|
||||||
Type* base = stripModifiers(type->toBasetype())->merge();
|
Type* base = stripModifiers(targetType->toBasetype())->merge();
|
||||||
|
|
||||||
// if not the same basetypes, we won't get the same llvm types either
|
// if not the same basetypes, we won't get the same llvm types either
|
||||||
if (!expbase->equals(base))
|
if (!expbase->equals(base))
|
||||||
|
@ -1365,12 +1360,12 @@ LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp)
|
||||||
fatal();
|
fatal();
|
||||||
}
|
}
|
||||||
Logger::println("type is a static array, building constant array initializer to single value");
|
Logger::println("type is a static array, building constant array initializer to single value");
|
||||||
return expand_to_sarray(base, exp);
|
return expand_to_sarray(base, expbase, val);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base->ty == Tvector)
|
if (base->ty == Tvector)
|
||||||
{
|
{
|
||||||
LLConstant* val = exp->toConstElem(gIR);
|
|
||||||
|
|
||||||
TypeVector* tv = (TypeVector*)base;
|
TypeVector* tv = (TypeVector*)base;
|
||||||
assert(tv->basetype->ty == Tsarray);
|
assert(tv->basetype->ty == Tsarray);
|
||||||
|
@ -1386,11 +1381,11 @@ LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp)
|
||||||
}
|
}
|
||||||
|
|
||||||
error(loc, "LDC internal error: cannot yet convert default initializer %s of type %s to %s",
|
error(loc, "LDC internal error: cannot yet convert default initializer %s of type %s to %s",
|
||||||
exp->toChars(), exp->type->toChars(), type->toChars());
|
exp->toChars(), exp->type->toChars(), targetType->toChars());
|
||||||
llvm_unreachable("Unsupported default initializer.");
|
llvm_unreachable("Unsupported default initializer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return exp->toConstElem(gIR);
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -115,7 +115,7 @@ LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr = 0);
|
||||||
|
|
||||||
// initializer helpers
|
// initializer helpers
|
||||||
LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init);
|
LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init);
|
||||||
LLConstant* DtoConstExpInit(Loc loc, Type* t, Expression* exp);
|
LLConstant* DtoConstExpInit(Loc loc, Type* targetType, Expression* exp);
|
||||||
|
|
||||||
// getting typeinfo of type, base=true casts to object.TypeInfo
|
// getting typeinfo of type, base=true casts to object.TypeInfo
|
||||||
LLConstant* DtoTypeInfoOf(Type* ty, bool base=true);
|
LLConstant* DtoTypeInfoOf(Type* ty, bool base=true);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue