From 3582c493e26f18bcb62111e10980d5c841962362 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 03:26:47 +0000 Subject: 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 --- lib/CodeGen/TypeCheckGen.cc | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) (limited to 'lib') 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(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; } -- cgit v1.3.1-4-g156e