aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/FunctionGen.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/FunctionGen.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/FunctionGen.cc')
-rw-r--r--lib/CodeGen/FunctionGen.cc11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc
index a0d0e32..37df8ff 100644
--- a/lib/CodeGen/FunctionGen.cc
+++ b/lib/CodeGen/FunctionGen.cc
@@ -91,7 +91,7 @@ void FunctionGen::createArgumentAllocas(Function *F, const std::vector<ParamDecl
IRBuilder<> TmpB(&F->getEntryBlock(), F->getEntryBlock().begin());
AllocaInst *Alloca = TmpB.CreateAlloca(ArgType, nullptr, P.Name);
- // Shallow BYVAL copy. The common lifetime hook is the future copy-constructor point.
+ // The caller constructs class arguments; this slot takes ownership of the value.
Builder.CreateStore(ArgVal, Alloca);
const TypeInfo *Info = Types.resolve(P.TypeName);
if (Info && Info->IsClass) {
@@ -123,6 +123,15 @@ const FuncSig *FunctionGen::getSignatureByLink(const std::string &Name) const {
Function *FunctionGen::emitPrototype(PrototypeAST *Proto) {
auto Registered = PrototypeLinks.find(Proto);
if (Registered != PrototypeLinks.end()) return Module.getFunction(Registered->second);
+ if (!Proto->getOwnerClass().empty() && sameIdentifier(Proto->getName(), "NEW") &&
+ Proto->getParams().size() == 1) {
+ const auto &P = Proto->getParams()[0];
+ if (!P.IsArray && sameIdentifier(P.TypeName, Proto->getOwnerClass()) &&
+ P.Mode != PassMode::ByRef) {
+ reportError("A copy constructor must take BYREF to its own class");
+ return nullptr;
+ }
+ }
if (int Op = Proto->getOperator()) {
size_t Count = Proto->getParams().size() + !Proto->getOwnerClass().empty();
bool ValidCount = Op == '-' ? Count == 1 || Count == 2