diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-24 18:01:36 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-24 18:01:36 +0000 |
| commit | 0900667401415a0914b8a1510543c7c7eaf32e53 (patch) | |
| tree | e61c43059f880878bc59259e82c5ab6665b20dbd /lib/CodeGen/FunctionGen.cc | |
| parent | 034ab48c5f30b0e6f402766b4c1bcf36661e16cd (diff) | |
feat(overload): select overloads by return type as well as parameters
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/FunctionGen.cc')
| -rw-r--r-- | lib/CodeGen/FunctionGen.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc index c233205..2e927f9 100644 --- a/lib/CodeGen/FunctionGen.cc +++ b/lib/CodeGen/FunctionGen.cc @@ -229,6 +229,10 @@ Function *FunctionGen::emitPrototype(PrototypeAST *Proto) { } Type *RetType = getLLVMType(Proto->getReturnType()); + const TypeInfo *ReturnInfo = Types.resolve(Proto->getReturnType()); + Sig.ReturnKey = ReturnInfo + ? (ReturnInfo->isC() ? "C:" + ReturnInfo->CIdentity : ReturnInfo->Name) + : Proto->getReturnType(); FunctionType *FT = FunctionType::get(RetType, ArgTypes, false); auto &Overloads = Signatures[Sig.Name]; for (const FuncSig &Existing : Overloads) { @@ -241,7 +245,8 @@ Function *FunctionGen::emitPrototype(PrototypeAST *Proto) { Proto->getName().c_str(), Proto->getName().c_str()); return nullptr; } - if (sameIdentifier(Existing.ParamKey, Sig.ParamKey)) { + if (sameIdentifier(Existing.ParamKey, Sig.ParamKey) && + sameIdentifier(Existing.ReturnKey, Sig.ReturnKey)) { if (Existing.OwnerUnit != CurrentUnit) reportError("Duplicate definition %s in %s and %s", Sig.Name.c_str(), UnitPaths[Existing.OwnerUnit].c_str(), UnitPaths[CurrentUnit].c_str()); @@ -250,6 +255,12 @@ Function *FunctionGen::emitPrototype(PrototypeAST *Proto) { } } Sig.LinkName = Sig.Name + (Sig.IsOverload ? "(" + Sig.ParamKey + ")" : ""); + // Only the return type distinguishes non-void overloads that share a + // parameter list, so it enters their link name. PROCEDURE, NEW and + // OPERATOR<- keep the established names. + if (Sig.IsOverload && ReturnInfo && !ReturnInfo->isVoid() && + !sameIdentifier(Proto->getName(), "NEW") && Proto->getOperator() != tok_assign) + Sig.LinkName += ":" + Sig.ReturnKey; Function *F = Function::Create(FT, Proto->getOwnerClass().empty() && sameIdentifier(Proto->getName(), "MAIN") ? Function::InternalLinkage : Function::ExternalLinkage, |
