mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-03-01 18:13:18 +01:00
Refactor struct initializers codegen.
This not only reduces code duplication, but the unification also enables code a la StructLiteralExp to handle classes (for CTFE class constant support in 2.063).
This commit is contained in:
10
gen/toir.cpp
10
gen/toir.cpp
@@ -2946,22 +2946,18 @@ LLConstant* StructLiteralExp::toConstElem(IRState* p)
|
||||
// make sure the struct is resolved
|
||||
sd->codegen(Type::sir);
|
||||
|
||||
// get inits
|
||||
llvm::SmallVector<IrTypeStruct::VarInitConst, 16> varInits;
|
||||
std::map<VarDeclaration*, llvm::Constant*> varInits;
|
||||
|
||||
size_t nexprs = elements->dim;
|
||||
for (size_t i = 0; i < nexprs; i++)
|
||||
{
|
||||
if ((*elements)[i])
|
||||
{
|
||||
IrTypeStruct::VarInitConst v;
|
||||
v.first = sd->fields[i];
|
||||
v.second = (*elements)[i]->toConstElem(p);
|
||||
varInits.push_back(v);
|
||||
varInits[sd->fields[i]] = (*elements)[i]->toConstElem(p);
|
||||
}
|
||||
}
|
||||
|
||||
return sd->type->irtype->isStruct()->createInitializerConstant(varInits);
|
||||
return sd->ir.irStruct->createInitializerConstant(varInits);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user