From 39661855c0816ac248be437704c76f58359cb5f0 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 06:52:23 +0000 Subject: feat(classes): construct declared objects and nested fields and arrays Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/ArrayHandler.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lib/CodeGen/ArrayHandler.cc') diff --git a/lib/CodeGen/ArrayHandler.cc b/lib/CodeGen/ArrayHandler.cc index 5eb8a52..337e5f4 100644 --- a/lib/CodeGen/ArrayHandler.cc +++ b/lib/CodeGen/ArrayHandler.cc @@ -139,6 +139,24 @@ void ArrayHandler::emitArrayDeclare(ArrayDeclareStmtAST *Stmt, CodeGen &CG) { Builder->CreateStore(Ptr, Alloca); CG.registerSymbol(Name, Alloca, ElemInfo->Name, true); + if (CG.typeNeedsConstruction(ElemInfo->Name)) { + BasicBlock *Preheader = Builder->GetInsertBlock(); + BasicBlock *Loop = BasicBlock::Create(*TheContext, "construct_elements", TheFunction); + BasicBlock *Body = BasicBlock::Create(*TheContext, "construct_element", TheFunction); + BasicBlock *Done = BasicBlock::Create(*TheContext, "constructed_array", TheFunction); + Builder->CreateBr(Loop); + Builder->SetInsertPoint(Loop); + auto *Index = Builder->CreatePHI(Type::getInt64Ty(*TheContext), 2, "construct_index"); + Index->addIncoming(ConstantInt::get(Type::getInt64Ty(*TheContext), 0), Preheader); + Builder->CreateCondBr(Builder->CreateICmpULT(Index, TotalElements), Body, Done); + Builder->SetInsertPoint(Body); + Value *Element = Builder->CreateGEP(ElemInfo->LLVMType, Ptr, Index); + CG.emitDefaultConstruct(ElemInfo->Name, Element, Stmt->getLine()); + Value *Next = Builder->CreateAdd(Index, ConstantInt::get(Type::getInt64Ty(*TheContext), 1)); + Index->addIncoming(Next, Builder->GetInsertBlock()); + Builder->CreateBr(Loop); + Builder->SetInsertPoint(Done); + } } void ArrayHandler::computeDimsAndMultipliers(const std::string &Name, -- cgit v1.3.1-4-g156e