aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-22 03:26:47 +0000
committer_ov4 <ov4@ov4.org>2026-10-22 03:58:36 +0000
commit3582c493e26f18bcb62111e10980d5c841962362 (patch)
tree09952392fe5f153cbac7353242f04e677695f26e /lib/CodeGen
parente575826c287f0dd0afeb1b9c6c8db45fb44c8d26 (diff)
refactor(codegen): spell user-kind operator diagnostics with operatorSpelling
TypeCheckGen's private opToText duplicated cps::operatorSpelling; both produce the same text for every binary operator the parser accepts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/TypeCheckGen.cc29
1 files changed, 4 insertions, 25 deletions
diff --git a/lib/CodeGen/TypeCheckGen.cc b/lib/CodeGen/TypeCheckGen.cc
index 0b66cfc..575fc04 100644
--- a/lib/CodeGen/TypeCheckGen.cc
+++ b/lib/CodeGen/TypeCheckGen.cc
@@ -2,32 +2,11 @@
#include "cps/CodeGen.h"
#include "cps/TypeAST.h"
#include "cps/Lexer.h"
+#include "cps/Operator.h"
using namespace llvm;
using namespace cps;
-namespace {
-
-// Operator spelling for diagnostics (raw ASCII or a keyword token).
-std::string opToText(int Op) {
- switch (Op) {
- case tok_eq: return "=";
- case tok_ne: return "<>";
- case tok_le: return "<=";
- case tok_ge: return ">=";
- case tok_and: return "AND";
- case tok_or: return "OR";
- case tok_div: return "DIV";
- case tok_mod: return "MOD";
- default:
- if (Op >= 0) return std::string(1, static_cast<char>(Op));
- return "?";
- }
-}
-
-} // namespace
-
-
// The single name-level admission gate. Targets of a user kind demand exact
// type-name equality (their representations are indistinguishable at the
// LLVM level); builtin targets additionally reject user-kind sources, then
@@ -133,7 +112,7 @@ Value *CodeGen::emitUserKindBinaryOp(int Op, Value *L, const TypeInfo *LT,
if ((LT && LT->isRecord()) || (RT && RT->isRecord())) {
reportError("Operator %s cannot be applied to a record value (type %s)",
- opToText(Op).c_str(), (LT && LT->isRecord()) ? LName : RName);
+ operatorSpelling(Op).c_str(), (LT && LT->isRecord()) ? LName : RName);
return nullptr;
}
@@ -144,7 +123,7 @@ Value *CodeGen::emitUserKindBinaryOp(int Op, Value *L, const TypeInfo *LT,
: Builder->CreateICmpNE(L, R, "ptr_ne");
}
reportError("Pointer values support only = and <> between the same pointer type (got %s %s %s)",
- LName, opToText(Op).c_str(), RName);
+ LName, operatorSpelling(Op).c_str(), RName);
return nullptr;
}
@@ -182,6 +161,6 @@ Value *CodeGen::emitUserKindBinaryOp(int Op, Value *L, const TypeInfo *LT,
reportError("Operator %s cannot be applied to %s and %s "
"(enums allow comparison with the same enum type, and enum + or - INTEGER)",
- opToText(Op).c_str(), LName, RName);
+ operatorSpelling(Op).c_str(), LName, RName);
return nullptr;
}