aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/OperatorGen.cc
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-18 06:05:53 +0000
committer_ov4 <ov4@ov4.org>2026-10-18 06:05:53 +0000
commit16231050058131860f710073c17d3bca7c6637eb (patch)
tree1da2ca606f1d513822ccd04b3053d5eee69ac19d /lib/CodeGen/OperatorGen.cc
parent1b0b287629e6e3b6d8eb6182db72b28fd0510574 (diff)
feat(operators): support global binary operator overloads
Resolve exact operand types and preserve declared operator return types. Reject implicit STRING to BOOLEAN conversion at typed expression boundaries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/OperatorGen.cc')
-rw-r--r--lib/CodeGen/OperatorGen.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/CodeGen/OperatorGen.cc b/lib/CodeGen/OperatorGen.cc
new file mode 100644
index 0000000..83c515b
--- /dev/null
+++ b/lib/CodeGen/OperatorGen.cc
@@ -0,0 +1,20 @@
+#include "cps/CodeGen.h"
+#include "cps/Operator.h"
+
+using namespace cps;
+
+// Probing candidates must not evaluate operands or diagnose absent overloads:
+// both static typing and emission use this same selection.
+CodeGen::OperatorResolution CodeGen::resolveOperator(
+ int Op, const TypeInfo *Left, const TypeInfo *Right) {
+ OperatorResolution Result;
+ if (!Left) return Result;
+ for (const FuncSig *Sig : FuncGen->getOverloads(operatorName(Op))) {
+ if (Sig->Prototype->getOperator() != Op || Sig->Params.size() != (Right ? 2u : 1u)) continue;
+ if (!Left->sameType(resolveType(Sig->Params[0].TypeName))) continue;
+ if (Right && !Right->sameType(resolveType(Sig->Params[1].TypeName))) continue;
+ if (Result.Signature) Result.Ambiguous = true;
+ else Result.Signature = Sig;
+ }
+ return Result;
+}