aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/StatementGen.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 08:07:50 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 08:07:50 +0000
commit345e3d419eafb0e234aecb4a33f37efe2afbbf53 (patch)
tree9330322103f26f15c6df91cbbd62bf5a1f6e72da /lib/CodeGen/StatementGen.cc
parent927e3fc0384c941f9ad313a28768660c3cdb1777 (diff)
feat(classes): add copy constructors and statement-scoped temporaries
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/StatementGen.cc')
-rw-r--r--lib/CodeGen/StatementGen.cc21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/CodeGen/StatementGen.cc b/lib/CodeGen/StatementGen.cc
index 99a269d..c0bc223 100644
--- a/lib/CodeGen/StatementGen.cc
+++ b/lib/CodeGen/StatementGen.cc
@@ -10,6 +10,12 @@ using namespace llvm;
using namespace cps;
void CodeGen::emitStmt(StmtAST *Stmt) {
+ size_t Start = StackObjects.size();
+ emitStmtImpl(Stmt);
+ cleanupTemporaries(Start);
+}
+
+void CodeGen::emitStmtImpl(StmtAST *Stmt) {
SaveAndRestore<int> Location(DiagnosticLine, Stmt && Stmt->getLine() ? Stmt->getLine() : DiagnosticLine);
if (!Stmt) return;
@@ -89,12 +95,18 @@ void CodeGen::emitStmt(StmtAST *Stmt) {
}
if (auto *Call = dynamic_cast<MemberCallStmtAST*>(Stmt)) {
- emitMemberCall(Call->getCall());
+ Value *Result = emitMemberCall(Call->getCall());
+ const TypeInfo *Type = getExprTypeInfo(Call->getCall());
+ if (Result && Type && Type->IsClass) materializeOperatorReceiver(Result, Type);
return;
}
if (auto *Call = dynamic_cast<CallStmtAST*>(Stmt)) {
- emitCall(Call->getCallee(), Call->getArgs(), Call->getLine());
+ Value *Result = emitCall(Call->getCallee(), Call->getArgs(), Call->getLine());
+ const FuncSig *Sig = FuncGen->hasFunction(Call->getCallee())
+ ? resolveCall(Call->getCallee(), Call->getArgs()) : nullptr;
+ const TypeInfo *Type = Sig ? resolveType(Sig->ReturnTypeName) : nullptr;
+ if (Result && Type && Type->IsClass) materializeOperatorReceiver(Result, Type);
return;
}
@@ -117,9 +129,12 @@ void CodeGen::emitStmt(StmtAST *Stmt) {
}
Value *RetVal = nullptr;
if (Ret->getRetVal()) {
- RetVal = emitCoercedExpr(Ret->getRetVal(), resolveType(Sig->ReturnTypeName));
+ std::vector<size_t> Transfers;
+ RetVal = emitOwnedValue(Ret->getRetVal(), resolveType(Sig->ReturnTypeName), Transfers);
+ transferObjects(Transfers);
if (!RetVal) return;
}
+ cleanupTemporaries();
FuncGen->emitReturn(Ret, RetVal);
return;
}