aboutsummaryrefslogtreecommitdiff
path: root/include/cps/Operator.h
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 /include/cps/Operator.h
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 'include/cps/Operator.h')
-rw-r--r--include/cps/Operator.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/cps/Operator.h b/include/cps/Operator.h
new file mode 100644
index 0000000..7cbb5d9
--- /dev/null
+++ b/include/cps/Operator.h
@@ -0,0 +1,28 @@
+#pragma once
+#include "cps/Lexer.h"
+#include <string>
+
+namespace cps {
+
+inline std::string operatorSpelling(int Op) {
+ switch (Op) {
+ case '+': case '-': case '*': case '/': case '&': case '<': case '>':
+ return std::string(1, static_cast<char>(Op));
+ case tok_div: return "DIV";
+ case tok_mod: return "MOD";
+ 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_not: return "NOT";
+ default: return {};
+ }
+}
+
+inline std::string operatorName(int Op) {
+ return "OPERATOR" + operatorSpelling(Op);
+}
+
+} // namespace cps